I am attempting to use a sensor in conjunction with a raspberry pi smbus. When I try and read a specific byte of data, it returns 181. No matter what byte you tell it to read it returns 181, regardless of whether that byte actually exists or not.
Equipment: raspberry PI zero w connecting to a MikroeElictronika air quality 2 click via SMBus and I2C. Connected via a 2 click board. Other slot has a Adafruit ultimate GPS sensor that works fine.
https://download.mikroe.com/documents/datasheets/iaq-core-datasheet-en-v1.pdf
Code:
import smbus
from time import sleep
bus = smbus.SMBus(1)
def read_byte(byte):
reading = bus.read_byte_data(0x5a,byte)
return reading
co2 = read_byte(0x01)
print(co2)
sleep(5)
status = read_byte(0x2)
print(status)
bus.close()
this does not return any error but even if the sensor is stimulated it returns 181. none of the error messages output by the device are 181.
If you do not specify a byte, it does return a value that corresponds to air quality, but not one that corresponds with any of the outputs the sensor is meant to have. This is not the main problem but I have included it in case it helps.
Code:
reading = bus.read_byte(add)
I have no idea why this is happening. Please help as I have little experience in this area. This is a school project.
UPDATE: I have got I2C to block read the data
pigs reading returns:
9 1 199 0 0 1 249 51 0 127
I2C block read returns:
[181, 127, 255, 255, 255, 255, 255, 255, 255]
my pigpio python returns (-25L, ' ' )