Raspberry Pi Pico W with Headers Soldered and USB Cable
The Raspberry Pi Pico W is a microcontroller board from Raspberry Pi, featuring the RP2040 microcontroller chip. This board comes with headers soldered and a USB cable, making it a convenient option for IoT projects. The Pico W is a wireless version of the Pico, with Wi-Fi and Bluetooth capabilities.
Microcontroller: RP2040
Processor: Dual-core ARM Cortex-M0+ processor
Clock Speed: Up to 133 MHz
RAM: 264 KB
Flash Storage: 2 MB
Wi-Fi: 2.4 GHz IEEE 802.11 b/g/n
Bluetooth: Bluetooth 5.0
Interfaces: 2 x SPI, 2 x I2C, 2 x UART, 1 x USB 1.1
Operating Temperature: -20C to 85C
### Example 1: Blinking LED using MicroPython
In this example, we will use MicroPython to blink an LED connected to GPIO 25 on the Raspberry Pi Pico W.
Raspberry Pi Pico W with headers soldered and USB cable
LED
220 resistor
Breadboard and jumper wires
Code
```python
import machine
import time
# Set up the LED on GPIO 25
led = machine.Pin(25, machine.Pin.OUT)
while True:
led.value(1) # Turn on the LED
time.sleep(0.5) # Wait for 0.5 seconds
led.value(0) # Turn off the LED
time.sleep(0.5) # Wait for 0.5 seconds
```
Explanation
1. Import the `machine` and `time` modules.
2. Set up the LED on GPIO 25 as an output pin using `machine.Pin`.
3. Enter an infinite loop where the LED is turned on and off using the `value` method.
### Example 2: Wi-Fi Connection using C/C++
In this example, we will use the C/C++ SDK to connect the Raspberry Pi Pico W to a Wi-Fi network.
Raspberry Pi Pico W with headers soldered and USB cable
Wi-Fi network
Code
```c
#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "pico/wifi.h"
int main() {
// Initialize Wi-Fi
wifi_init();
// Set Wi-Fi credentials
wifi_set_credentials("your_ssid", "your_password");
// Connect to Wi-Fi
wifi_connect();
// Check if connected
if (wifi_is_connected()) {
printf("Connected to Wi-Fi!
");
} else {
printf("Failed to connect to Wi-Fi
");
}
return 0;
}
```
Explanation
1. Include the necessary headers for Wi-Fi functionality.
2. Initialize the Wi-Fi module using `wifi_init`.
3. Set the Wi-Fi credentials using `wifi_set_credentials`.
4. Connect to the Wi-Fi network using `wifi_connect`.
5. Check if the connection was successful using `wifi_is_connected`.
Note: Replace "your_ssid" and "your_password" with your actual Wi-Fi credentials.
### Example 3: Reading Temperature and Humidity using a Sensor (DHT11)
In this example, we will use the Raspberry Pi Pico W to read temperature and humidity data from a DHT11 sensor using MicroPython.
Raspberry Pi Pico W with headers soldered and USB cable
DHT11 temperature and humidity sensor
Breadboard and jumper wires
Code
```python
import machine
import dht
# Create a DHT11 object on GPIO 16
d = dht.DHT11(machine.Pin(16))
while True:
# Read temperature and humidity data
temp, hum = d.measure()
# Print the data
print(f"Temperature: {temp:.1f}C, Humidity: {hum:.1f}%")
# Wait for 1 second before taking the next reading
time.sleep(1)
```
Explanation
1. Import the `machine` and `dht` modules.
2. Create a DHT11 object on GPIO 16 using the `dht.DHT11` class.
3. Enter an infinite loop where the temperature and humidity data are read using the `measure` method.
4. Print the data to the console using f-strings.
Note: Make sure to install the `dht` library using `pip` before running this example.