Chapter 10. A Practical Example

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:

  • Building a simple weather station
  • Getting the weather data online
  • Implementing weather alerts
  • Creating a web interface for configuring the alerts

Weather station

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:

  • Breadboard
  • 1x HTU21D breakout board
  • 1x BMP183 breakout board
  • Jumper wires

Wire up the breakout boards as shown:

Weather station

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)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.78.237