Raspberry Pi Detailed Notes
Raspberry Pi Detailed Notes
Definition:
Raspberry Pi is a small, affordable, single-board computer developed to promote computer
science education and DIY projects. It is open platform hardware, meaning users can
develop, program, and interface with external devices using its General Purpose
Input/Output (GPIO) pins.
Architecture:
Raspberry Pi uses an ARM-based processor (usually Broadcom SoC - System on Chip). The
architecture includes:
- ARM CPU
- RAM (varies from 512MB to 8GB)
- GPIO pins for interfacing
- USB ports for input devices
- HDMI port for display
- Ethernet or Wi-Fi for networking
- CSI (Camera Serial Interface)
- DSI (Display Serial Interface)
- SD card slot for storage and operating system
Logging in:
- Default username: pi
- Default password: raspberry
- Login through connected monitor or SSH (if enabled)
Starting the Raspbian GUI:
- Command to start GUI: startx
- The GUI provides a desktop-like interface to access files, programs, and settings
Raspberry Pi Interfacing:
Interfacing is how external components communicate with the Raspberry Pi using GPIO and
communication protocols.
Raspberry Pi Programming:
- Programming language: Mostly Python
- Libraries:
- RPi.GPIO: Basic GPIO control
- gpiozero: Simplified interface for common tasks
- Python code can control sensors, actuators, LEDs, switches, and more
Python Code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.cleanup()
Python Code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT) # LED
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Switch
while True:
if GPIO.input(17) == GPIO.HIGH:
GPIO.output(18, GPIO.HIGH)
else:
GPIO.output(18, GPIO.LOW)
Python Code:
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
def read_channel(channel):
adc = spi.xfer2([1, (8+channel)<<4, 0])
data = ((adc[1]&3) << 8) + adc[2]
return data
while True:
light_level = read_channel(0)
print("Light Level:", light_level)
time.sleep(1)