Dear Adafruit Support Team,
I am writing to you in regard to an issue I am facing with the Sensirion SGP40 sensor. I am currently using a Raspberry Pi 4 Model B to read data from the SGP40 sensor over an I2C interface. However, when I run the i2cdetect -y 1 command to list all the connected I2C devices, the SGP40 sensor does not appear in the list. I have verified that the wiring and connections are correct, and I have also ensured that the I2C bus is enabled on my Raspberry Pi. The I2C address for the SGP40 sensor (0x59) has been correctly set as well. Despite these measures, the sensor remains undetected when running the i2cdetect -y 1 command.
Interestingly, I have successfully used the i2cdetect -y 1 command to detect an SGP30 sensor on the same Raspberry Pi. Therefore, this issue seems to be specific to the SGP40 sensor. When I try to communicate directly with the sensor using Python scripts, I receive a "Remote I/O error" (Errno 121). This suggests that there is a communication problem between the Raspberry Pi and the SGP40 sensor. I would greatly appreciate your support in resolving this issue.
Please let me know if you require any additional information or if there are any troubleshooting steps that you recommend. Thank you in advance for your assistance.
Best,
BANNED Parhizkar
SGP40 I2C Issue
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
Please post a photo of your setup showing how the SGP40 is being connected to the Pi.
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
Please see attached the picture of SGP40 connection.
Pin 1 in pi (3.3v) --> VIN
pin 6 on pi (Ground) --> Ground
pin 3 on pi (SDA) --> SDA
pin5 on pi (SLC) --> SLA
Pin 1 in pi (3.3v) --> VIN
pin 6 on pi (Ground) --> Ground
pin 3 on pi (SDA) --> SDA
pin5 on pi (SLC) --> SLA
- Attachments
-
- SPG40 .jpg (792.59 KiB) Viewed 204 times
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
Just tested a similar setup here. The SGP40 did not show up in an I2C scan:
However, it worked OK when running the example code here:
https://learn.adafruit.com/adafruit-sgp ... de-3080635
Try reflowing the soldering on the header pins:
They appear to be possibly cold soldered and not wetted out enough on the pads.
https://learn.adafruit.com/adafruit-gui ... n-problems
Code: Select all
pi@raspberrypi:~ $ 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
https://learn.adafruit.com/adafruit-sgp ... de-3080635
Code: Select all
pi@raspberrypi:~ $ python3 sgp40_test.py
Raw Gas: 28234
Raw Gas: 28263
Raw Gas: 28283
Raw Gas: 27858
https://learn.adafruit.com/adafruit-gui ... n-problems
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
Thank you. I followed your recommendation and reflowed the soldering across the pin header but still getting below error:
Traceback (most recent call last):
File "/home/BANNED/s.py", line 13, in <module>
sgp = adafruit_sgp40.SGP40(i2c)
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 123, in __init__
self.initialize()
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 141, in initialize
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
RuntimeError: Feature set does not match: 0x3240
Traceback (most recent call last):
File "/home/BANNED/s.py", line 13, in <module>
sgp = adafruit_sgp40.SGP40(i2c)
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 123, in __init__
self.initialize()
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 141, in initialize
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
RuntimeError: Feature set does not match: 0x3240
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
To ensure that the problem is not with soldering, I used STEMMA QT to connect the sensor with pi and still same result.
Traceback (most recent call last):
File "/home/BANNED/s.py", line 13, in <module>
sgp = adafruit_sgp40.SGP40(i2c)
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 123, in __init__
self.initialize()
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 141, in initialize
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
RuntimeError: Feature set does not match: 0x3240
Traceback (most recent call last):
File "/home/BANNED/s.py", line 13, in <module>
sgp = adafruit_sgp40.SGP40(i2c)
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 123, in __init__
self.initialize()
File "/home/BANNED/.local/lib/python3.9/site-packages/adafruit_sgp40/__init__.py", line 141, in initialize
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
RuntimeError: Feature set does not match: 0x3240
- Attachments
-
- IMG_0951.jpg (995.34 KiB) Viewed 177 times
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
Is a Raspberry Pi the only board you have available for testing? Do you have an Arduino board by any chance?
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
I tried Arduino and it reads data successfully, So there is an issue with the python library. Any idea how to fix it?
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
We can't recreate the issue locally.
Is it failing every time with the same:
message?
Is it failing every time with the same:
Code: Select all
RuntimeError: Feature set does not match: 0x3240
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
In response to your question, the sensor reports the RuntimeError: Feature set does not match: 0x3240 error if I use the default SGP40 example. Manually, we have been able to successfully send the "Read FeatureSet" command to the SGP40 sensor and received a valid response. The FeatureSet response we received was [50, 64].
The problem we are facing currently is a persistent Remote I/O error (Errno 121) when we attempt to read data from the sensor, specifically, trying to put it into continuous measurement mode and then reading the raw data. This error is being received every time we attempt to read the data.
Our testing setup with Arduino works without any issues, which implies the hardware seems to be functioning properly. The problem seems specific to the Raspberry Pi environment. We have been meticulous in our troubleshooting, taking into consideration potential factors like necessary wait times after sending commands, correct CRC checksums, and appropriate command sequences. However, the issue persists.
It would be very helpful if you could provide any suggestions or insights, or if there are any specific conditions under which these sensors operate best, that we might not be aware of.
Thank you
BANNED
The problem we are facing currently is a persistent Remote I/O error (Errno 121) when we attempt to read data from the sensor, specifically, trying to put it into continuous measurement mode and then reading the raw data. This error is being received every time we attempt to read the data.
Our testing setup with Arduino works without any issues, which implies the hardware seems to be functioning properly. The problem seems specific to the Raspberry Pi environment. We have been meticulous in our troubleshooting, taking into consideration potential factors like necessary wait times after sending commands, correct CRC checksums, and appropriate command sequences. However, the issue persists.
It would be very helpful if you could provide any suggestions or insights, or if there are any specific conditions under which these sensors operate best, that we might not be aware of.
Thank you
BANNED
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
By the way, we noticed something interesting during our troubeshooting process that I wanted to discuss. In the __init__.py file of the SGP40 library, we noticed that there's a check against the featureset 0x3220 as follows:
" if featureset[0] != 0x3220:
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
"
However, during our tests, we were able to successfully read the featureset as [50, 64], which translates to 0x2032 in hexadecimal if we consider the first byte as the most significant byte. If we swap the bytes (considering the second byte as the most significant byte), this translates to 0x3220, matching the featureset checked in the library.
This inconsistency suggests that there might be different interpretations of the I2C data. In some systems, the I2C data might be interpreted as big-endian (where the first byte is the most significant byte), while in others it might be interpreted as litle endian (where the last byte is the most significant byte). We wanted to know if you have any thoughts on this. Is there a specific reason why the check in the library is against 0x3220? Is it possible that the featureset bytes need to be swapped in our case?
" if featureset[0] != 0x3220:
raise RuntimeError(f"Feature set does not match: {featureset[0]:#x}")
"
However, during our tests, we were able to successfully read the featureset as [50, 64], which translates to 0x2032 in hexadecimal if we consider the first byte as the most significant byte. If we swap the bytes (considering the second byte as the most significant byte), this translates to 0x3220, matching the featureset checked in the library.
This inconsistency suggests that there might be different interpretations of the I2C data. In some systems, the I2C data might be interpreted as big-endian (where the first byte is the most significant byte), while in others it might be interpreted as litle endian (where the last byte is the most significant byte). We wanted to know if you have any thoughts on this. Is there a specific reason why the check in the library is against 0x3220? Is it possible that the featureset bytes need to be swapped in our case?
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
The byte ordering could be reversed in how you read the feature set. If there was an actual byte ordering issue in the library, it'd repeat here with local testing. As is, we can't recreate this behavior.
Where did the STEMMA QT cable from? It looks custom made?
Where did the STEMMA QT cable from? It looks custom made?
- hparhizkar
- Posts: 9
- Joined: Wed May 24, 2023 4:58 pm
Re: SGP40 I2C Issue
After multiple rounds of edition, I was finally able to read data using smbus library, and separately through Sensirion library. This confirms that wiring is fine and Adafruit library needs some revision to make it compatible with Python. I suggest starting out by looking into the feature set which is currently defined 0x3220 in the __init__ file. That needs to change to 0x3240 and this change may require further revision throughout the library.
Hope your team can figure this out because I am a very big fan of Adafruit libraries!
Thank You for your time
Hope your team can figure this out because I am a very big fan of Adafruit libraries!
Thank You for your time
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: SGP40 I2C Issue
Opened a new issue for this here:
https://github.com/adafruit/Adafruit_Ci ... /issues/19
https://github.com/adafruit/Adafruit_Ci ... /issues/19
- DaySynth
- Posts: 7
- Joined: Thu Jan 05, 2023 1:09 pm
Re: SGP40 I2C Issue
@Here, i have the same issue where the feature set did not match. I also confirmed that the feature set is listed as 0x3240, but the software is looking for 0x3220...However!
I have sgp40 boards from adafruit that were ordered a few months back and still have not issue with those boards, but new adafruit boards (still sgp40) do have an issue. i have unplugged and plugged in my old and new boards, and still find that one works instantly, the newer purchased ones dont
(as for wiring, i am using the QT stemma cable directly connected to the esp32 feather v2, so no solder involved)
also, i changed the init file to look for 0x3240, but the following error occurred afterwards:
| File "<stdin>", line 1, in <module>
File "/lib/adafruit_sgp40/__init__.py", line 123, in __init__
File "/lib/adafruit_sgp40/__init__.py", line 146, in initialize
File "/lib/adafruit_sgp40/__init__.py", line 293, in _read_word_from_command
OSError: [Errno 116] ETIMEDOUT
I have sgp40 boards from adafruit that were ordered a few months back and still have not issue with those boards, but new adafruit boards (still sgp40) do have an issue. i have unplugged and plugged in my old and new boards, and still find that one works instantly, the newer purchased ones dont
(as for wiring, i am using the QT stemma cable directly connected to the esp32 feather v2, so no solder involved)
also, i changed the init file to look for 0x3240, but the following error occurred afterwards:
| File "<stdin>", line 1, in <module>
File "/lib/adafruit_sgp40/__init__.py", line 123, in __init__
File "/lib/adafruit_sgp40/__init__.py", line 146, in initialize
File "/lib/adafruit_sgp40/__init__.py", line 293, in _read_word_from_command
OSError: [Errno 116] ETIMEDOUT
Please be positive and constructive with your questions and comments.