Add sensors and output to your PC using the Pico 2040 with custom firmware Desktop Python and Blinka
Extend your PC into the microcontroller sensor and control realm with Desktop Python Adafruit Blinka and an RP2040 Pico running U2IF firmware. This setup gives you access to the microcontroller component libraries without writing code on the microcontroller itself. No code-download-run cycle is required!
Video
Writing data to an attached LCD display from inside the Python REPLSteps
There are several sites that provide good instructions so I'll just provide the basics.
Device Prep
- Buy a supported Pico board. Adafruit has some variants. I used the original Raspberry Pi Pico in the video.
- Find and download a Raspberry Pi Pico that is supported by the firmware, UF2 file. There are a couple different variants of the Pico boards. most will work but the custom firmware versions may bake in special component support of some of the boards.
- The original firmware is at https://github.com/execuc/u2if
- Adafruit firmware fork https://github.com/adafruit/u2if
- Adafruit learning describes the process https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico/setup
- Hold down the reset button on the Pico board while plugging it into your PC/Mac. You should see a mounted device labeled RPI-RP2
- Drag the firmware onto the RPI-RP2 device.
- The device file system. should disappear and new HID devices should appear.
Python Prep
- Install Python 3 if you don't already have it.
- Set The BLINKA_U2IF environment variable to 1
- # Linux set BLINKA_U2IF=1# Powershell $env:BLINKA_U2IF=1
- Use pip3 to install the Adafruit libraries on your PC using PIP. You need the HID and the BLINKA libraries plus any device-specific libraries such as your gyroscope, LCD, or servo libraries.
- Open a REPL window where we know the BLINKA_U2IF variable is set and verify the board with the following. You should see a list of board capabilities
- import os# verify "BLINKA_U2IF" set. Should = 1try:os.environ["BLINKA_U2IF"]print("BLINKA_U2IF set correctly. Well Done!")except KeyError:print("**** ABORT! BLINKA_U2IF not set")exitexcept ValueError:print("**** ABORT! BLINKA_U2IF not set")exitimport boarddir(board)
Sample Program
This source code comes from my CircuitPython playground repository which is very much a work in progress.
My sample program assumes you have an I2C 16x2 LCD attached to the default I2C bus, Pins 5 and 6 on the full-sized Pico.
Your pins may be different if you are using a different device. This just displays a few messages and changes the backlight intensity or color.
import time
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
import board
dir(board)
start_connect = time.perf_counter()
lcd_columns = 16
lcd_rows = 2
i2c = board.I2C()
start_connect = time.perf_counter()
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
end_connect = time.perf_counter()
print("conect time: " + str(end_connect - start_connect))
# I have the RGB backlit Adafruit device
lcd.clear()
lcd.color = [100, 0, 0]
# Show text
start_hello = time.perf_counter()
lcd.message = "Hello\nCircuitPython"
end_hello = time.perf_counter()
print("draw hello time: " + str(end_hello - start_hello))
# blink
lcd.blink = True
lcd.clear()
lcd.blink = False
# final message
lcd.message = "Goodbye"
lcd.cursor_position(8, 1)
lcd.message = "over here"
lcd.home()
lcd.clear()
lcd.color = [0, 0, 0]
Related Posts
https://joe.blog.freemansoft.com/2023/01/using-circuitpython-and-adafruit.html
Revision History
Created 2025 01
Comments
Post a Comment