Raspberry Pi Pico -...
 
Notifications
Clear all

Raspberry Pi Pico - Control the (I/O) World

Page 1 / 5

DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 3 years ago
Posts: 1114
Topic starter  

Let’s hook up some common components to the new Raspberry Pi Pico and see how to code for them in MicroPython!

Detailed Article with Code downloads: https://dbot.ws/picoint

The Raspberry Pi Pico is the first microcontroller produced by the Raspberry Pi Foundations, and they even designed the MCU for it. It has a wealth of features and a budget-friendly 4-dollar price tag.

With all of the hype around the Pico since its announcement a few weeks ago I wanted to actually DO something with it. So I decided to hook up a few simple I/O devices to it and see how to code for them using MicroPython.

I did all the coding on the Thonny IDE, and to keep things in the family I used a Raspberry Pi 4 as my host computer. You can also use Thonny and the Pico with Linux, Windows, and Mac OS X workstations as well, but it’s already installed and ready to go with the latest Raspberry Pi Operating System release.

All of these are basic I/O experiments with very simple code, but they each illustrate a useful technique that can be applied to other I/O devices. Plus, if you’re not familiar with MicroPython, it will help you ease into it, as all of the code is very elementary.

For those of you who are put off by the need to solder your own Pico pins fear not, I’ll show you just how easy it is. I'll even give my Pico a bath after I finish soldering it!

Here is what you will see in today's detailed look at the Raspberry Pi Pico:

00:00 - Introduction
03:17 - Raspberry Pi Pico
12:02 - Pico Soldering
19:15 - Set up Thonny IDE
23:36 - LEDs and Switches Intro & Hookup
26:12 - RGB Blink Demo
28:55 - Switch Test
31:36 - Interrupts & Toggle Demo
36:09 - LED & Switch Demo
37:42 - Analog Input Intro & Hookup
38:59 - Analog Input Demo
42:32 - LED PWM Demo
44:26 - OLED Display Intro & Hookup
45:49 - Display Demo
49:13 - Motor & H-Bridge Intro & Hookup
51:21 - Motor Demo
54:37 - The Everything Demo
58:05 - Running Programs at Boot-up
142 - Conclusion

It will be interesting to see what the future holds for this cute little microcontroller. It has some very nice design features but it also faces a lot of competition from devices like the Seeeduino XIAO, Arduino 33 IoT series, and, of course, the ESP32 boards.

But as I just received a big bag of Pico accessories, with more on the way, you're sure to see the Pico here in the workshop again very soon!

Hope you enjoy the video!

"Never trust a computer you can’t throw out a window." — Steve Wozniak


Safetywrench, Smurf, TheOutlander and 3 people liked
Quote
OceanChild67
(@oceanchild67)
New Member
Joined: 2 years ago
Posts: 4
 

Another excellent video with good clear instructions and a pleasure to watch.

I have only one question. Having spent many years doing Health and Safety industry I ask what the mask will do to reduce the fumes I could breath in?  Surly you would need a respirator (P1) and not one like you show? Just a question.

Oh the average price here in the UK is about £12 to £15. They will go down no doubt.

thanks again

Dave

Davie


ReplyQuote
DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 3 years ago
Posts: 1114
Topic starter  
Posted by: @oceanchild67

I have only one question. Having spent many years doing Health and Safety industry I ask what the mask will do to reduce the fumes I could breath in?  Surly you would need a respirator (P1) and not one like you show? Just a question.

You're right of course, in this particular case there are not a lot of fumes but the mask I showed is not particularly great, as you point out.

My biggest concern when doing the cleaning operation is splashing myself in the eyes, or in the face, with the PCB cleaner.

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


ReplyQuote
OceanChild67
(@oceanchild67)
New Member
Joined: 2 years ago
Posts: 4
 

@dronebot-workshop

Great video though. Was an old C++ programmer and spent the last year getting over the Arduino IDE and now it's great to get back to the Python (just have to remember it all again.

Ohm just one more thing - your great video on the IR Remote has now had a major update to the library and all your old sketches are not working unless I revert back to the old one. Now doubt there will be a way to fix them but I thought I'd just update you and let you know.

Keep up the great work.

Stay Safe

Davie


ReplyQuote
jfabernathy
(@jfabernathy)
Estimable Member
Joined: 2 years ago
Posts: 148
 

I've only used my Pico with either CircuitPython or C/C++ with VSCode IDE.  I did do the blink sketch with MicroPython, but for me it all comes down to library availability.  I use a lot of Adafruit and other common modules like Stemma QT sensors and displays. There are plenty of libraries in Arduino and CircuitPython provided by Adafruit for 300 devices.  I don't see that capability in MicroPython or the C/C++ VSCode IDE.  

If we get to Arduino support later as promised then the world of Adafruit sensor libraries become available.

Has anyone spent any time with devices that need libraries in MicroPython?

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


ReplyQuote
b
 b
(@b)
Prominent Member
Joined: 3 years ago
Posts: 912
 
Posted by: @jfabernathy

Has anyone spent any time with devices that need libraries in MicroPython

Yes I have 😀  and here is a link to some libraries for micropython. 

https://github.com/mcauser/awesome-micropython.

I was looking for a Library for an MCP9808 sensor on an adafruit i2c board and found a bit of a longwinded CircuitPython one. All I really need to do was to use the i2c to read the temperature so the following small micropython snippet is all that is required (having lifted the temp conversion function from the CircuitPython example 😎 )  Anyway I have found it easy enough to leverage the CircuitPython libs and examples when coding in micropython.  

