Closed SteffRainville closed 2 years ago
I'm getting the same error on a RPi 3B+, have you had any luck resolving it?
I believe this is because the sensors are currently in use. if you have IoT on the device your working with and running this code, try killing the Atlasiotcore process and then immediately launching the i2c.py Alternatively you could use > sudo systemctl disable AtlasIoT.service
You will encounter this issue if you have a non Atlas Scientific I2C sensor connected to your RPi.
For example, I have a Catnip soil sensor on address 32 and a bme280 on address 119. Here's what I get if I try to query each device with the command "I"
Enter command: List_addr
32
99
119
Enter command: Address,99 # querying an Atlas pH sensor
I2C address set to 99
Enter command: I
Command succeeded ?I,pH,2.13 # the python script will properly parse this line
Enter command: Address,32 # querying the catnip sensor
I2C address set to 32
Enter command: I
Error 0 # not an Atlas device, so we get an error that the i2c.py script does not handle, hence your error
Enter command: Address,119
I2C address set to 119
Enter command: I
Error 0 # not an Atlas device either, still not expected by the python script
As a workaround, replace:
for i in device_address_list:
device.set_i2c_address(i)
response = device.query("I")
moduletype = response.split(",")[1]
response = device.query("name,?").split(",")[1]
device_list.append(AtlasI2C(address = i, moduletype = moduletype, name = response))
with
for i in device_address_list:
device.set_i2c_address(i)
response = device.query("I")
try:
moduletype = response.split(",")[1]
response = device.query("name,?").split(",")[1]
except Exception:
continue
device_list.append(AtlasI2C(address = i, moduletype = moduletype, name = response))
Hey all, not sure what the source of the issue was but Atlas wrote some new sample code for the OEM devices that I was testing out and it's working for me now! Here's the link to the repo https://github.com/Atlas-Scientific/python_AtlasOEM_lib
I have fixed this in the whitebox-fork of this code (PR #8 ). The problem was the code assumed only EZO devices and did not handle responses in a different format gracefully.
I have tested with catnip soil moisture sensor, but it should now ignore all non-EZO devices.
Glad if some of you guys could test it. I don't know if and when Atlas accepts my PR - until then you can use the whitebox fork: https://github.com/whitebox-labs/Raspberry-Pi-sample-code
So we (finally) implemented a fix for this by having the i2c sample code issue an verbal warning in the console if there's non EZO devices present on the bus, in this commit. https://github.com/AtlasScientific/Raspberry-Pi-sample-code/commit/b05a907bc4bbfc310295718a980ee4d2e0708ded
Followed instructions for i2C on a RTD sensor on a raspberry pi 4 with the latest version of Raspian.
sudo python i2c.py or sudo python3 i2.py both give the following
Sensor is detected correctly by sudo i2cdetect -y 1
Traceback (most recent call last): File "i2c.py", line 146, in
main()
File "i2c.py", line 59, in main
device_list = get_devices()
File "i2c.py", line 29, in get_devices
moduletype = response.split(",")[1]
IndexError: list index out of range