Do you have other devices on your I2C-bus? The device has rather weak pullups and the builtin pullups of the pico are even weaker. I assume that you use the Stemma/QT connector, so this would rule out a connection issue.
Since you only use a single device, I doubt that it is a pullup-issue. BTW: I use a Badger2040 with the AHT20 without extra pullups and that works fine. But I use the CircuitPython library but the MicroPython lib should be just fine. And I think the error isn’t even triggered directly in the library, it triggers when the I2C-object is opened.
So here are some more ideas: use the alternative plug in the AHT20. Use a different cable.
Nice to see. You actually had the correct id the first time you created the I2C-object, that is why the scan worked.
BTW: that is one of the reasons I prefer CircuitPython. You just use board.I2C() and you don’t have to worry about pins and bus-numbers. And if you decide to change the MCU, your code still works. (To be honest, the original pico is one notable exception since I2C can be on almost any pins, but CircuitPython for Pimoroni’s pico-lipo does define board.I2C()).
MPY: soft reboot
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "/lib/ahtx0.py", line 50, in __init__
File "/lib/ahtx0.py", line 59, in reset
OSError: [Errno 5] EIO
Using ‘MicroPython v1.24.0 on 2024-10-25; Raspberry Pi Pico with RP2040’. ANy ideas why that might happen? I’m using the same code from @Tonygo2’s post where he says he cracked it.
I think I had a wiring issue. i2c.scan wasn’t finding anything. Unhooked everything and hooked it back up and it works. For some reason, the error message made me believe it was a library problem rather than a wiring problem. Thanks for looking.
Glad you have it working now. The problem with Picos is that we have too many choices of pin pairs for I2C connections where most other microprocessor boards limit the sda and scl pins available.
Hm… not really. Most Espressif chips (and that is a huge share of the market) have full peripheral multiplexing like the Pico. And STM32 also has multiplexing.
What we do have: some form-factors like Feather always put the same functions on the same pins, regardless of the chip. So a RP2040 Feather will have the same pinout as an ESP32-S3 Feather. This is definitely less confusing and you usually also find labels on the boards which also helps. And programs are more portable.