AM2321 temperature and humidity reading

This example shows how to use the inbuilt sensor module to read temperature and humidity.

Requirements:

  • Uper1 board
  • AM2321 sensor
  • Breadboard
  • Connection wires
  • Two 4.7k (or similar) resistors

Schematic:

Code:

from time import sleep
from IoTPy.pyuper.uper import UPER1
from IoTPy.things.am2321 import AM2321
 
with UPER1() as board, board.I2C("I2C0") as i2c, AM2321(i2c) as sensor:
    while True:
        sensor.read()
        print "Temperature: %.1f Humidity: %.1f" % (sensor.temperature, sensor.humidity)
        sleep(1)