Micropython code snipped using i2c to communicate to a MCP9808 sensor:

import machine

mcpTemp_Reg = 5

mcpRes_Reg = 8

mcpAddress = 24

def temp_c(data):
    value = data[0] << 8 | data[1]
    temp = (value & 0xFFF) / 16.0
    if value & 0x1000:
        temp -= 256.0
    return temp

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
memdata = bytearray(2)
i2c.readfrom_mem_into(mcpAddress,mcpTemp_Reg,memdata)
ctemp = temp_c(memdata)

This post was modified 2 years ago 2 times by b

ReplyQuote
jfabernathy
(@jfabernathy)
Estimable Member
Joined: 2 years ago
Posts: 148
 
Posted by: @byron
Posted by: @jfabernathy

Has anyone spent any time with devices that need libraries in MicroPython

Yes I have 😀  and here is a link to some libraries for micropython. 

https://github.com/mcauser/awesome-micropython.

I was looking for a Library for an MCP9808 sensor on an adafruit i2c board and found a bit of a longwinded CircuitPython one. All I really need to do was to use the i2c to read the temperature so the following small micropython snippet is all that is required (having lifted the temp conversion function from the CircuitPython example 😎 )  Anyway I have found it easy enough to leverage the CircuitPython libs and examples when coding in micropython.  

Micropython code snipped using i2c to communicate to a MCP9808 sensor:

import machine

mcpTemp_Reg = 5

mcpRes_Reg = 8

mcpAddress = 24

def temp_c(data):
    value = data[0] << 8 | data[1]
    temp = (value & 0xFFF) / 16.0
    if value & 0x1000:
        temp -= 256.0
    return temp

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
memdata = bytearray(2)
i2c.readfrom_mem_into(mcpAddress,mcpTemp_Reg,memdata)
ctemp = temp_c(memdata)

The link doesn't work for me,  https://github.com/mcauser/awesome-micropython

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


ReplyQuote
b
 b
(@b)
Prominent Member
Joined: 3 years ago
Posts: 912
 
Posted by: @jfabernathy

The link doesn't work for me, 404

Woops - the link had a full stop at the end, 

if you use the link from your post where you say 'it does not work for me' then it works

This post was modified 2 years ago by b

ReplyQuote
sj_h1
(@sj_h1)
Estimable Member
Joined: 2 years ago
Posts: 154
 

I tried to find a Rasberry Pi pico online and all of them were $14+. Some even charge for shipping. I found 1 local source, MicroCenter has them for $2. The weather is bad today so I will have to wait but it looks like I know where I am going to get it.

 

 

 


ReplyQuote
DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 3 years ago
Posts: 1114
Topic starter  
Posted by: @oceanchild67

Ohm just one more thing - your great video on the IR Remote has now had a major update to the library and all your old sketches are not working unless I revert back to the old one. Now doubt there will be a way to fix them but I thought I'd just update you and let you know.

Actually, that has become an issue with a few of the videos and articles I created a few years ago, they have relied upon libraries that no longer exist or have been changed and are no longer compatible.

I know the RF module ones that use the Radiohead library also have become impossible to work with, as the library is no longer available.  And I'm sure a few components that were easy t find a few years ago may not be as common today.

I am really thinking of re-visiting a few of the more popular videos with updated code and libraries.

😎

Bill

 

"Never trust a computer you can’t throw out a window." — Steve Wozniak


ReplyQuote
DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 3 years ago
Posts: 1114
Topic starter  
Posted by: @sj_h1

I found 1 local source, MicroCenter has them for $2. The weather is bad today so I will have to wait but it looks like I know where I am going to get it.

Was that a typo, or were they really two dollars? because if they were I'd suggest you brave the bad weather and grab as many as you can!

I have now purchased 15 of them from three different places, two Canadian sources, and Pimoroni in the UK. None of them worked out to 4 US dollars, but being in Canada I'm used to that.

Pimoroni's price is £3.60, which is just under 5 US dollars. 

In the US you CAN get them for 4 dollars from PiShop, at least you could if they were not out of stock.

When a new unit like this is released it's not uncommon for the prices to be all over the map.

😎

Bill

 

"Never trust a computer you can’t throw out a window." — Steve Wozniak


ReplyQuote
YurkshireLad
(@yurkshirelad)
Reputable Member
Joined: 2 years ago
Posts: 463
 

Wow $2 is cheap - one Canadian place I found is selling it for C$7.95 plus tax and shipping.


ReplyQuote
sj_h1
(@sj_h1)
Estimable Member
Joined: 2 years ago
Posts: 154
 

@dronebot-workshop That was the online price of $14 from 5 different vendors through amazon. The microcenter $2 price is for 1 only. It is $4 after that. That is pickup only, not available online. Due to my health I cannot brave the weather.

 


ReplyQuote
TheOutlander
(@theoutlander)
Trusted Member
Joined: 2 years ago
Posts: 77
 

@yurkshirelad Mine were $8.95 at a Montreal store, my usual source of supply were our of stock. I think we are seeing price and availability fluctuations. ABRA , where I got mine had "a pile" of them!

"Hardware eventually fails. Software eventually works." - Michael Hartung


ReplyQuote
Sean451
(@sean451)
Trusted Member
Joined: 2 years ago
Posts: 69
 

MicroCenter has in-store only blockbuster prices so they can get you into the store and upsell. You might walk in looking for a $2 Pico, but walk out spending $100+.

--->Sean

(◕(' 人 ') ◕)


ReplyQuote
Page 1 / 5