Raspberry Pi 4 Model B (1GB Ram) Documentation
The Raspberry Pi 4 Model B is a single-board computer designed for IoT, robotics, and other applications. This model features 1GB of RAM, making it an affordable and compact solution for various projects.
Processor: Broadcom BCM2711B0 quad-core Cortex-A72 (ARMv8) 64-bit SoC
RAM: 1GB LPDDR4
Storage: microSD card slot
Networking: Gigabit Ethernet, 2.4GHz and 5GHz IEEE 802.11b/g/n/ac wireless LAN, Bluetooth 5.0
GPIO: 40-pin GPIO header
Operating System: Raspbian OS (based on Linux)
### Example 1: Blinking an LED using Python
This example demonstrates how to use the Raspberry Pi's GPIO pins to control an LED.
Raspberry Pi 4 Model B (1GB Ram)
Breadboard
LED
1 k 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)
# 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)
```
Explanation:
This code uses the RPi.GPIO library to interact with the Raspberry Pi's GPIO pins. It sets up the LED pin as an output and then enters an infinite loop, toggling the LED on and off every second using the `GPIO.output()` function.
### Example 2: Reading Temperature and Humidity using DHT11 Sensor and Python
This example demonstrates how to use the Raspberry Pi to read temperature and humidity data from a DHT11 sensor.
Raspberry Pi 4 Model B (1GB Ram)
DHT11 temperature and humidity sensor
Breadboard
Jumper wires
Raspbian OS (latest version)
Python 3.x
`Adafruit_DHT` library (install using `pip install Adafruit_DHT`)
Code:
```python
import Adafruit_DHT
# Set up the DHT11 sensor
sensor = Adafruit_DHT.DHT11
# Define the GPIO pin for the DHT11 sensor
DHT_PIN = 4
while True:
# Read temperature and humidity data
humidity, temperature = Adafruit_DHT.read_retry(sensor, DHT_PIN)
# Print the data
print("Temperature: {:.1f}C Humidity: {:.1f}%".format(temperature, humidity))
# Wait 5 seconds before taking the next reading
time.sleep(5)
```
Explanation:
This code uses the `Adafruit_DHT` library to interact with the DHT11 sensor. It sets up the sensor and defines the GPIO pin used to connect it to the Raspberry Pi. The code then enters an infinite loop, reading temperature and humidity data every 5 seconds using the `read_retry()` function and printing it to the console.
These examples demonstrate the versatility and ease of use of the Raspberry Pi 4 Model B (1GB Ram) in IoT and robotics projects.