CS811 Sensor

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
benficafan1904
 
Posts: 4
Joined: Mon Feb 06, 2023 8:24 am

CS811 Sensor

Post by benficafan1904 »

Hi everyone! Just a quick introduction, I am quite new to this world of sensors and over the last couple of days I have been trying to use the CS811 sensor on my Raspberry Pi Zero but I have been facing some problems.

Code: Select all

import time
import board
import adafruit_ccs811

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
ccs811 = adafruit_ccs811.CCS811(i2c)

# Wait for the sensor to be ready
while not ccs811.data_ready:
    pass

while True:
    print("CO2: {} PPM, TVOC: {} PPB".format(ccs811.eco2, ccs811.tvoc))
    time.sleep(0.5)
And I've been getting this error when I run it:

Code: Select all

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/gas2.py", line 7, in <module>
    ccs811 = 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
When I run sudo i2cdetect -y 1 this is the output:
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: -- -- -- -- -- -- -- --

I don't know if it is the code or if I have done something wrong when connecting the wires. Thanks for your help and sorry if it is a dumb question, still a bit of a noob but trying to learn!

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CS811 Sensor

Post by dastels »

It doesn't seem to be attached. It should show up at address 0x53; the 0x5b is something else.

Check your wiring/connections. How do you have it connected? Feel free to post clear photos.

Dave

User avatar
benficafan1904
 
Posts: 4
Joined: Mon Feb 06, 2023 8:24 am

Re: CS811 Sensor

Post by benficafan1904 »

Here they are, I'm not sure how I can take these photos properly but I hope you understand. If you don't let me know and I will try to take better pictures.

Thanks for your help.

WAK - Ground (Pin 25)
SCL - Pin 5
SDA - Pin 3
3.3V - Pin 1
GND - Pin 9
Attachments
image1.jpg
image1.jpg (22.2 KiB) Viewed 252 times
image2.jpg
image2.jpg (25.09 KiB) Viewed 252 times
image3.jpg
image3.jpg (29.44 KiB) Viewed 252 times

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CS811 Sensor

Post by dastels »

OK, that should be good enough of connections. Have you double/triple checked the wiring?

Where is the sensor from?

Dave

User avatar
benficafan1904
 
Posts: 4
Joined: Mon Feb 06, 2023 8:24 am

Re: CS811 Sensor

Post by benficafan1904 »

Yes I have checked it several times now, still having the same errors.

I was given this sensor by my university but I think that it is from here:

https://www.sparkfun.com/products/retired/14193

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CS811 Sensor

Post by dastels »

OK, I thought it looked like Sparkfun, but couldn't find it on their site.

It looks straightforward. It has pullups on the I2C lines. WAK already has a pulldown on it so you don't need to connect it to ground. It looks like you have it connected to GPIO11 instead of ground.

Dave

User avatar
benficafan1904
 
Posts: 4
Joined: Mon Feb 06, 2023 8:24 am

Re: CS811 Sensor

Post by benficafan1904 »

dastels wrote: Mon Feb 06, 2023 4:17 pm OK, I thought it looked like Sparkfun, but couldn't find it on their site.

It looks straightforward. It has pullups on the I2C lines. WAK already has a pulldown on it so you don't need to connect it to ground. It looks like you have it connected to GPIO11 instead of ground.

Dave
Hi! I have removed the wiring from WAK but I am still getting the same error when I run the code. I think this sensor can have its address at 0x5a and 0x5b but the one I have is at 0x5b. At the end of the error it says "ValueError: No I2C device at address: 0x5a". I think this is where the mistake is coming from as it is looking for 0x5a and there is nothing there. Is there a way for me to change it?

Thanks for your help, once again.

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CS811 Sensor

Post by dastels »

You should really go to Sparkfun support about this board.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”