July 22, 2018

IoT Project 2 : RaspberryPi3, BMP085 Sensor and Thingspeak(Avinash Aeron)

I was looking for the pressure sensor for building another IOT project and got BMP085 sensor package (pressure and temperature sensor). Another simple IOT project initiated with Raspberry Pi3 that I have been using for a while. Here are the details:

Required items:
– Raspberry PI 3 & SD Card with ubuntu-mate Operating System https://www.raspberrypi.org/products/raspberry-pi-3-model-b/
– BMP085 sensor pack
– 4 x pitch jumpers

Preparing Raspberry PI 3 & SHDC:
Create the setup as follows:
1. Download below two as described https://ubuntu-mate.org/raspberry-pi/
– 7-Zip to extract the image.
– Win32 Disk Imager to write the image.
2. Extracted ‘ubuntu-mate from zip and flashed SHCD using Win32 Disk Imager
3. Put the SHCD into slot and power-up the Raspberry PI 3.
4. After ubuntu-mate is up, execute following on the terminal:

CODE: SELECT ALL
sudo apt-get update
sudo apt-get upgrade

5. After a successful upgrade, get the Adafruit_Python_DHT from GitHub (see reference):
If you have not installed git, install it now:

CODE: SELECT ALL
sudo apt-get install git

Get the code from GitHub:

CODE: SELECT ALL
git clone https://github.com/adafruit/Adafruit_Python_BMP
cd Adafruit_Python_BMP
sudo python setup.py

6. python script used for this experiment:

CODE: SELECT ALL
"""
My First Internet of Things

Temperature/Humidity/Pressure monitor using Raspberry Pi, DHT11, and BMP085
Data is displayed at thingspeak.com
2016-June-15
"""
# Import all the libraries we need to run
import sys
import RPi.GPIO as GPIO
import os
from time import sleep
import math
import Adafruit_DHT
import urllib2
import Adafruit_BMP.BMP085 as BMP085

sensor = BMP085.BMP085()

DEBUG = 1
# Setup the pins we are connect to
RCpin = 24
DHTpin = 4

# Constants for Dew Point cumputation
DPB = 17.6 # 17.67 to be accurate
DPC = 243.5

#Setup our API and delay
myAPI = "MMC6LWE2DVMYFNPU"
myDelay = 15 #how many seconds between posting data

GPIO.setmode(GPIO.BCM)
#GPIO.setup(RCpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def getSensorData():
RHW, TW = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)

#Convert from Celius to Farenheit
TWF = 9*TW/5+32

# return dict
return (str(RHW), str(TW), str(TWF))

def computeDewPoint():

RHW, TW = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)

LGMA  = math.log(RHW/100)
DPTW = DPC+TW
GMA = DPB*TW/DPTW+LGMA
DPBGMA = DPB-GMA
DEWPC = DPC*GMA/DPBGMA

# return dict
return (str(DEWPC))

def getPressureData():

APHA = sensor.read_pressure()

MSLP = sensor.read_sealevel_pressure()

# return dict
return (str(APHA), str(MSLP))

# main() function
def main():

print 'starting...'

baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
print baseURL

while True:
try:
RHW, TW, TWF = getSensorData()

DEWPC = computeDewPoint()

APHA, MSLP = getPressureData()
LT = "0"
#            print TW + "C " + TWF+ "F " + RHW + "% " + DEWPC + "C " + LT

f = urllib2.urlopen(baseURL +
"&field1=%s&field2=%s&field3=%s&field4=%s&field5=%s" % (TW, DEWPC, RHW, APHA, MSLP)+
"&field6=%s" % (LT))
print f.read()
print TW + "*C " + TWF+ "*F " + RHW + "% " + DEWPC +"*C "+ APHA + "Pa " + MSLP + "Pa " + LT
f.close()

sleep(int(myDelay))
except:
print " "
print TW + "*C " + TWF + "*F " + RHW + "% "
print 'exiting.'
break

# call main
if __name__ == '__main__':
main()

Enable i2c :
Follow instructions (see reference – Steps to enable i2c on Rpi)

Setup BMP085 with Raspberry Pi:
Connect as illustrated in picture:
VCC (BMP085 board) <-> pin17 (RPi-3 3.3v)
Ground (BMP085 board) <-> pin20 (RPi-3 Ground)
SDA (BMP085 board) <-> pin03 (RPi-3 GPIO-02 / SDA I2c)
SCL (BMP085 board) <-> pin05 (RPi-3 GPIO-03 / SCL I2c)

RPi_BMP085_connection.jpg
connection between RPi and BMP085

Setup Thingspeak:
Create your account at https://thingspeak.com/
Create your channel and set it up as you wish. Instructions are on the website.
The one created for this experiment is here:

Screenshot_IOT.png
screen-shot of Thingspeak channel

Here you go!
execute the python script and monitor data on web.

On the Android smart-phone:
Install ThingView from Google Play Store
Log in to your account and setup channel. You are done! All data on your smart-phone.

Screenshot_2016-06-29-23-26-19.png
ThingView screen-shot
Screenshot_2016-06-30-18-33-42.png
ThingView screen-shot 2

References:
This blog has been a help in quickly setting up:
http://raspi.tv/2012/how-to-set-up-a-barometric-pressure-sensor-bmp085-on-raspberry-pi-with-raspbian

RPi-3 pin diagram has been picked from here:
https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/

Datasheet for BMP085 can be found here:
https://www.sparkfun.com/datasheets/Components/General/BST-BMP085-DS000-05.pdf

BMP085 library on GitHub:
https://github.com/adafruit/Adafruit_Python_BMP

Steps to enable i2c on Rpi:
http://skpang.co.uk/blog/archives/575

Leave a Reply

Your email address will not be published. Required fields are marked *