Hi everyone! I am trying to use the CCS811 sensor with my Raspberry Pi Zero and I am facing some problems right now.
This is the code I am using:
GNU nano 5.4 ccs811.py
import time
import board
import adafruit_ccs811
from board import *
i2c = board.I2C() # uses board.SCL and board.SDA
ccs = adafruit_ccs811.CCS811(i2c)
print("CO2: ", ccs.eco2, " TVOC:", ccs.tvoc)
This is the output I am receiving:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 176, in __probe_for_device
self.i2c.writeto(self.device_address, b"")
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 175, in writeto
return self._i2c.writeto(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 52, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 314, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 182, in __probe_for_device
self.i2c.readfrom_into(self.device_address, result)
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 165, in readfrom_into
return self._i2c.readfrom_into(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 59, in readfrom_into
readin = self._i2c_bus.read_bytes(address, end - start)
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 181, in read_bytes
return self._device.read(number)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/ccs811.py", line 8, in <module>
ccs = adafruit_ccs811.CCS811(i2c)
File "/usr/local/lib/python3.9/dist-packages/adafruit_ccs811.py", line 130, in __init__
self.i2c_device = I2CDevice(i2c_bus, address)
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 63, in __init__
self.__probe_for_device()
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 185, in __probe_for_device
raise ValueError("No I2C device at address: 0x%x" % self.device_address)
ValueError: No I2C device at address: 0x5a
I saw that this sensor’s address could be at 0x5a or 0x5b and mine is at 0x5b according to i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – 5b – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
It seems like the code is looking into 0x5a and doesn’t encounter anything. Is there a way I can change this?
Thanks for your help, I am still a bit of a newbie to this and still trying to learn!