Raspberry Pi Zero 2 W Documentation
The Raspberry Pi Zero 2 W is a compact, low-cost, and highly capable single-board computer (SBC) designed for IoT and robotics projects. It is an upgraded version of the original Raspberry Pi Zero, featuring a powerful quad-core CPU, 512MB of RAM, and built-in Wi-Fi and Bluetooth capabilities.
Processor: Broadcom BCM2710A1 quad-core Cortex-A53 ( ARMv8) 64-bit SoC
Clock Speed: 1GHz
RAM: 512MB LPDDR2 SDRAM
Storage: microSD Card Slot
Wireless Connectivity: 802.11 b/g/n Wi-Fi, Bluetooth 4.2
GPIO: 40-pin GPIO header
Power: microUSB port for power, 5V 2.5A recommended
### Example 1: Blinking an LED using Python
This example demonstrates how to use the Raspberry Pi Zero 2 W's GPIO pins to control an LED.
Raspberry Pi Zero 2 W
Breadboard
LED (any color)
1k resistor
Jumper wires
Raspbian OS (latest version)
Python 3.x
Code:
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Set up LED pin as output
LED_PIN = 17
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
# Turn LED on
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
# Turn LED off
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
# Clean up GPIO on exit
GPIO.cleanup()
```
Explanation:
1. Import the `RPi.GPIO` module and set up the GPIO mode to Broadcom (BCM).
2. Set up the LED pin as an output.
3. Use a try-except block to handle keyboard interrupts.
4. Inside the loop, turn the LED on and off using `GPIO.output()` with a 1-second delay between each state.
### Example 2: Wi-Fi Connectivity using Python
This example demonstrates how to use the Raspberry Pi Zero 2 W's built-in Wi-Fi capabilities to connect to a network and send an HTTP request.
Raspbian OS (latest version)
Python 3.x
`requests` library (install using `pip install requests`)
Code:
```python
import requests
# Set up Wi-Fi credentials
ssid = "your_wifi_ssid"
password = "your_wifi_password"
# Connect to Wi-Fi network
print("Connecting to Wi-Fi...")
requests.get(f"http://your_wifi_ssid:{password}@api.github.com")
# Send an HTTP request
print("Sending HTTP request...")
response = requests.get("https://www.example.com")
print(response.status_code)
```
Explanation:
1. Import the `requests` library.
2. Set up your Wi-Fi credentials (SSID and password).
3. Use the `requests.get()` function to connect to the Wi-Fi network by sending a GET request to the GitHub API with your credentials.
4. Send an HTTP request to a sample website (in this case, `https://www.example.com`) and print the response status code.
Note: Make sure to replace `your_wifi_ssid` and `your_wifi_password` with your actual Wi-Fi credentials.
These examples demonstrate the Raspberry Pi Zero 2 W's capabilities in GPIO control and Wi-Fi connectivity, making it an ideal choice for IoT projects.