Raspberry Pi Notes
Raspberry Pi Notes
The Raspberry Pi is a small, affordable, single board computer developed by the Raspberry
Pi Foundation. It was designed to promote the teaching of computer science and
programming in schools and developing countries. Over time, it has evolved from a tool for
educational use to a versatile platform for DIY projects, industrial applications, and much
more.
The Raspberry Pi was first released in 2012 with the goal of making computer science more
accessible and affordable to people around the world. The Pi aimed to provide a low cost,
basic computer to teach programming and computational thinking. It has since gained
popularity among hobbyists, engineers, and developers for a wide range of applications.
2. Key Features
Each Raspberry Pi board typically includes the following features (varies depending on the
model):
Networking: Ethernet port for wired networking (Gigabit on newer models) and
builtin WiFi (starting with Raspberry Pi 3).
Storage: MicroSD card slot for storing the operating system and files (although newer
models also have eMMC support).
Camera Interface: Camera Serial Interface (CSI) for connecting a camera module.
Display Interface: Display Serial Interface (DSI) for connecting a compatible
display.
Audio Output: 3.5mm audio jack and support for HDMI audio.
Power Supply: Typically powered by a 5V USBC or microUSB power supply.
The Raspberry Pi Foundation has released multiple models since 2012, each with different
features and performance:
The Raspberry Pi supports various operating systems, the most popular being Raspberry Pi
OS (formerly Raspbian), which is a Debian based Linux distribution designed specifically for
the Pi. However, the Pi can also run other operating systems like:
Operating systems are typically loaded onto a microSD card, which serves as the primary
storage for the system.
The Raspberry Pi is extremely versatile and has found its way into countless applications:
Robotics: Use the GPIO pins and various sensors to build robots.
Media Center: Use it as a lowcost media center to stream music and videos.
Web Server: Host a website or web application on the Pi.
Networking Projects: Pi can be used as a network server, VPN, or firewall.
IoT Projects: Create Internet of Things (IoT) devices for monitoring or automation.
Gaming: Set up retro gaming emulators (RetroPie) or even run lightweight games.
Programming on the Raspberry Pi can be done in several languages, with Python being the
most commonly used due to its simplicity and the large number of libraries available for
interacting with the Pi's hardware.
WiFi: The Raspberry Pi 3 and 4 have builtin WiFi, allowing for easy wireless
networking.
Ethernet: For reliable, fast networking, particularly with the Raspberry Pi 4, which
has Gigabit Ethernet.
Bluetooth: Supported in the Raspberry Pi 3 and 4, useful for connecting devices like
headphones, keyboards, or even controlling other hardware wirelessly.
The Raspberry Pi has a large, active community that contributes tutorials, software, and
hardware projects. Resources for the Pi are readily available, from official documentation to
forums, YouTube tutorials, and books. The ecosystem includes accessories like:
9. Power Supply
The Pi typically requires a stable 5V power supply, with newer models using USBC (for
Raspberry Pi 4) or microUSB (for earlier models). Powering the Pi is crucial, as unstable or
underpowered conditions can lead to system crashes or instability.
Performance: While powerful for its size, the Raspberry Pi is not as fast as a desktop
PC. Tasks like video editing or highperformance gaming are generally not suitable for
the Pi.
Storage: Dependent on the microSD card for storage, which is slower compared to
solidstate drives (SSD) or hard drives.
Limited I/O: Although it has GPIO pins for hardware interfacing, the Pi’s number of
USB ports, network connectivity, and video outputs is limited compared to a
fullfledged PC.
Program Explanation:
The script sets up GPIO 18 as an output pin.
It enters a loop to turn the LED on and off every second.
A `try`/`except` block handles graceful exit (e.g., Ctrl+C) and cleans up GPIO
settings.
How to Run:
1. Save the code to a file, e.g., `blink_led.py`.
2. Open a terminal on the Raspberry Pi.
PROGRAM
import RPi.GPIO as GPIO
import time
try:
while True:
# Turn LED on
GPIO.output(LED_PIN, GPIO.HIGH)
print("LED ON")
time.sleep(1) # Wait for 1 second
except KeyboardInterrupt:
print("\nProgram terminated by user")
finally:
# Clean up GPIO settings
GPIO.cleanup()
print("GPIO cleaned up")
Notes:
GPIO Mode: The script uses BCM numbering (GPIO 18). If you prefer BOARD
numbering (pin 12), change `GPIO.setmode(GPIO.BCM)` to
`GPIO.setmode(GPIO.BOARD)` and adjust `LED_PIN = 12`.
Safety: Always use a resistor with the LED to prevent damage. Check your LED’s
forward voltage and current rating.
Troubleshooting:
If the LED doesn’t blink, verify connections, ensure the LED is oriented correctly,
and confirm `RPi.GPIO` is installed.
Run `sudo raspigpio get 18` to check the pin’s state.
Customization: Adjust `time.sleep(1)` to change the blink rate (e.g., `0.5` for faster
blinking).
If you want a different GPIO pin or additional features (e.g., multiple LEDs), let me
know, and I can modify the code.
5. df -h
- Description: Displays disk space usage for mounted filesystems in a human-readable
format.
- Example: `df -h` shows available and used space on the SD card or external drives.
Package Management
6. sudo apt update
- Description: Updates the package lists for upgrades and new package installations from
the repositories.
- Example: Run before installing or upgrading software to ensure the latest package
information.
13. rm <file_or_directory>
- Description: Deletes files or directories. Use `-r` for recursive deletion of directories.
- Example: `rm -r old_project` deletes the `old_project` directory and its contents.
14. cp <source> <destination>
- Description: Copies files or directories. Use `-r` for recursive copying of directories.
- Example: `cp file.txt /home/pi/backup/` copies `file.txt` to the backup folder.
15. mv <source> <destination>
- Description: Moves or renames files or directories.
- Example: `mv file.txt new_file.txt` renames `file.txt` to `new_file.txt`.
System Configuration
16. sudo raspi-config
- Description: Opens the Raspberry Pi configuration tool to set up system options like boot
settings, network, and overclocking.
- Example: Use to enable SSH, VNC, or expand the filesystem.
17. sudo passwd
- Description: Changes the password for the current user (default is `pi`).
- Example: Run to secure the default user account.
18. sudo hostnamectl set-hostname <new_hostname>
- Description: Changes the hostname of the Raspberry Pi.
- Example: `sudo hostnamectl set-hostname mypi` sets the hostname to `mypi`.
Network Management
19. ifconfig or ip a
- Description: Displays network interface information, such as IP addresses for Ethernet
(`eth0`) or Wi-Fi (`wlan0`).
- Example: `ip a` shows active network interfaces and their configurations.
20. ping <hostname_or_ip>
- Description: Tests network connectivity to a host or IP address.
- Example: `ping 8.8.8.8` checks connectivity to Google’s DNS server.
21. sudo systemctl restart networking
Process Management
22. top or htop
- Description: Displays real-time system processes, CPU, and memory usage. (`htop` is
more user-friendly but may need installation via `sudo apt install htop`).
- Example: Use to monitor running applications and system load.
23. ps aux
- Description: Lists all running processes with detailed information.
- Example: `ps aux | grep python` finds all Python processes.
24. kill <pid> or killall <process_name>
- Description: Terminates a process by its process ID (`pid`) or name. Use `sudo` if
needed.
- Example: `kill 1234` stops the process with PID 1234; `killall python` stops all Python
processes.
System Control
25. sudo reboot
- Description: Reboots the Raspberry Pi.
- Example: Used after installing updates or changing system settings.
26. sudo shutdown -h now
- Description: Shuts down the Raspberry Pi immediately.
- Example: Safely powers off the system to avoid SD card corruption.
27. sudo systemctl <start|stop|restart> <service>
- Description: Manages system services (e.g., SSH, Apache).
- Example: `sudo systemctl start ssh` starts the SSH service.
File Editing
30. nano <filename>
- Description: Opens a file in the Nano text editor for editing.
- Example: `nano /etc/wpa_supplicant/wpa_supplicant.conf` to edit Wi-Fi settings.
31. cat <filename>
- Description: Displays the contents of a file.
- Example: `cat /etc/hostname` shows the current hostname.
Miscellaneous
34. man <command>
- Description: Displays the manual page for a specified command.
- Example: `man ls` shows detailed documentation for the `ls` command.
35. history
- Description: Lists previously executed commands in the terminal.
- Example: Use to recall and reuse commands.
Notes
- sudo: Many commands require super user privileges, so prepend `sudo` to run them as an
administrator.
- Raspberry Pi OS: These commands assume Raspberry Pi OS (Debian-based). Some may
differ in other Linux distributions.
- Contextual Usage: Commands like `vcgencmd` and `raspi-config` are specific to Raspberry
Pi hardware.