|# -*- coding: UTF-8 -*-|
|import serial, time, struct|
|ser = serial.Serial()|
|ser.port = "/dev/cu.wchusbserial1410" # Set this to your serial port|
|ser.baudrate = 9600|
|byte, lastbyte = "\x00", "\x00"|
|lastbyte = byte|
|byte = ser.read(size=1)|
|# We got a valid packet header|
|if lastbyte == "\xAA" and byte == "\xC0":|
|sentence = ser.read(size=8) # Read 8 more bytes|
|readings = struct.unpack('>hhxxcc',sentence) # Decode the packet - big endian, 2 shorts for pm2.5 and pm10, 2 reserved bytes, checksum, message tail|
|pm_25 = readings/10.0|
|pm_10 = readings/10.0|
|# ignoring the checksum and message tail|
|print "PM 2.5:",pm_25,"μg/m^3 PM 10:",pm_10,"μg/m^3"|
Are you sure it is a big endian? Shouldn't that be an little endian? (http://inovafitness.com/upload/file/20150311/14261262164716.pdf → Page 5). I don't know much about big and little endian, but your output for PM2.5 and PM10 are to high (negative or over 1000).
it is little endian!!!
Look at page 7! It starts with the low byte and finishes with the high byte !
So please correct line 22 from