Embedded Software Development with Python and the Raspberry Pi Class 5: An Internet of Things Weather Station Example August 22, 2014 Jacob Beningo, CSDP © All Images and content in this presentation may not be used or copied without express written permission of the owner.
Course Overview Introduction to Python Python Fundamentals An Overview of the Raspberry Pi Controlling Raspberry Pi Peripherals with Python An Internet of Things Weather Station Example
Session Overview An IoT Weather Station Example The Personal Weather Station (PWS) Setup a PWS Account Temperature & Humidity Sensors PWS Application PWS Results Script Automation
The Personal Weather Station (PWS) Thermometer Barometer Anemometer Hygrometer Wind vanes UV index Soil moistness And more!
The Personal Weather Station (PWS)
The Personal Weather Station (PWS) Weather Underground Resources http://www.wunderground.com/weatherstation/about.asp http://wiki.wunderground.com/index.php/PWS_-_Personal_Weather_Stations http://wiki.wunderground.com/index.php/PWS_-_Upload_Protocol
Setup a PWS Account Registering at Weather Underground
Setup A PWS Account PWS Location
Temperature and Humidity Sensors AM2302 (DHT22) Capacitive Humidity Sensor 0 – 99.9% +/- 2% Thermistor for Temperature -40 to 80 C +/- 0.5 C Digital Single Wire Read Sample Rate 0.5 Hz ( relatively slow!)
Temperature and Humidity Sensors AM2302 (DHT22) Wiring Red (3.3V – PI Pin 1) Yellow (Data – PI Pin 7) Black ( Ground – PI Pin 6)
Temperature and Humidity Sensors AM2302 (DHT22) Communication Protocol Manchester “like” encoding Bit-Bang GPIO using a low level C driver Installing the Low Level C Driver Wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.36.tar.gz -O bcm2835-1.36.tar.gz
Temperature and Humidity Sensor Installing the Adafruit DHT Python Driver git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT sudo apt-get upgrade sudo apt-get install build-essential python-dev sudo python setup.py install Test the Sensor sudo python AdafruitDHT.py 22 4 cd Adafruit_Python_DHT/examples Sensor Type GPIO 4
Personal Weather Station Application Application Design Read DHT Sensor Delay 5 s Send Data Verify Sensor Data Invalid Prepare Weather URL String Convert Temperature
Personal Weather Station Application Script Dependencies Why urllib? datetime.utcnow()
Personal Weather Station Application Configuration datetime.utcnow()
Personal Weather Station Application Reading and verifying the sensor datetime.utcnow()
Personal Weather Station Application Web Connection datetime.utcnow()
Personal Weather Station Application Web Connection Error Checking datetime.utcnow()
PWS Results It is live!
PWS Results
Script Automation Login Automatically Script start on login sudo nano /etc/initab comment out 1:2345:respawn:/sbin/getty 115200 tty1 Add 1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1 Script start on login nano ~/.bashrc At the bottom add “sudo python /path/pws.py”
Going Further Download Template Materials for Web Tutorials YouTube Python Doxygen Script Template Personal Weather Station Python Script Raspberry Pi Example Python Scripts Web Tutorials YouTube From www.beningo.com under Blog and Articles > Software Techniques > Embedded Software with Python
Contact Information P.O. Box 400 Linden, Michigan 48451 : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Jacob Beningo Principal Consultant © All Images and content in this presentation may not be used or copied without express written permission of the owner.