Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior #2

Closed
RemBrandNL opened this issue Feb 16, 2021 · 9 comments
Closed

Unexpected behavior #2

RemBrandNL opened this issue Feb 16, 2021 · 9 comments

Comments

@RemBrandNL
Copy link

Firstly, new to programming, github and all of this, so please correct me if this is not the right channel for this.

Ordered in some SHTC3 sensors to replace my BME280 of which I don't trust the RH data. Using this on old spare Raspberry PIPI and i2cdetect -y 1 returns an address which gives me the impression it's recognized. Running the script @kratsg shared here however gives me: I2C transceive failed: [Errno 121] Remote I/O error
Is there some magic flag I missed, or just ordered from a wrong seller on the big bad internet?
Kind regards,
Remco

pi@serialsds:~ $ 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: 70 -- -- -- -- -- -- --                         
pi@serialsds:~ $ python3 sht.py 
Traceback (most recent call last):
  File "sht.py", line 5, in <module>
    sht3x.single_shot_measurement()
  File "/home/pi/.local/lib/python3.7/site-packages/sensirion_i2c_sht/sht3x/device.py", line 48, in single_shot_measurement
    result = self.execute(Sht3xI2cCmdMeasHighRes())
  File "/home/pi/.local/lib/python3.7/site-packages/sensirion_i2c_driver/device.py", line 61, in execute
    return self._connection.execute(self._slave_address, command)
  File "/home/pi/.local/lib/python3.7/site-packages/sensirion_i2c_driver/connection.py", line 116, in execute
    return self._interpret_response(command, response)
  File "/home/pi/.local/lib/python3.7/site-packages/sensirion_i2c_driver/connection.py", line 205, in _interpret_response
    raise response
sensirion_i2c_driver.errors.I2cTransceiveError: I2C transceive failed: [Errno 121] Remote I/O error
pi@serialsds:~ $ 
@kratsg
Copy link

kratsg commented Feb 16, 2021

Note that this seems like you might need to ping sensirion_i2c_driver developers instead (that's under Sensiron's purview - I believe) which looks like it's failing perhaps.

In my case, the example for what I used had this i2cdetect output

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --     

@RemBrandNL
Copy link
Author

About the i2cdetect value. The datasheet on Sensirion's website says in chapter 5.1 that the I2C address is 0x70, so this looks to be OK.
What I don't get is why it is detected, yet I don't get any data. I assumed it was all one and the same team developing this, my mistake. I'll read up a bit more on the documentation and otherwise raise a question/issue @ https://github.com/Sensirion/python-i2c-driver I still have hope I didn't get 5 faulty sensors ;-)
Cheers,
Remco

@ubruhin
Copy link

ubruhin commented Feb 17, 2021

Hi @RemBrandNL,

It seems that you are using an SHTC3, which is simply not supported yet by this driver. @rnestler do you maybe know if there are intentions to add support for the SHTC3 as well?

@RemBrandNL
Copy link
Author

Ouch, amazed and surprised. I was so focussed on the errors I got I didn't realize I ordered the wrong ones, my apologies. I did a search for SHT3, but apparently somewhere down the lines fuzzy search kicked in.
Possibly not the right place to ask, but indeed, are there plans to add support for SHTC3 as well? :-) If not, I probably have to source some SHT3's for my outdoor sensorbox.
Cheers,
Remco

@rnestler
Copy link

We have drivers for several platforms for the SHTC3 (or the SHTC1 which also works with the SHTC3):

Possibly not the right place to ask, but indeed, are there plans to add support for SHTC3 as well?

At least not in the short term. But since it is still an active sensor it would make sense to add a Python driver as well for it.

@RemBrandNL
Copy link
Author

Awesome! But again, very new to programming and all and just trying to get a reliable sensors box in the backyard. My limited knowledge covers a bit of python and advanced googling. Code for Arduino and C unfortunately doesn't apply to me.

Link 3 sent me in the right direction, got it to work and learned a few things as a bonus! Should someone end up here in the future. https://blog.dbrgn.ch/2018/8/20/read-shtc3-sensor-from-linux-raspberry-pi/ got me started, but the device would be gone after each reboot.

Googled some more and this solved it for me (try at your own risk and all, might be cleaner ways):

  • Added to /etc/rc.local (sudo pico /etc/rc.local): echo shtc1 0x70 > /sys/bus/i2c/devices/i2c-1/new_device
    (I added it at the top before your IP is shown)
  • Added to /etc/modules (sudo pico /etc/modules): shtc1

After reboot this now works and you can easily test it by running sensors (sudo apt install lm-sensors):

pi@demopi:~ $ sensors
shtc1-i2c-1-70
Adapter: bcm2835 (i2c@7e804000)
temp1:        +22.6°C  
humidity1:     40.1 %RH

