New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

SCD30 on Pi gives Remote I/O error, should I write I2C in Python with bit-bang?

SCD30 on Pi gives Remote I/O error, should I write I2C in Python with bit-bang?

Solved 5 3

Translated from Türkçe by AI ·

We measure CO2 for meeting rooms, Pi 3B+ and Sensirion SCD30. The Pi reads every 30 seconds and sends co2, temp, rh to Hermetry. Some of the readings fail with this error:

OSError: [Errno 121] Remote I/O error
  File "scd30.py", line 58, in read_measurement
    data = bus.read_i2c_block_data(0x61, 0x03, 18)

20-30 times an hour. There are gaps in the graph. From what I have read, the SCD30 uses clock stretching and the Pi’s hardware I2C does not support this properly. What I am considering is writing the I2C master in Python as bit-bang with RPi.GPIO. Does this make sense, has anyone done it before? I am not sure whether the timing holds up in Python.

Ağ geçidi yine bağlanıyor…
♥ 2

Translated from Türkçe by AI ·

Have you tried lowering the speed? With i2c_arm_baudrate in config.txt.

♥ 0

Translated from Türkçe by AI ·

I lowered it to 10000, the error dropped to 5-6 per hour but didn’t stop.

Ağ geçidi yine bağlanıyor…
♥ 0

Translated from Türkçe by AI ·

Don’t write it yourself in Python, the kernel already has a ready-made software I2C that does the bit-banging and correctly monitors clock stretching. That’s exactly why I moved the SCD30 over to it. /boot/config.txt (on Bookworm /boot/firmware/config.txt):

dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24,i2c_gpio_delay_us=2

Reboot, and check that 0x61 shows up with i2cdetect -y 3. In the code, use SMBus(3) instead of SMBus(1). Move the sensor to GPIO 23/24, and put a 4.7k pull-up to 3.3V (the internal pull-ups on the hardware I2C pins aren’t there in this setup). If you have other sensors, they can stay on bus 1.
Also, do the reading according to the sensor’s “data ready” command (0x0202); if you read while the measurement isn’t ready, it also gives nonsense. If an error still happens now and then, retry once and skip that reading; don’t send anything for a skipped reading, the last value stays in Hermetry.

Accepted solution♥ 2

Translated from Türkçe by AI ·

I moved it to bus 3 with an overlay, and for 2 days there has not been a single Errno 121. I had forgotten the pull-ups; on first boot i2cdetect came back empty, and once I added the 4.7k resistors it showed up. Good thing I didn’t get into writing bit-bang.

Ağ geçidi yine bağlanıyor…
♥ 0

Translated from Türkçe by AI ·

Why didn’t lowering the speed fully solve it then? I’m curious.

♥ 1
Viewing 6 posts – 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Join the conversation

Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

Share