sudo reboot Why?

Download Report

Transcript sudo reboot Why?

Raspberry Pi Class
Ed 299
Mike Davis
Truman College
5/26/2015
Goals for Today
• Discuss Raspberry Camera Projects
• Fruit Rotting
• Air Powered Car
• Photo booth
• Use a Python Program to control the camera
• Copy, edit, and execute Python programs
• Connect a temperature sensor
• Make a program repeatable in Cron
• Make a local web server
• Upload the temperatures to Google
Start of Class
• Plug in the Raspberry Pi.
• Get the IP address (ifconfig).
• Log in via PuTTY from another computer.
Bash Commands
BASH
Create a File
• Bourne Again Shell
• Based on a shell that interprets
commands.
• Commands that are typed
directly into the command
terminal.
• Considered easy to use for
beginners, and powerful for
advanced users.
• sudo nano hello.sh
#! /bin/bash
echo Hello World
Save it
• sudo chmod +x hello.sh
• ./hello.sh
Bash Commands & Cron
Useful
• Anything you would want to do
from the command line can be
made into a Bash script.
• Make the script executable
• sudo chmod +x name.sh
• Execute it
• ./name.sh
Get a Python Program
• Go to:
https://www.raspberrypi.org/learning/python-picamera-setup/worksheet.md
• Find the time lapse program about 2/3 of the way down the page.
• Highlight and copy it.
• Open a file called camera.py (sudo nano camera.py)
• Paste it by right clicking
• Close and save it.
• Execute it (sudo python camera.py)
Some things to know in Python
• Python is a programming language.
• Pre-installed on the Raspberry Pi.
• Has numerous libraries that can be imported (such as picamera).
• A # at the start of the line will be ignored (commented out).
• Python programs are pretty readable and can be figured out without
a lot of effort.
Structure of a Cron Job
• * * * * * command
• Min (0-59) Hour (1-24) Day(1-31) Month (1-12) Day of the Week (1-7)
• Run the Python program starting at 6:00 every day.
• 00 18 * * * python /home/pi/camera/camera.py
• Run the Python program starting 6:00 every Monday
• 00 18 * * 1 python /home/pi/camera/camera.py
• Run the Python program whenever your start the computer
• @reboot python /home/pi/camera/camera.py
Project 2 – Make a Local Web Server
Description
Goals
• Apache is a popular web server
application that can be used to
serve up web pages on a local
network.
• It can serve up HTML pages over
HTTP.
• With additional modules you
can serve up dynamic web
pages.
• Download / install Apache
• Navigate to your local web page
• Navigate to another web page
• Make changes to your web page
How to Make it a Web Server.
Instructions
Effect
• Command
• This will look for updates to your
operating system and install them.
• sudo apt-get update
• sudo apt-get upgrade {NOT NOW}
• Command
• Sudo apt-get install apache2 -y
• Do before starting almost any project.
• If you don’t do it often, it will take a
while.
• This will download and install the
Apache application on your
Raspberry Pi.
• You must be connected to the
internet for this work.
• Take couple minutes.
Lets find your Web Page
Commands
• Make sure you know the IP
address for your RPi.
• sudo ifconfig
• In your web browser go to:
http://localhost/
• From any computer on the same
network, go to:
http://IPADDRESS/
Your Web Page
Make a Change to Your Local Web Page
Commands
What you are doing
• You have a default web page
already loaded.
• In the terminal type
• You navigating to a specific file
folder and using a text editing
program ‘nano’ to open the
index.html file.
cd /var/www/
sudo nano index.html
• Save changes.
• Refresh the web page.
Project 3 – Set up a Temperature Sensor
What we will need to do
Goals
• Build the temperature sensing
circuit.
• Test the circuit.
• Copy a python program.
• Make a temperature sensing
circuit.
• Load and execute a python
program.
• Read temperatures in Celsius.
Make the Circuit
Raspberry Pi GPIO Pins
Circuit Diagram
Connections to the Raspberry Pi
The Circuit Diagram
From the Raspberry Pi
• Connect
• Red to Pin 1 and the right prong of
the probe. (Power)
• Yellow to Pin 7 and the center
prong of the probe. (Data)
• Black to Pin 6 and the left prong
on the probe. (Ground)
Software Configuration
Commands
Why?
• In the terminal type:
sudo nano /boot/config.txt
• Go to the bottom and insert
dtoverlay=w1-gpio
• Save, close, and reboot.
sudo reboot
• I don’t know.
• This is a one time operation that
will activate one-wire devices
like the temperature probe.
• Do this once, and you don’t have
to do it again.
Software Configuration
Commands
What does this do?
• In the terminal, type:
sudo modprobe w1-gpio
sudo modprobe w1-therm
• This activates the pins for
readings.
• Type
cd /sys/bus/w1/devices
ls
cd 28*
cat w1_slave
• This goes to the folder where
that device is located. Once we
find it, we will get it read a
temperature.
You Should See This
A python program to record temperatures
• Use a python program to record lots of temperatures in a Google
Spreadsheet.
• Will require a Google account
• May require a change in your security settings
• Need to load the gspread python library
•
•
•
•
git clone https://github.com/burnash/gspread.git gspread
cd gspread
sudo python setup.py install
sudo reboot
Create A Google Spreadsheet
• Go to Drive.Google.Com
• Create a New Spreadsheet and
note the name:
• Ex. temperature
• (case sensitive)
• Download “Remove Blank Rows”
• This will put an add-on in your
Google Spreadsheets.
• Label A1 as time and B1 as
temp.
• Remove the blank rows.
A python program to record temperatures
• Download a python program from GitHub.
• sudo git clone https://github.com/MDScience/temperature.git
• cd temperature
• sudo nano temp.py
• In that program put in your Google information
• gc = gspread.login('[email protected]','password')
• worksheet = gc.open('spreadsheet_name').sheet1
• Save and close program <Cntrl x>.
• In the terminal type:
• sudo python temp.py
Make it repeatable in Cron
• This sets up operations that are scheduled to repeat at regular intervals or at regular
times.
• In the terminal type:
• sudo crontab –e
• In this program, add this line at the bottom:
• @reboot /bin/sleep 10 ; python /home/pi/temperature/temp.py &
• */1 * * * * python /home/pi/subdirectory/temp.py
• Close the program <Cntrl x>
• Reboot: sudo reboot
• Watch your Google Spreadsheet
Resources
Sign Up For
Where to Get Help / Ideas
• Element14 STEM Academy
• RaspberryPi.org
• Raspberry Pi Forum
• Element14 STEM Academy
• Make Magazine
• Adafruit
• RaspiTV