If you are here, you are likely trying to work your way through the setup of your Inventr.io Python Starter Kit and its Lesson 0 – Getting Started with your Raspberry Pi Pico W (Firmware, Thonny IDE, and Blink).
You can get to Lesson 0 through either:
- https://inventr.io/PythonStart
- https://learn.inventr.io/courses/micropython-starter-course/
Course materials are located through either:
- https://inventr.io/downloads
- https://learn.inventr.io/resources/
This information is on the back of the card that came with the kit.
This post is unaffiliated with Inventr.io, and just documents my experience working through the setup procedure on an Apple MacBook Pro M2 Max running macOS Sonoma 14.4.1 in April of 2024, which did not go smoothly.
My purchasing decision was based on the expectation was that this would be an everything-included kit designed to teach absolutely beginner electronics, using Python. I may have erred in that decision.
The kit appears to be more about using Python than understanding the electronics that came with the kit, which I was hoping for. The Inventr website does not make it clear what prerequisite knowledge is expected.
If you are already setup, then hop over to Lesson 1 – Traffic Light Simulator, as you are likely about to run into issues as I did.
Unpacking
The first thing you'll notice is a box of parts, you'll want to pull out the Raspberry Pi Pico W out of its sealed grey static bag; the device is embedded into some white styrofoam to protect it (leave it in for now, as it has long exposed pins we don't want to bend).
You will also need a MicroUSB cord, which is strangely absent. If you need to buy one, you can get a USB-C to MicroUSB or a USB-A to MicroUSB from Amazon.
Do not plug the cord into the computer yet, just plug the MicroUSB end of the cord into the Raspberry Pi Pico W.
Download the Latest Firmware
I suggest grabbing a copy from: https://rpf.io/pico-w-firmware
This resulted in downloading a file called RPI_PICO_W-20240222-v1.22.2.uf2
on 2024-04-13.
Beware that Inventr.io's "[DOWNLOAD FIRMWARE]" link will likely obtain an older version.
Installing the Firmware on the Device
This is where it gets a little tricky, because you're going to need multiple hands.
Before plugging anything into your computer, press and keep held down the BOOTSELECT button (it is a white oval button on the top of the circuit board labeled BOOTSEL
). As you do this, plug the other end of the USB cable into the computer.
In a moment, you'll see a volume mount (similar to a thumb drive) labeled RPI-RP2
. At that point you can let go.
Open that mounted drive, you should see a file called INFO_UF2.TXT
and likely one other. If things look sparse, you're in the right place.
Now, copy the downloaded .uf2
file over to it. (You might do this by drag'n'drop or via the command line.)
The moment the file completes, the device instantly reboots, and installs the new file.
This sudden and unexpected dismounting will likely make macOS report that the drive was improperly ejected; it's fine, as the device choose to disconnect. Further more, if you go back and remount the device again, you'll see the file is gone — it gets deleted after it's been installed.
Installing the Thonny IDE
You could download the Thonny IDE from https://thonny.org/, as of 2024-04-13 it is v4.1.4.
However, I didn't want a .pkg
making system configurations, and as much as I love HomeBrew, sometimes it just isn't up to date.
Note, for this to work, I do have Python 3.12 installed, which I did with: brew install python@3.12
I went with making a Python virtual environment:
1
2
3
4
5
6
7
8
9
10
11
12mkdir thonny # Creates a directory to work in
cd thonny # Go to that directory
python3.12 -m venv env # Make a virtual environment called 'env'
source env/bin/activate # Activate the 'env' virtual environment
pip install --upgrade pip # Upgrade pip while we're here
python --version # Should report v3.12.0 or better
pip --version # Should report v24.0 or better
pip install thonny # Install the thonny IDE
In the future, you would just cd thonny
and source env/bin/activate
.
Starting Thonny IDE
Just start the IDE by typing its name at the command line:
1
thonny
I was immediately greeted by a language choice. I picked English (US), Standard for initial settings, then clicked Let's Go.
The next step, as shown in their YouTube Video at 03:25 involves going down to the bottom right and selecting MicroPython (Raspberry Pi Pico)
...
Except non-Windows machines don't have COMx: ports, and I'm using macOS.
The choices presented looked incorrect, and I selected the closest thing and got an error as the IDE crashed, with this hit that it was having problems:
1
2[MainThread] INFO thonny.plugins.micropython.mp_front: Listing serial ports
[MainThread] INFO thonny.plugins.micropython.mp_front: Falling back to serial.tools.list_ports.comports
Troubleshooting
macOS has two USB to Serial port drivers: /dev/tty.usbmodem21401
and /dev/cu.usbmodem21301
. Your suffix numbers may vary.
Side Note: The 'tty' devices were used for "call-in" devices, waiting for a Carrier Detect signal on the line before establishing a connection; the 'cu' devices were used for "call-up" to call out, and is suitable when making a connection rather than waiting for one (the Carrier Detect signal need not be present).
Knowing that, we can try to connect to the Raspberry Pi Pico W with the only USB serial port we have available at the moment.
1
screen /dev/cu.usbmodem21301 115200
The screen
program can connect to a specified device at the specified baudrate, effectively providing an interactive console terminal to the Pi.
Immediately after connecting, pressing Return on our keyboard should drop us into a Python interpreter on the device!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19Welcome to MicroPython!
For online docs please visit http://docs.micropython.org/
For access to the hardware use the 'machine' module. RP2 specific commands
are in the 'rp2' module.
Quick overview of some objects:
machine.Pin(pin) -- get a pin, eg machine.Pin(0)
... lots more stuff ...
Useful control commands:
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
CTRL-E -- on a blank line, enter paste mode
For further help on a specific object, type help(obj)
For a list of available modules, type help('modules')
To get out of screen requires pressing Control-A then the letter 'k'.
After I did this and restarted Thonny (by typing thonny
at the command line), I was able to select MicroPython (Raspberry Pi Pico) - Board in FS mode @ /dev/cu.usbmodem21301
(your suffix numbers may vary).
If you end up seeing something like the following, then it worked:
1
2MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
Installing the picozero module
Now go to Tools / Manage packages..., enter picozero
and click Search micropython-lib and PyPl.
There should be a button to install it. Do that.
Except, for me, this resulted in an error:
1
2Could not fetch search results:
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>
Tried loading from package directly from the link on the screen, that also failed.
Workaround for picozero.py
Note: over at https://projects.raspberrypi.org/en/projects/get-started-pico-w/1, they have a nice 'Installing picozero offline' set of instructions for different scenarios.
Grabbing straight from the source, I went to https://github.com/RaspberryPiFoundation/picozero/blob/main/picozero/picozero.py, clicked Raw, and right-click Save Page As... picozero.py
Back in Thonny, go to View / Files, then navigate to where you saved picozero.py
(likely your ~/Downloads directory), select that file, and right-click and choose "Upload to /" from the menu, which sends it to the root on the Raspberry Pi Pico W.
Note the view display is not a new dialog, so closing the window closes the app; rather, it is a tab in a side bar, that you can close.
Finally Some Python Code
In the editor, copy'n'paste this:
1
2
3
4
5
6
7
8
9
10import machine
import time
led = machine.Pin('LED', machine.Pin.OUT)
while True:
led.value(True)
time.sleep(1)
led.value(False)
time.sleep(1)
You can press the green Run button, and the LED will start flashing on the device. Success.
NOTE: In the next lesson, the author silently switches modules from import time
to import utime
. He also switches from using Boolean values to numerical 1s and 0s.
NOTE TO INSTRUCTOR: This kind of inconsistency can really boggle a student who is trying to build upon prior knowledge.