This guide will show you how to use a Raspberry Pi Pico RP2040 to connect various sensors and breakouts to your PC running Windows, Mac OSX, or Linux. Special firmware gets loaded onto the Pico and turns it into a sort of Swiss army knife providing:
- General Purpose digital Input and Output (GPIO) for things like buttons and LEDs
- Analog to Digital Conversion (ADC) for reading analog signals
- Pulse Width Modulation (PWM) for servos or LED dimming
- I2C and SPI for connecting *lots* of external sensors, displays, etc.
- NeoPixels (WS2812B) for happy rainbow blinky fun!
The approach in this guide is useful if you want to run "regular" Python code on your main computer and have it communicate with external devices connected through the Pico (or other RP2040 board). If you are instead trying to run MicroPython code directly on the Pico and use CircuitPython libraries, then see this other guide: CircuitPython Libraries on MicroPython using the Raspberry Pi Pico.
The key element to enabling this capability on the Raspberry Pi Pico is thanks to the excellent u2if firmware written by execuc. The main repo not only contains the firmware that goes on the Pico itself, but micropython compliant Python code for interfacing to the Pico from your PC. So if you're more used to the micropython interface, then checkout the u2if repo. It has everything you need.
In this guide, we use the exact same firmware on the Pico. But on the PC, we use the newly updated Blinka library which has added support for interfacing with a Pico running the u2if firmware.
This is essentially the same idea as discussed in the FT232H Guide and the MCP2221 Guide. How can we directly connect common hardware items like buttons and LEDS (GPIO) or sensor breakouts (I2C/SPI) to a PC?
By loading the u2if firmware onto the Pico, it turns it into sort of a bridge using USB on the main PC. So you end up with something like this:
On the computer, we install Blinka which provides a CircuitPython compliant interface to the Pico with u2if. That way, all the CircuitPython libraries can then be used - on your PC!
You'll need a USB cable for programming and interacting with the Pico - but you probably have one of these laying around. Just make sure it's not a charge only cable.
Beyond that, it all depends on what you want to do. There are examples provided later in this guide that show some typical use cases.