Im a novice with Python 3, however I thought others might benefit from my snippet of code showing how to read the sensor feed on the USB port.
For those interested, im hoping to have multiple sensors around the office posting their sensor readings back via a RESTful API to a central Odroid-XU which is running Python 3 and Cherrypy and will have graphing and historical logging etc. All running ArchlinuxARM.
This code just shows how im reading the data every ~5secs. Hope it helps someone with their project.
Code: Select all
import serial import time x=0 while x<1: ser = serial.Serial('/dev/ttyUSB0', 500000, timeout=2) line = ser.readline(75) ser.close() tempreading=str(line.decode('utf-8')) print('Decoded String=',tempreading) print('BMP Temp = ',tempreading[2:7],'Deg C') print('Pressure = ',tempreading[10:16],'Pa') print('Altitude = ',tempreading[19:25],'Meters') print('Si7020 Temp = ',tempreading[28:33],'Deg C') print('Humidity = ',tempreading[36:42],' %') print('UV Index = ',tempreading[44:49],) print('Visible Light = ',tempreading[51:54],'Lux') print('IR Light = ',tempreading[56:59],'Lux') deltatemp=round(float(tempreading[2:7])-float(tempreading[28:33]),2) print('Difference between Temp sensors',str(deltatemp)) time.sleep(4)