Raspberry Pi Learning Resources Collection

Raspberry Pi Learning Resources Collection
Raspberry Pi Learning Resources Collection
Software and Tool Resources
-
SD card formatting software for Windows: SD Formatter
-
[Operating system image writing tool for Windows](Win32 Disk Imager)
-
Remote desktop access via VNC
Install tightvncserver on the Raspberry Pi, and install RealVNC on the computer.
- Remote desktop access via RDP (better performance than VNC)
Install xrdp on the Raspberry Pi, and use the mstsc command on Windows.
-
Remote access to the Raspberry Pi via SSH. On Windows, available tools include PuTTY and [XSHELL](Products : Xshell 5)
-
A useful open-source archive utility for Windows: [Bandizip](Download Free Zip Archiver to open ZIP, RAR, 7z files)
-
Open-source FTP server and client software: [FileZilla](The free FTP solution)
-
Domestic PyPI mirror from Douban. Add the suffix after the
pipcommand, for example:pip install pygame -i Simple Index
Raspberry Pi Operation and Usage
- Configuration file
/boot/config.txt
- IP address configuration file
/etc/network/interfaces
- DHCP configuration files (if using a static IP, clear them with the following command)
sudo rm /var/lib/dhcp/*
- Hostname/network name configuration file
/etc/hosts
- Configuration command
sudo raspi-config
- Take a photo with the camera
rapistill -o xxx.jpg
- Record video with the camera (ms)
raspivid -o video.h264 -t 10000
- Use the Raspberry Pi as a network-attached storage server
sudo apt-get install samba
sudo apt-get install samba-common-bin
Add a Samba user:
sudo smbpasswd -a xxx
Modify the workgroup on the first line of /etc/samba/smb.conf
Add the following at the bottom:
[USB]
path=/media/NAS
comment= NAS driver
valid users=xxx
writeable=yes
browseable=yes
create mask=0777
public=yes
Restart Samba.
- Network print server: CUPS
sudo apt-get install cups
sudo usermod -a -G lpadmin xxx
Install a browser for web-based management, using port 631:
sudo apt-get install iceweasel
- Screenshot tool:
scrot
sudo apt-get install scrot
- Delayed screenshot
scrot -d 5
- Interactive mouse selection screenshot
scrot -s
- I2C communication tools
sudo apt-get install i2c-tools
sudo i2cdetect -y 1 // for older versions, change 1 to 0
- Serial port monitoring tool:
minicom
sudo apt-get install minicom
minicom -b 9600 -o -D /dev/ttyAMA0
First enable local echo to see feedback: Ctrl+A, Z, E
Raspberry Pi Hardware
-
Safety guidelines
-
Voltage on GPIO pins must not exceed 3.3V
-
Output current per pin must not exceed 3mA
-
Power supply voltage must not exceed 5V
-
Total output current of the 5V supply should not exceed 250mA
-
The simplest voltage conversion method is to use a resistor divider with 470 ohms and 220 ohms in series. You can also scale this proportionally to 47k and 22k to reduce current loss.
-
GPIO output capability summary reference article
-
Raspberry Pi accessories
-
Raspberry Squid, an accessory with built-in resistors, LEDs, and buttons. Includes a Python squid library.
-
You can use the motor driver RasPiRobot Board to power the Raspberry Pi. The motor driver board Python library is
raspirobotboard. -
Sensor interface board [SenseHAT], with Python libraries such as
sense-hat,SenseHAT, andexplorerhat -
[Compute Module](Raspberry Pi Compute Module: new product! - Raspberry Pi)
-
Pi Plate prototyping board for soldering components and rapid development
-
You can design your own prototype board that complies with the HAT standard. Enable
dtparam=i2cvc=onin the config file, and use the EEPROM flashing tool -
AC power switching accessory: PowerSwitch Tail II (opto-isolator + relay module)
-
For precise servo motor control, you can use the Servo Blaster library
-
To control multiple servo motors at the same time, you can use Adafruit's servo motor HAT (Hardware Attached on Top), see the Adafruit documentation
-
To control DC motors, you can build an H-bridge using a chip such as the L293D, or use an H-bridge module from SparkFun
-
To control stepper motors, you can use RaspiRobot
-
To detect motion, you can use a passive infrared motion detector (PIR)
-
To measure resistance, you can connect a capacitor and estimate the value by measuring the capacitor charging time
-
The Raspberry Pi does not have built-in analog input. Analog signal acquisition can be implemented using an ADC module such as the MCP3008
-
For temperature measurement, you can use the less accurate TMP36 or the high-precision digital temperature sensor DS18B20
-
For measuring temperature, humidity, and air pressure, use the [Sense HAT](API Reference - Sense HAT)
-
The aLaMode board (an Arduino platform with GPIO interface). Due to a design flaw in aLaMode, you need to wrap a little insulating tape around the Raspberry Pi Ethernet port.
Quick Uses for Raspberry Pi
-
Media center: install the
OpenELEC_Pi2system and use [Kodi](Official Kodi Wiki) -
Office software:
abiword,gnumeric -
Browser:
chromium-browser -
Webcam server: install
motion -
Configuration
sudo vim /etc/motion/motion.conf
# change daemon off to on
# change webcam_localhost=on to off
sudo vim /etc/default/motion
# change sart_motion_daemon=no to yes
-
Start it with:
service motion start -
Run classic emulator games: install
stella -
Install JDK and run Minecraft (this software is already installed on Raspberry Pi 3)
sudo apt-get install openjdk7-jkd(you may need to update to version 8)
wget http://getspigot.org/spigot18/spigot_server.jar
java -Xms512M -Xmx800M -jar spigot_server.jar nogui
# sudo vim eula.txt
# change eula=false to true
-
Run the game [Open Arena](OpenArena EX - オープンアリーナ) (very violent)
-
FM transmitter: install the
pifmlibrary. Attach a short wire to GPIO pin 4 as an antenna.
mkdir pifm
cd pifm
wget http://www.icrobotics.co.uk/wiki/imagies/c/c3/Pifm.tar.gz
tar -xzf Pifm.tar.gz
sudo ./pifm sound.wav 103.0 # audio file and frequency to play
- Image processing: GIMP
sudo apt-get install gimp
-
Listen to internet radio:
vlc -
GPS modules:
gpsdandgpsd-clients, commands:cgps -s,xgps -
To communicate with Arduino, you can use
pyserialover serial, or install PyFirmata firmware on the Arduino
Linux Command Reference
- View IP address
ifconfig (this command is already outdated in the book)
ip a
- Run a script automatically at system startup
Modify /etc/rc.local
Add something like this on the first line:
/user/bin python /home/pi/my_program.py &
The & symbol means run in the background. Otherwise, the system may fail to boot into the desktop properly. Very important.
- Make a script run automatically
/etc/init.d/my_server (my_server is a custom script file)
sudo chmod +x /etc/init.d/my_server (add execution permission)
-
Run scripts periodically:
crontab -e -
Search files:
find /home/pi(starting directory)-name abc.py -
View command history:
history !x(execute the x-th command in history) -
List USB devices:
lsusb -
Redirect command output to a file:
ls > abc.txt -
Concatenate files:
cat a.txt b.txt > c.txt -
Pipes and regular expressions:
ls *.py | grep Jun -
Suppress output:
ls > /dev/null -
Run in background:
abc.py &, bring back to foreground withfg -
Alias:
alias l='ls -a' -
Apply changes to a file immediately:
source .bashrc -
Change system time:
sudo date 010203042031(MMDDHHMMYYYY) -
Disk space:
df -h
Python Computer Vision
- Install SimpleCV
sudo apt-get update
sudo apt-get install ipython python-opencv python-scipy
sudo apt-get install python-numpy python-setuptools python-pip
sudo pip install svgwrite
sudo pip install https://github.com/sightmachine/SimpleCV/zipball/master
Run SimpleCV
- Example program using Python and the Raspberry Pi camera
import picamera
from SimpleCV import *
def get_camera_image():
with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
camera.awb_mode = 'off'
camera.capture('tmp.jpg')
return Image('tmp.jpg')
-
Python [picamera](picamera - Picamera 1.13 Documentation) documentation
-
Edge detection. Parameters: Canny edge detection,
threshdetermines the required edge length,distanceis the distance between circles.
SimpleCV:1> c=Camera()
SimpleCV:2> i=c.getImage()
SimpleCV:3> i.show - best i source and related information.()
SimpleCV:4> i2=i.invert()
SimpleCV:5> i2.show()
SimpleCV:6> coins=i2.findCircle(canny=100,thresh=70,distance=15)
SimpleCV:7> coins
SimpleCV:8> coins.draw(width=4)
SimpleCV:9> coins.show()
from SimpleCV import *
c = Camera()
while True:
i = c.getImage().invert()
coins = i.findCircle(canny=100, thresh=70, distance=1)
print(len(coins))
-
Face detection:
findHaarFeaturesHaar feature reference -
Motion detection: blob detection,
findBlobs -
Optical character recognition (OCR): install
tesseract -
To control LEDs with as few pins as possible, you can use [Charlieplexing](Charlieplexing - Wikipedia)
Python Control of Raspberry Pi Hardware
- Turn an LED on and off. Python needs superuser privileges to call the
RPi.GPIOlibrary, so run it withsudo python led_blink.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
try:
while True:
GPIO.output(18, True)
time.sleep(0.5)
GPIO.output(18, False)
time.sleep(0.5)
finally:
GPIO.cleanup() # safety mode: reset GPIO pins to input state to avoid short circuits
- PWM output
import RPi.GPIO as GPIO
led_pin = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
pwm_led = GPIO.PWM(led_pin, 500)
pwm_led.start(100)
while True:
duty_s = input("Brightness input (0-100):")
duty = int(duty_s)
pwm_led.ChangeDutyCycle(duty)
- PWM control program with GUI
from tkinter import *
import RPi.GPIO as GPIO
import time
led_pin = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.check_var = BooleanVar()
check = Checkbutton(
frame,
text='Pin 18',
command=self.update,
variable=self.check_var,
onvalue=True,
offvalue=False
)
check.grid(row=1)
def update(self):
GPIO.output(led_pin, self.check_var.get())
root = Tk()
root.wm_title('On/Off Switch')
app = App(root)
root.geometry("200x50+0+0")
root.mainloop()
- PWM output
import RPi.GPIO as GPIO
import time
led_pin = 18
GPIO.setmode(GPIO.BCM)
# callback function
def my_callback(channel):
print('You pressed the button')
GPIO.setup(led_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# bouncetime is the GPIO library's built-in debounce feature
GPIO.add_event_detect(led_pin, GPIO.FALLING, callback=my_callback, bouncetime=100)
i = 0
while True:
i = i + 1
print(i)
time.sleep(1)
- Use RaspiRobot to control a bipolar stepper motor
from rrb3 import *
import time
rr = RRB3(12.0, 12.0) # battery, motor
try:
while True:
delay = input("Delay milliseconds between steps:")
steps = input("How many steps forward?")
rr.step_forward(int(delay) / 1000.0, int(steps))
steps = input("How many steps backward?")
rr.step_reverse(int(delay) / 1000.0, int(steps))
finally:
GPIO.cleanup()
- Use
pygameto detect keyboard and mouse movement
import pygame
import sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.mouse.set_visible(0)


