SCD30 on Pi gives Remote I/O error, should I write I2C in Python with bit-bang?
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.
Toplantı odaları için CO2 ölçüyoruz, Pi 3B+ ve Sensirion SCD30. Pi her 30 saniyede okuyup Hermetry’ye co2, temp, rh gönderiyor. Okumaların bir kısmı şu hatayla patlıyor:
OSError: [Errno 121] Remote I/O error
File "scd30.py", line 58, in read_measurement
data = bus.read_i2c_block_data(0x61, 0x03, 18)
Saatte 20-30 kez. Grafikte boşluklar oluyor. Okuduğum kadarıyla SCD30 clock stretching yapıyor ve Pi’nin donanım I2C’si bunu düzgün desteklemiyor. Düşündüğüm şey RPi.GPIO ile I2C master’ı Python’da bit-bang olarak yazmak. Mantıklı mı, daha önce yapan var mı? Zamanlama Python’da tutar mı emin değilim.
Translated from Türkçe by AI ·
Have you tried lowering the speed? With i2c_arm_baudrate in config.txt.
Hızı düşürmeyi denediniz mi? config.txt’de i2c_arm_baudrate ile.
Translated from Türkçe by AI ·
I lowered it to 10000, the error dropped to 5-6 per hour but didn’t stop.
10000’e indirdim, hata saatte 5-6’ya düştü ama bitmedi.
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.
Python’da kendin yazma, çekirdekte zaten hazır bir yazılım I2C var, bit-bang’i o yapıyor ve clock stretching’i doğru izliyor. SCD30’u ben de tam bu yüzden ona taşıdım. /boot/config.txt (Bookworm’da /boot/firmware/config.txt):
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24,i2c_gpio_delay_us=2
Yeniden başlat, i2cdetect -y 3 ile 0x61’i gör. Kodda SMBus(1) yerine SMBus(3). Sensörü GPIO 23/24’e taşı, 3.3V’a 4.7k pull-up koy (donanım I2C pinlerindeki dahili pull-up’lar burada yok). Diğer sensörlerin varsa onlar bus 1’de kalabilir.
Bir de okumayı sensörün “data ready” komutuna (0x0202) göre yap, ölçüm hazır değilken okursan da saçmalıyor. Arada bir hata yine olursa bir kez tekrar dene, o okumayı atla; boş geçen okuma için bir şey gönderme, Hermetry’de son değer kalır.
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.
Overlay ile bus 3’e aldım, 2 gündür tek Errno 121 yok. Pull-up’ları unutmuştum, ilk açılışta i2cdetect boş geldi, 4.7k’ları takınca göründü. Bit-bang yazmaya girişmediğim iyi olmuş.
Translated from Türkçe by AI ·
Why didn’t lowering the speed fully solve it then? I’m curious.
Hız düşürmek neden tamamen çözmedi peki? Merak ettim.
- 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.

