12. NETWORKING WITH THE PI
Builtin Ethernet for wired connections
Wireless also supported when attached to a
compatible WiFi dongle
We will connect to the Pi through a network
using SSH
32. TURNING THE PI OFF
1. Run this command
2. Wait for the lights to stop flashing
3. Disconnect the USB power cable from the Pi
or
switch off the power socket
sudo halt
45. READING A SWITCH
TO CONTROL LED PATTERN
Get the script
And run it
Press the switch and watch the LED patterns
change
~/thinkerers/06‐switch‐led.py
sudo python 06‐switch‐led.py
61. CONTROLLING A SERVO MOTOR
The Pi isn't actually good for servo control
Only one PWM pin GPIO18
Linux OS interrupts the pulse generated
Both software and hardware solutions available
63. CONTROLLING A SERVO MOTOR
Script to use:
Execute the script
Enter angle between 0 and 180 degrees
~/thinkerers/09‐servo‐motor.py
sudo python 09‐servo‐motor.py
66. CONTROLLING A MOTOR
BASED ON LIGHT
Get the script
And run it
Enter a light level around 7
Slowly cover / uncover the LDR and watch the
motor move
~/thinkerers/10‐light‐dc‐motor.py
sudo python 10‐light‐dc‐motor.py
68. RUN A SIMPLE FILE SERVER
Create a directory
Change to that directory
Create a test file, enter some text, and save it
Run this
mkdir ~/website
cd ~/website
nano test.txt
sudo python ‐m SimpleHTTPServer 80
69. RUN A SIMPLE FILE SERVER
Enter your Pi's IP address into your browser's
address bar:
Can you see the test file you created?
http://10.1.1.XXX/
71. WEB SERVER + SENSOR
Load temperature sensor modules
Check if module detected the sensor
A file with the name "28xxxxxxxx" should exist
sudo modprobe w1‐gpio
sudo modprobe w1‐therm
cd /sys/bus/w1/devices
75. CHANGING THE PI'S IP ADDRESS
Edit the configuration file
Modify these lines to match your local network
For example:
sudo nano /etc/network/interfaces
address 10.1.1.XXX
gateway 10.1.1.1
address 192.168.0.XXX
gateway 192.168.0.1
76. CHANGING THE WIRELESS NETWORK
Edit the configuration file
Modify the ssid and psk values to match your
local network
For example:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ssid="MyWirelessSSID"
psk="MySecretPassword"