1

I have an Adafruit RPI3 running Raspbian version = "8 jessie". I connected a CO2 sensor via I2c and the sensor properly responds to i2cdetect -y 1 with 0x68 and 0x69. I believe these are read and write addresses.

Here is my code that compiles with no errors with the Raspian Geany programming editor:

import smbus

DEVICE_BUS = 1
DEVICE_ADDR =  0X69
bus = smbus.SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 0X00,0X01)
print("Wrote to bus")

When from Geany I execute, a Terminal opens with the following message:

Traceback (most recent call last):
  File "smb_bus_write.py", line 9, in <module>
    bus.write_byte_data(DEVICE_ADDR, 0X00,0X01)
IOError: [Errno 5] Input/output error
  • 1
    I2C errors are invariably down to a poor, loose, or missing connection. A description and photo may be useful. What does the data sheet say the address should be? I'd expect just the one to be used. I suspect you are not setting the address properly which would explain why two are seen and the errors. – joan Sep 4 '16 at 20:36
  • BTW there is no such thing as an adafruit RPI3 they may have sold it to you but they don't make Raspberry Pi's – Steve Robillard Sep 4 '16 at 22:44
  • The connections and sensor response are both correct as verified by i2cdetect -y 1 responding with 0x68 and 0x69. Would you please give me more detail as to the error message: what specifically is reporting the IO error? – user53025 Sep 5 '16 at 16:37
  • @user53025 The SSCCE and traceback above look as specific as you are going to get to me; bus.write_byte_data from the SSCCE threw the error which in the traceback leads to a file presumably internal to the smbus module. – goldilocks Sep 5 '16 at 16:47
  • However, unless python actually allows you to use 0X for hexadecimal notation (as opposed to 0x), that SSCCE is fake. – goldilocks Sep 5 '16 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.