In this chapter, you will use what you've learned throughout the book to build a complete, practical application. We will cover the following topics:
Until this point, we've only looked at relatively simple program examples, without any real scope to them. Let's take some time to build a more complete program that actually accomplishes a practical task, a weather station.
Let's start with the hardware. We'll use a HTU21D I2C relative humidity sensor (for example, https://www.sparkfun.com/products/12064), as well as a BMP183 SPI pressure sensor (for example, https://www.adafruit.com/product/1900). Both include internal temperature sensors from which we can retrieve data, so we won't need an additional temperature sensor.
For this circuit, you will need:
Wire up the breakout boards as shown:
PyBBIO includes libraries for both sensors, so we'll use it for this program. For starters, let's look at getting the data from the sensors:
from bbio import * from bbio.libraries.BMP183 import BMP183 from bbio.libraries.HTU21D import HTU21D bmp = BMP183(SPI0) htu = HTU21D(I2C2) def setup(): pass def loop(): pressure = bmp.getPressure() # in Pascals rh = htu.getHumidity() # in %RH temp = htu.getTemp() # in Celsius dew_point = htu.calculateDewPoint(rh, temp) # in Celsius pressure /= 1000.0 # convert Pa to kPa print "temperature : {:0.2f} C".format(temp) print "humidity : {:0.2f} %RH".format(rh) print "pressure : {:0.2f} kPa".format(pressure) print "dew point : {:0.2f} C ".format(dew_point) delay(3000) run(setup, loop)
18.191.234.150