Raspberry Pi Pico Documentation
The Raspberry Pi Pico is a microcontroller board developed by Raspberry Pi, a UK-based company. It is a small, low-cost, and highly capable board that is ideal for a wide range of applications, from simple prototypes to complex IoT projects. The Pico is based on the Raspberry Pi RP2040 microcontroller, which features a dual-core ARM Cortex-M0+ processor, 264KB of SRAM, and 2MB of flash storage.
Dual-core ARM Cortex-M0+ processor
264KB of SRAM
2MB of flash storage
26 multifunction GPIO pins
3 analog inputs
2 UARTs
2 SPI interfaces
1 I2C interface
1 USB 1.1 interface
Support for C/C++ and MicroPython programming languages
### Example 1: Blinking an LED using C/C++
This example demonstrates how to use the Raspberry Pi Pico to blink an LED connected to one of its GPIO pins.
Raspberry Pi Pico board
LED
220 resistor
Breadboard
Jumper wires
C/C++ compiler (e.g., GCC)
Code
```c
#include <iostream>
#include <rp2040.h>
int main() {
// Initialize the GPIO pin as an output
gpio_init(25); // GPIO 25 is used as an example, change to the pin connected to your LED
gpio_set_dir(25, GPIO_OUT);
while (true) {
// Set the GPIO pin high to turn the LED on
gpio_put(25, 1);
delay_ms(500);
// Set the GPIO pin low to turn the LED off
gpio_put(25, 0);
delay_ms(500);
}
return 0;
}
```
Explanation
This code initializes the GPIO pin as an output and sets it high to turn the LED on, then sets it low to turn the LED off, creating a blinking effect.
### Example 2: Reading Temperature Data using MicroPython
This example demonstrates how to use the Raspberry Pi Pico to read temperature data from a DS18B20 temperature sensor using MicroPython.
Raspberry Pi Pico board
DS18B20 temperature sensor
Breadboard
Jumper wires
MicroPython firmware (e.g., version 1.15.0 or later)
Code
```python
import machine
import ds18x20
# Initialize the DS18B20 temperature sensor
ds_sensor = ds18x20.DS18X20(machine.Pin(4)) # Pin 4 is used as an example, change to the pin connected to your sensor
while True:
# Read the temperature data from the sensor
temp_c = ds_sensor.read_temp()
print("Temperature: {:.1f}C".format(temp_c))
time.sleep(1)
```
Explanation
This code initializes the DS18B20 temperature sensor and reads the temperature data from it using the `read_temp()` method. The temperature data is then printed to the console.
These examples demonstrate the basic capabilities of the Raspberry Pi Pico and its ease of use in various IoT applications. The Pico's flexibility and affordability make it an ideal choice for prototyping and developing a wide range of projects.