Raspberry Pi Pico Examples

repository·master·Indexed 26 days ago

https://github.com/raspberrypi/pico-examples

A collection of example projects for the Raspberry Pi Pico SDK demonstrating hardware features and software patterns. Includes demonstrations for Bluetooth Low Energy (BLE) communication, Wi-Fi credential provisioning, async_context workers, and the use of picotool for configuring binary variables post-compilation.

Tokens
25.2K
Snippets
41
Records
172
Agent score
86%

What's inside raspberrypi-pico-examples

  1. Overview of SSD1309 SPI stdout example

    master

    This example demonstrates how to display text and graphics on an SSD1309-based OLED panel using SPI.

    Key Features:

    • Background Rendering: Content is rendered to a frame buffer and transferred to the SPI port in the background via a DMA channel controlled by a frame timer.
    • Stdout Redirection: A simple driver copies _stdout content directly to the frame buffer.
    • Graphics Support: Provides basic graphics functions and uses an 8x8 bit font table (font.h).
    • Compatibility: While designed for SSD1309, it should work with compatible SSD1306 devices.
  2. MMA8451 I2C Example Overview

    master

    This example demonstrates how to interface a Raspberry Pi Pico with an MMA8451 3-axis digital accelerometer sensor board via I2C.

    Key Features:

    • Reads and displays acceleration values across 3 axes.
    • Allows users to configure the trade-off between range and precision.
    • Supports offset correction by writing to the sensor's offset correction registers.

    Files included:

    • CMakeLists.txt: CMake configuration to include the example in the build tree.
    • mma8451_i2c.c: The primary C source code for the example.
  3. Interface 1-Wire devices (DS18B20) to the Pico

    master
    This example demonstrates how to interface 1-Wire devices, specifically DS18B20 temperature sensors, to a Raspberry Pi Pico (RP2040). It uses a driver based on the RP2040 PIO (Programmable I/O) state machine to ensure accurate bus timings via a single GPIO pin. The temperature readings are output to the default serial terminal (USB or UART) as configured in your SDK settings.
  4. Use the PCF8523 I2C Example

    master

    The PCF8523 example demonstrates how to interface a Raspberry Pi Pico with a PCF8523 Real Time Clock module.

    Capabilities:

    • Initialize the current time and date.
    • Display the time/date every half-second.
    • Set an alarm for a specific time and date.
    • Trigger an alert when the alarm time is reached.

    Required Files:

    • CMakeLists.txt: Used to incorporate the example into the Pico SDK build tree.
    • pcf8523_i2c.c: The main application source code.
  5. BME280 SPI Example Overview

    master

    The bme280_spi example demonstrates how to read temperature, humidity, and pressure data from a BME280 sensor using the SPI interface.

    Key behaviors:

    • Interfaces at 3.3V.
    • Reads compensation parameters from the chip at startup.
    • Applies compensation routines to raw data as specified in the Bosch BME280 datasheet.

    Files included:

    • CMakeLists.txt: Used to incorporate the example into the Pico SDK build tree.
    • bme280_spi.c: The primary C source code for the example.
  6. Use the MPU6050 I2C example code

    master

    The mpu6050_i2c example is a basic implementation that recovers raw data from the sensor via polling.

    Limitations and Improvements:

    • Accuracy: This example only retrieves raw data. For accurate results, you should implement calibration.
    • Data Retrieval: The current implementation uses a polling approach. For better efficiency, you can wire the MPU6050 interrupt pin to a Pico GPIO and read data only when the sensor signals it is ready.
  7. Install OTA Update Example Firmware

    master

    After partitioning, you must load the Wi-Fi firmware and then the main application. Using picotool, the first load writes the Wi-Fi firmware to its designated partition, and the second load (-x) loads the application and resets the chip to begin execution.

    picotool load picow_ota_update_wifi_firmware.uf2
    picotool load -x picow_ota_update.uf2
  8. Wire DHT-11, DHT-22, or AM2302 sensors to Raspberry Pi Pico

    master

    To use DHT sensors (DHT-11, DHT-22, or AM2302) with a Raspberry Pi Pico, follow these wiring requirements:

    • Data Line Pull-up: Place a 10 kΩ resistor between the VCC pin and the data pin to act as a medium-strength pull-up on the data line.
    • Sensor Pins: One pin on the DHT sensor (typically pin 3) is unused and should not be connected.
    • Communication: The sensors use a custom single-wire protocol for data transmission.

    Bill of Materials:

    • 1x Raspberry Pi Pico
    • 1x DHT-22 sensor (or DHT-11/AM2302)
    • 1x 10 kΩ resistor
    • 1x Breadboard
    • 4x M/M Jumper wires
  9. Generate security keys for RP235x encrypted examples

    master

    To use the encrypted examples, you must replace the placeholder key files with your own. The system requires a secp256k1 PEM signing key, a 32-byte AES key, and a 16-byte IV salt.

    Warning: Do not lose these keys and salts. If lost, you may be unable to update the code on your device once secure boot is enabled.

  10. Wire DS18B20 sensors to the Pico

    master

    To connect DS18B20 sensors to the Pico, use the following pin mapping. Note that a pull-up resistor of approximately 4k ohms (or a 3900 ohm resistor) must be connected between the GPIO pin and the 3V3(OUT) pin.

    |==================================================
    |Pico    |pin         |DS18B20    |pin / sensor wire
    |==================================================
    |GND     |38 or equivalent   |GND        |1 / Black
    |GPIO 15 |20          |DQ         |2 / Yellow
    |3V3(OUT)|36          |VDD        |3 / Red
    |==================================================
  11. Configure Platform and Board for CMake builds

    master

    When building examples with CMake, you can specify the target hardware using PICO_PLATFORM and PICO_BOARD variables.

    • Default: The SDK targets RP2040 (PICO_PLATFORM=rp2040).
    • RP2350: To target the RP2350, use -DPICO_PLATFORM=rp2350. For RISC-V support on RP2350, use -DPICO_PLATFORM=rp2350-riscv.
    • Board-based selection: Passing -DPICO_BOARD=<board_name> (e.g., -DPICO_BOARD=pico2) will automatically set the correct PICO_PLATFORM.

    Note that certain examples (like Wi-Fi/Bluetooth or chip-specific features like DCP/HSTX) will only build on compatible boards or platforms.

  12. Wire an HT16K33 4-digit 14-segment LED to a Raspberry Pi Pico

    master

    To interface an HT16K33 driven 4-digit 14-segment LED with a Raspberry Pi Pico using I2C port 0, use the following wiring configuration.

    Important Voltage Note: The Pico GPIO pins are not 5V tolerant. Ensure the vi2c pin on the LED board is connected to the Pico's 3.3V pin to select the correct I2C voltage. If your specific display does not allow selecting 3.3V for I2C and requires 5V, you must use level shifters on the SDA and SCL lines to prevent damage to the RP2040.