I am using an air quality sensor with an I2C interface (datasheet: https://docs-emea.rs-online.com/webdocs/14cd/0900766b814cdbb8.pdf).
When running the below code asking for less than 8 bytes I get reasonable results. But when I ask for 9 bytes (which I need as the datasheet states) I get the result with strange characters such as "}" or "R" in the hex values.It states that 9 values have been returned but there are only 8. On rare occassions I will get 9 sensible bytes returned.
import pigpio import RPi.GPIO as GPIO pi = pigpio.pi() if not pi.connected: print("no pi") exit() bus = 1 address = 0x5a read_bytes = 9 handle = pi.i2c_open(bus,address) count, data = pi.i2c_read_device(handle, read_bytes) pi.i2c_close(handle) pi.stop() print(count) print(data) exit()
I have tried using SMBus with this component but that doesn't seem to be supported. Has anyone seen this before or know a workaround?
EDIT: may be a duplicate of smbus/I2C sensor returns fixed data
I tried using:
sudo pigpiod pigs i2co 1 0x5A 0 pigs i2crd 0 9
and that seems to return reasonable results:
9 1 194 16 0 1 8 80 0 125
the first digit is returning the count. I'm still not able to run this in python though. Someone suggested it was the print buffer, but I'm closing I2c before printing.
The data sheet does state not to request more than 3 bytes. Could this be the problem? How would I request bytes 7-8?