Im trying to read and write i2c messages to/from Sensirion SGP30 sensor with Raspberry Pi 3 but I have hard time to wrap my head around smbus lib.
SGP30 documentation (https://cdn.sos.sk/productdata/46/c9/ba351164/sgp30.pdf) has table that shows hexdecimals to init and start measuring:
And here is how I try to get it up and running:
bus = smbus.SMBus(1)
address = 0x58
time.sleep(.5)
bus.write_i2c_block_data(address, 0x2003, [])
time.sleep(.5)
bus.write_i2c_block_data(address, 0x2008, [])
time.sleep(.5)
while 1:
print bus.read_i2c_block_data(address, 0)
This prints me array
[0, 0, 129, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
But sensor is not reacting to alcohol.
What I would really need is tutorial for dummies about i2c communication and same with smbus (python). It seems that every tutorial Ive seen is those "just put these bytes here and you are good to go".
So how can I get this to work? Thank you! :)
Got it to work.
bus = smbus.SMBus(1)
address = 0x58
bus.write_i2c_block_data(address, 0x20, [0x03])
time.sleep(.5)
while 1:
bus.write_i2c_block_data(address, 0x20, [0x08])
time.sleep(.6)
print bus.read_i2c_block_data(address, 0)
time.sleep(.8)
Went thru the documentation again and as it says
“Measure_air_quality” command has to be sent in regular intervals of 1s to ensure proper operation of the dynamic baseline compensation algorithm.
It seems that sleep times needs to be slightly bigger since loop is not running too smoothly on raspberry pi.
Still didn't find good explanation why I need to split that byte in two.