test the new Blockly Micropython Editor!
Welcome to the RP2040 Examples repository! This collection showcases various projects and code samples for the Raspberry Pi Pico and other RP2040-based microcontroller boards. Whether you're a beginner looking to get started with MicroPython or an experienced developer exploring Golang on embedded systems, you'll find something useful here.
If you're also interested in Raspberry Pi projects using Golang, be sure to check out my Raspberry Pi Golang examples.
- Where to Buy
- Documentation & Resources
- MicroPython
- Golang
- Project Categories
- Troubleshooting
- Contributing
- License
The Raspberry Pi Pico is a powerful yet affordable microcontroller that you can purchase from various retailers worldwide. Here are some trusted sources:
To get the most out of your Raspberry Pi Pico, you can refer to the following documentation and resources:
- Official Raspberry Pi Pico Documentation - Comprehensive guide to getting started, programming, and using the Pico.
- Raspberry Pi Pico Pinout - Visual reference for the GPIO pins on the Pico.
MicroPython is an efficient and beginner-friendly way to program your Raspberry Pi Pico. Follow the links below to download the latest firmware:
- Install MicroPython firmware: Download and flash the .uf2 file to your Pico
- Choose an IDE: We recommend Thonny for beginners
- Connect your Pico: Use a USB cable to connect to your computer
- Run examples: Copy and paste code directly into the REPL or save as .py files
Explore these example scripts to get hands-on with MicroPython:
-
blink_with_pcf8574.py
Need more GPIO pins? Use a PCF8574 I/O expander. -
blink_with_ws2812.py
Create stunning LED displays with WS2812 light strips or modules. -
distance_with_hc-sr04.py
Accurately measure distances with the HC-SR04 ultrasonic sensor. -
info.py
Retrieve and display system information from your Raspberry Pi Pico. -
interactive_blink.py
Control GPIO pins interactively via text input, ideal for use with Thonny. -
morse_blink.py
Convert text into Morse code using an LED on the Pico. -
nunchuck.py
Interface with a Wii Nunchuck using a Nunchuck adapter. -
pwm_with_pca9685.py
Control up to 16 servos using the PCA9685 PWM driver. -
read_rfid_with_rc522.py
Implement RFID reading using the RC522 module. -
snake_on_hub75_zeroplayer.py
Display a snake animation on a Hub75 LED-Matrix with a Pimoroni Interstate 75 W. For a playable version, see my DIY-Arcade-Machine. -
weigh_with_hx711.py
Build a digital scale using a load cell and the HX711 A/D converter. -
wlan.py
Connect your Pico to WiFi and fetch data from the web. -
adc.py
Read analog signals using the Pico’s built-in ADC pins. -
balls_on_hub75.py
Simulate bouncing balls on a Hub75 LED-Matrix. -
conway_on_hub75.py
Implement Conway's Game of Life on a Hub75 LED-Matrix. -
floodfill_on_hub75.py
Visualize a flood fill algorithm on a Hub75 LED-Matrix. -
joystick.py
Interface a joystick with the Pico for simple gaming or control applications. -
read_rfid_with_rc522_with_light.py
Enhance RFID reading with visual feedback using LEDs. -
temperature_with_dht22.py
Read temperature and humidity data using the popular DHT22 sensor. -
environmental_with_bme280.py
Monitor temperature, humidity, and atmospheric pressure with the BME280 sensor. -
display_with_ssd1306.py
Control a small SSD1306 OLED display via SPI interface for text and graphics. -
button_with_interrupts.py
Handle button inputs with proper debouncing and interrupt-driven responses. -
uart_communication.py
Demonstrate UART serial communication including GPS data simulation and echo server. -
motor_control.py
Control DC motors, servo motors, and stepper motors using PWM and digital outputs. -
communication_examples.py
Comprehensive examples for I2C, SPI, and general GPIO communication protocols. -
rtc_and_timing.py
Real-time clock operations with DS3231 RTC module and precise timing examples. -
led_matrix_max7219.py
Drive 8x8 LED matrices using the MAX7219 controller for text and pattern display. -
memory_eeprom.py
Read and write data to external EEPROM memory for persistent storage.
The repository includes advanced examples that demonstrate more complex integrations and use cases:
- DHT22/BME280: Temperature, humidity, and pressure monitoring
- Real-time data logging: Store sensor readings to EEPROM memory
- ADC applications: Multi-channel analog sensor reading
- OLED displays: SSD1306 driver with text and graphics
- LED matrices: MAX7219 8x8 matrix control with patterns
- Advanced LED effects: WS2812 animations and Hub75 visualizations
- DC motor control: PWM speed control with direction
- Servo positioning: Precise servo motor control
- Stepper motors: Step-by-step positioning control
- I2C device scanning: Automatic detection of connected devices
- UART communication: Serial data transmission and GPS simulation
- SPI interfaces: High-speed peripheral communication
- Real-time clocks: DS3231 RTC for timekeeping
- External memory: EEPROM storage for persistent data
- Interrupt handling: Efficient button and sensor response
This repository covers a wide range of project categories to help you learn and build:
| Category | Examples | Skill Level |
|---|---|---|
| Basic I/O | LED blinking, button input, ADC reading | Beginner |
| Sensors | Distance (HC-SR04), weight (HX711), environmental (DHT22, BME280) | Beginner-Intermediate |
| Communication | I2C, SPI, UART, RFID (RC522) | Intermediate |
| Displays | OLED (SSD1306), LED matrices (MAX7219, Hub75) | Intermediate |
| Motor Control | DC motors, servos, steppers | Intermediate |
| Networking | WiFi connectivity, web data fetching | Intermediate |
| Advanced | Game simulations, real-time systems, data logging | Advanced |
For those who prefer to code in Golang, this section provides examples of using Golang on the Raspberry Pi Pico with the TinyGo compiler.
- Install TinyGo: Follow the installation guide
- Verify installation: Run
tinygo versionin your terminal - Connect your Pico: Hold BOOTSEL button while connecting USB
- Build and flash: Use
tinygo flash -target=pico your_program.go
# Build only (creates .uf2 file)
tinygo build -o program.uf2 -target=pico program.go
# Build and flash directly
tinygo flash -target=pico program.go
# Monitor serial output
tinygo flash -target=pico -monitor program.go-
blink.go
Blink an LED using Golang. Install TinyGo and compile with:tinygo build -o blink.uf2 -target=pico blink.go
Flash directly to the Pico with:
tinygo flash -target=pico blink.go
Add
-monitorto the command to see the program’s output in the terminal. -
blink_with_ws2812.go
Control WS2812 LEDs using Golang, creating vibrant lighting effects. -
blink_with_ws2812_struct.go
An advanced example for controlling WS2812 LEDs using structured Golang code. -
read_rfid_with_rc522.go
Read RFID cards and tags using the RC522 module and Golang. -
button_control.go
Simple button input handling with debouncing using TinyGo. -
adc_reading.go
Read analog values from multiple ADC channels and convert to voltage. -
pwm_patterns.go
Generate various PWM patterns including sawtooth, triangle, and square waves. -
i2c_scanner.go
Scan I2C bus for connected devices and attempt basic communication.
MicroPython:
- "No module named 'machine'": Make sure MicroPython firmware is installed correctly
- Connection issues: Check USB cable and ensure Pico is recognized as a serial device
- Import errors: Verify all required files are uploaded to the Pico
TinyGo:
- "tinygo command not found": Ensure TinyGo is properly installed and in your PATH
- Flash errors: Make sure Pico is in BOOTSEL mode (hold button while connecting)
- Build errors: Check TinyGo version compatibility with target features
Hardware:
- No response from sensors: Verify wiring and power connections
- I2C issues: Check pull-up resistors (often 4.7kΩ) on SDA and SCL lines
- PWM not working: Ensure pins support PWM functionality
- Check the official Raspberry Pi Pico documentation
- Visit the MicroPython forum
- Browse TinyGo examples and documentation
- Submit issues to this repository for example-specific problems
Contributions are welcome! If you have a project or code sample you'd like to share, feel free to submit a pull request.
This repository is licensed under the MIT License. For more details, see the LICENSE file.
Feel free to explore the examples and contribute to this growing repository! Whether you're building a simple LED blinker or a complex sensor network, these examples are designed to help you get the most out of your Raspberry Pi Pico.
