85 x 56 x 17 mm (3.37 x 2.21 x 0.67 inches)
85 x 56 x 17 mm (3.37 x 2.21 x 0.67 inches)
approximately 40 grams (1.41 ounces)
Accessories
Optional cases and enclosures available for protection and aesthetics
Various adapter boards and accessories available for expanded functionality
In summary, the Raspberry Pi 5 4GB is a powerful, feature-rich SBC that offers improved performance, expanded memory, and enhanced functionality compared to its predecessors. Its affordability, compact size, and wide range of applications make it an attractive choice for developers, makers, and enthusiasts alike.
Raspberry Pi 5 4GB DocumentationOverviewThe Raspberry Pi 5 4GB is a powerful single-board computer (SBC) designed for IoT, robotics, and automation projects. With a quad-core Cortex-A55 CPU, 4GB of RAM, and a wide range of interfaces, it's an excellent choice for developing complex projects.Hardware SpecificationsProcessor: Quad-core Cortex-A55 CPU
RAM: 4GB
Storage: MicroSD card slot
Operating System: Raspberry Pi OS (based on Linux)
Interfaces:
+ HDMI 2.0
+ USB 3.0 (x2)
+ USB 2.0 (x2)
+ Ethernet RJ45
+ Wi-Fi 5 (802.11ac)
+ Bluetooth 5.0
+ GPIO (40-pin)
+ Camera interface (CSI)Code Examples### Example 1: Python Script to Control LED using GPIOThis example demonstrates how to use the Raspberry Pi 5's GPIO pins to control an LED.Hardware RequirementsRaspberry Pi 5 4GB
LED
1 k resistor
Breadboard
Jumper wiresSoftware RequirementsRaspberry Pi OS (latest version)
Python 3.xCode
```python
import RPi.GPIO as GPIO
import time# Set up GPIO mode
GPIO.setmode(GPIO.BCM)# Define the GPIO pin for the LED
LED_PIN = 17# Set up the LED pin as an output
GPIO.setup(LED_PIN, GPIO.OUT)while True:
# Turn the LED on
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
# Turn the LED off
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
```
ExplanationIn this example, we use the RPi.GPIO library to interact with the GPIO pins. We set up the LED pin (GPIO 17) as an output and then use a `while` loop to toggle the LED on and off every second.### Example 2: Node.js Script to Collect and Send Sensor Data to the CloudThis example demonstrates how to use the Raspberry Pi 5 to collect sensor data and send it to the cloud using Node.js.Hardware RequirementsRaspberry Pi 5 4GB
DHT11 temperature and humidity sensor
Breadboard
Jumper wiresSoftware RequirementsRaspberry Pi OS (latest version)
Node.js (latest version)
npm packages:
+ `dht-sensors`
+ `axios`Code
```javascript
const dht = require('dht-sensors');
const axios = require('axios');// Set up the DHT11 sensor
const sensor = new dht.DHT11(4); // GPIO 4// Set up the API endpoint
const API_ENDPOINT = 'https://your-cloud-api.com/temperature';// Collect and send sensor data every 10 seconds
setInterval(() => {
const temperature = sensor.readTemperature();
const humidity = sensor.readHumidity();const data = {
temperature: temperature.toFixed(2),
humidity: humidity.toFixed(2)
};axios.post(API_ENDPOINT, data)
.then(response => {
console.log(`Data sent to cloud: ${response.data}`);
})
.catch(error => {
console.error(`Error sending data to cloud: ${error}`);
});
}, 10000);
```
ExplanationIn this example, we use the `dht-sensors` library to interact with the DHT11 sensor and collect temperature and humidity data. We then use the `axios` library to send the data to a cloud API endpoint using a `POST` request. The `setInterval` function is used to collect and send data every 10 seconds.These examples demonstrate the flexibility and capabilities of the Raspberry Pi 5 4GB in various IoT contexts.