1. What is Raspberry Pi?
- Raspberry Pi is a low-cost, credit-card-sized computer developed by the Raspberry Pi Foundation.
- Used For:
- Learning to program
- IoT projects
- Robotics
- Home automation
- Media centers
2. Models of Raspberry Pi
- Raspberry Pi 5 (2GB/4GB/8GB RAM)
- Raspberry Pi 4 (2GB/4GB/8GB RAM)
- Raspberry Pi 3 Model B/B+
- Raspberry Pi Zeros (Compact version)
- Raspberry Pi Picos (Microcontroller)
3. Setting Up Raspberry Pi
What You Need:
- Raspberry Pi Board
- microSD Card (16GB+ recommended)
- Power Supply (USB-C for Pi 4, Micro-USB for Pi 3)
- HDMI Cable and Monitor
- Keyboard & Mouse
- Internet (Ethernet/WiFi)
Steps:
- Download Raspberry Pi OS:
https://www.raspberrypi.org/software/ - Flash OS to microSD:
Use Raspberry Pi Imager or balenaEtcher to write the OS to the card. - Insert microSD Card: Insert into Pi’s slot.
- Connect Peripherals: Attach keyboard, mouse, and HDMI.
- Power On: Connect power. Pi will boot.
4. First Boot & Configuration
sudo raspi-config
- Change User Password
- Set WiFi (Network Options)
- Enable SSH, I2C, SPI (Interface Options)
- Expand Filesystem (Advanced)
- Set Locale and Timezone
5. Useful Commands
sudo apt update && sudo apt upgrade # Update system sudo reboot # Reboot sudo shutdown -h now # Shutdown ifconfig # Show IP address ping google.com # Test internet connection
6. Enable SSH for Remote Access
- Run:
sudo systemctl enable ssh sudo systemctl start ssh
- Connect via SSH (from another computer):
ssh pi@<Raspberry_Pi_IP>
Default Login:
- Username: pi
- Password: raspberry
7. GPIO (General Purpose Input/Output)
- 40-Pin Header (Raspberry Pi 4/3): Used for electronics and sensors.
- Voltage Levels:
- 3.3V Logic (Pins can be damaged by 5V)
- GPIO Pins: Control LEDs, read sensors.
Pinout Diagram (Important Pins):
Pin | Function |
---|---|
1 (3.3V) | Power |
2 (5V) | Power |
6 (GND) | Ground |
7 (GPIO4) | General Purpose I/O |
11 (GPIO17) | Control LEDs/Sensors |
8. Basic Python GPIO Control
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # Use BCM pin numbering GPIO.setup(18, GPIO.OUT) while True: GPIO.output(18, GPIO.HIGH) # LED On time.sleep(1) GPIO.output(18, GPIO.LOW) # LED Off time.sleep(1)
- Run Script:
python3 led.py
9. Install and Update Software
sudo apt install python3-pip # Install pip for Python 3 sudo apt install git # Install Git pip3 install flask # Install Flask (Web Development)
10. Connecting to WiFi (CLI)
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add:
network={ ssid="Your_WiFi_Name" psk="Your_WiFi_Password" }
Save and reboot:
sudo reboot
11. Install VNC (Remote Desktop)
sudo apt install realvnc-vnc-server sudo systemctl enable vncserver-x11-serviced
- Access the Pi desktop from another computer using VNC Viewer.
12. Basic Projects to Try
- LED Blinking
- Temperature Sensor (DS18B20)
- Web Server (Flask or Node-RED)
- Media Center (Install Kodi)
- Home Automation (Relays, Sensors)
13. Camera Module (PiCam)
sudo raspi-config
- Enable Camera Interface.
- Capture Image:
raspistill -o image.jpg
- Record Video:
raspivid -o video.h264 -t 10000 # 10 seconds
14. I2C and SPI (For Sensors/Modules)
sudo raspi-config
- Enable I2C or SPI under Interface Options.
- Install tools:
sudo apt install i2c-tools
- Detect I2C Devices:
i2cdetect -y 1
15. Backup and Restore Raspberry Pi
- Backup SD Card (Linux/Mac):
sudo dd if=/dev/sdX of=backup.img bs=4M
- Restore Backup:
sudo dd if=backup.img of=/dev/sdX bs=4M
16. Python Libraries for Raspberry Pi
- GPIO Control: RPi.GPIO
- Sensors (I2C): smbus2
- Web Development: Flask
- AI/ML: TensorFlow Lite
- GUI: tkinter
Example Project: Temperature Logger
import Adafruit_DHT import time sensor = Adafruit_DHT.DHT11 pin = 4 # GPIO pin while True: humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if humidity is not None and temperature is not None: print(f"Temp: {temperature:.1f}C Humidity: {humidity:.1f}%") else: print("Failed to retrieve data.") time.sleep(2)