Alexandru Dragoescu
Published © GPL3+

Monitor environment with RaspberryPi

In this chapter I will explain how to use RaspberryPi to check ambient temperature, pressure, luminosity and current altitude.

Full instructions provided5,373
Monitor environment with RaspberryPi

Things used in this project

Story

Read more

Schematics

bmp180_rpi.jpg

Code

Code

Plain text
	# ls /dev/i2c*
	/dev/i2c-1

	# sudo i2cdetect -y 1
	0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
	00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
	10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- 
	40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	70: -- -- -- -- -- -- -- 77
	

Code

Plain text
	# cat read_sensor.py 

	#!/usr/bin/python

	from libs.BMP085 import BMP085
	import os
	from libs.TSL2561 import TSL2561

	# ===========================================================================
	# Example Code
	# ===========================================================================

	# Init the TSL2561 sensor class (default address is 0x39)
	Light = TSL2561(0x39)

	# Initialise the BMP085 and use STANDARD mode (default value)
	# bmp = BMP085(0x77, debug=True)
	bmp = BMP085(0x77)

	# To specify a different operating mode, uncomment one of the following:
	# bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
	# bmp = BMP085(0x77, 1)  # STANDARD Mode
	# bmp = BMP085(0x77, 2)  # HIRES Mode
	# bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode

	temp = bmp.readTemperature()

	# Read the current barometric pressure level
	pressure = bmp.readPressure()

	# To calculate altitude based on an estimated mean sea level pressure
	# (1013.25 hPa) call the function as follows, but this won't be very accurate
	altitude = bmp.readAltitude()

	# To specify a more accurate altitude, enter the correct mean sea level
	# pressure level.  For example, if the current pressure level is 1023.50 hPa
	# enter 102350 since we include two decimal places in the integer value
	# altitude = bmp.readAltitude(102350)
	print "Temperature: %.2f C" % temp
	print "Pressure:    %.2f mmHg" % (pressure / (100.0 * 1.33322) )
	print "Altitude:    %.2f m" % altitude
	print "Light:       %d lux" % Light.readLux(0)
	

Code

Plain text
	root@musicbox:/opt/rcontroller/scripts/bmp_sensor# ./read_sensor.py 
	Temperature: 32.10 C
	Pressure:    753.18 mmHg
	Altitude:    75.96 m
	Light:       0 lux 

Code

Plain text
	# ls /dev/i2c*
	/dev/i2c-1

	# sudo i2cdetect -y 1
	0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
	00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
	10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- 
	40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	70: -- -- -- -- -- -- -- 77
	

Code

Plain text
	# cat read_sensor.py 

	#!/usr/bin/python

	from libs.BMP085 import BMP085
	import os
	from libs.TSL2561 import TSL2561

	# ===========================================================================
	# Example Code
	# ===========================================================================

	# Init the TSL2561 sensor class (default address is 0x39)
	Light = TSL2561(0x39)

	# Initialise the BMP085 and use STANDARD mode (default value)
	# bmp = BMP085(0x77, debug=True)
	bmp = BMP085(0x77)

	# To specify a different operating mode, uncomment one of the following:
	# bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
	# bmp = BMP085(0x77, 1)  # STANDARD Mode
	# bmp = BMP085(0x77, 2)  # HIRES Mode
	# bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode

	temp = bmp.readTemperature()

	# Read the current barometric pressure level
	pressure = bmp.readPressure()

	# To calculate altitude based on an estimated mean sea level pressure
	# (1013.25 hPa) call the function as follows, but this won't be very accurate
	altitude = bmp.readAltitude()

	# To specify a more accurate altitude, enter the correct mean sea level
	# pressure level.  For example, if the current pressure level is 1023.50 hPa
	# enter 102350 since we include two decimal places in the integer value
	# altitude = bmp.readAltitude(102350)
	print "Temperature: %.2f C" % temp
	print "Pressure:    %.2f mmHg" % (pressure / (100.0 * 1.33322) )
	print "Altitude:    %.2f m" % altitude
	print "Light:       %d lux" % Light.readLux(0)
	

Code

Plain text
	root@musicbox:/opt/rcontroller/scripts/bmp_sensor# ./read_sensor.py 
	Temperature: 32.10 C
	Pressure:    753.18 mmHg
	Altitude:    75.96 m
	Light:       0 lux 

Github

https://github.com/adafruit/Adafruit_Python_BMP

Credits

Alexandru Dragoescu

Alexandru Dragoescu

5 projects • 10 followers
http://home-automation.duculete.com

Comments