TAFE ICT Projects

Projects for NT Schools, National Science Week and other projects aimed at school aged children.

Palmerston Library Weather Station

Setting up your weatherStation

Download Weather Station file
 

#!/usr/bin/python3
from sensor_client import SensorClient
import time
import board
import adafruit_sht4x
import adafruit_dps310
import sys


client = SensorClient()
client.connect()
last_read = [0,0,0]

try:
    i2c = board.I2C()
    sht40 = adafruit_sht4x.SHT4x(i2c)
    dps310 = adafruit_dps310.basic.DPS310(i2c)
    
except Exception as err:
    print("i2c init failed: ", err, file=sys.stderr)
    exit(2)
    
try:
    while True:
        
        timer = time.time()
        
        if timer - last_read[0] >= client.temp_int:
            temps = round(sht40.temperature, 1)
            client.send_data("temperature", temps)
            last_read[0] = timer
            
        if timer - last_read[1] >= client.pres_int:
            press = round(dps310.pressure, 1)
            client.send_data("pressure", press)
            last_read[1] = timer
            
        if timer - last_read[2] >= client.humd_int:
            humid = round(sht40.relative_humidity, 0)
            client.send_data("humidity", humid)
            last_read[2] = timer
            
        time.sleep(1)
        
except Exception as err:
    print("Sensor read failed: ", err, file=sys.stderr)
    print("Shutting down Weather Station.", file=sys.stderr)
    client.close()
    exit(1)
    

Back to the top