cpu_thermal-virtual-0
Adapter: Virtual device
temp1:        +32.6°C  

rpi_volt-isa-0000
Adapter: ISA adapter
in0:              N/A  

I then installed PySensors (pip3 install PySensors) to use the data in Python:

pi@demopi:~ $ python3 sensorSHTC3.py 
shtc1-i2c-1-70
bcm2835 (i2c@7e804000)
temp1: 22.635
humidity1: 40.147

Not the easiest route, but I at least have a way to get the readings from the SHTC3 sensors I ordered. I'll keep my eyes open for any easier solutions, but for now this should suffice.

Thanks again for all your help!
Remco

PS: this specific test was done on Linux 5.10.11+ #1399 armv6l GNU/Linux, running on an old Raspberry Pi Model B Plus Rev 1.2.

@ubruhin
Copy link

ubruhin commented Feb 19, 2021

Good to hear you were able to read out the sensor! 👍

For your information, I just realized that there is actually one more way to read out the sensor. Maybe you are interested in this variant as well 🙂

With the sensirion-i2c-driver it's actually quite easy to communicate with Sensirion sensors (including CRC handling etc.) even if no sensor-specific driver is available yet. Its quickstart guide shows how this works. For the SHTC3 it might look somehow like this (I didn't test it, so it might contain mistakes 😉):

from struct import unpack
from sensirion_i2c_driver import LinuxI2cTransceiver, I2cConnection, \
    I2cDevice, SensirionI2cCommand, CrcCalculator
from sensirion_i2c_sht.sht3x import Sht3xTemperature, Sht3xHumidity


class Shtc3I2cCmdMeasure(SensirionI2cCommand):
    def __init__(self):
        super(Shtc3I2cCmdMeasure, self).__init__(
            command=0x7866,
            tx_data=[],
            rx_length=6,
            read_delay=0.02,
            timeout=0,
            crc=CrcCalculator(8, 0x31, 0xFF),
        )

    def interpret_response(self, data):
        checked_data = SensirionI2cCommand.interpret_response(self, data)
        temperature_ticks, humidity_ticks = unpack(">2H", checked_data)
        return Sht3xTemperature(temperature_ticks), Sht3xHumidity(humidity_ticks)


with LinuxI2cTransceiver('/dev/i2c-1') as transceiver:
    device = I2cDevice(I2cConnection(transceiver), 0x70)
    temperature, humidity = device.execute(Shtc3I2cCmdMeasure())
    print("Temperature: {}, Humidity: {}".format(temperature, humidity))

@RemBrandNL
Copy link
Author

@ubruhin Let's just say I hope to arrive at a level where I can figure this out myself. I make a deep bow in respect, since it's spot on, no tweaking needed!!

It looks safe enough to run it blindly (keep best practice in mind and all ;-) ) and it hit me with a OSError: [Errno 16] Device or resource busy. I figured it was probably the driver that locked it so I removed the shtc1 reference I made in the /etc/rc.local.

1 reboot later and added a 1 second loop:

pi@demopi:~ $ python3 shtc3v2.py 
> 19-02 18:18:03: Temperature: 22.4 °C / Humidity: 41.2 %RH
> 19-02 18:18:04: Temperature: 22.4 °C / Humidity: 41.1 %RH
> 19-02 18:18:05: Temperature: 22.5 °C / Humidity: 41.1 %RH
> 19-02 18:18:06: Temperature: 22.4 °C / Humidity: 41.0 %RH
> 19-02 18:18:07: Temperature: 22.4 °C / Humidity: 41.0 %RH
> 19-02 18:18:08: Temperature: 22.4 °C / Humidity: 41.0 %RH
> 19-02 18:18:09: Temperature: 22.4 °C / Humidity: 41.1 %RH
> 19-02 18:18:10: Temperature: 22.4 °C / Humidity: 41.1 %RH
> 19-02 18:18:11: Temperature: 22.5 °C / Humidity: 41.1 %RH
> 19-02 18:18:12: Temperature: 22.5 °C / Humidity: 41.1 %RH
> 19-02 18:18:13: Temperature: 22.4 °C / Humidity: 41.1 %RH

This should be indeed a cleaner approach since you keep it all within python without other dependencies (OK, installing some modules). I'll test it on a clean install to see if I missed anything, but thanks again for all your help and support. Let's hope google indexes all this so it helps others as well.

Cheers and have a great weekend!
Remco

@ubruhin
Copy link

ubruhin commented Feb 22, 2021

Awesome! 😃

I created an internal ticket to officially add support for the SHTC3 sensor some day. Let's close this issue now since the reason for the initial error is clear.

@ubruhin ubruhin closed this as completed Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants