Hi folks,
I’ve got myself stuck trying to setup an “Adafruit I2C QT Rotary Encoder” on a pico. I’m trying to run the code through my computer, so I can utilise the encoder feedback to control some computer based applications. I have been following this guide: Overview | CircuitPython Libraries on any Computer with Raspberry Pi Pico | Adafruit Learning System
I did originally test everthing just on the pico using the circuit python libraries. Now I am using Adafruit Blinka to access it through my laptop via USB. The pico now has micropython installed with the u2if Firmware as mentioned on the link above.
The setup seemed straight forward, I tested everything and I have been able to get a push button to work on the pico, but I cannot get the I2C working on the pico to use the rotary encoder. I have tried the various examples such as:
import board, busio
#i tried all of these variations:
i2c = busio.I2C(board.GP17, board.GP16) #trying to explicitly select these pins
i2c = busio.I2C(board.SCL0, board.SDA0) #tried leaving it undefined
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
But each one of these has hung python frozen…
Even if I tried ‘unlocking’ or scanning for I2C devices:
while not i2c.try_lock():
pass
try:
while True:
print(
"I2C addresses found:",
[hex(device_address) for device_address in i2c.scan()],
)
time.sleep(2)
finally: # unlock the i2c bus when ctrl-c'ing out of the loop
i2c.unlock()
Which again, would make the program just hang indefinitely.
I also tried using machine, but cannot access or specifically install “machine” in this configuration
from machine import I2C, SPI, u2if, Pin
# Run a scan on the second I2C (i2_index=1)
i2c = I2C(i2c_index=0, frequency=400000) # , pullup=True
slaves = i2c.scan()
print("i2c slaves found %s" % slaves)
Bare in mind this is all running off my computer onto the pico thanks to the “Magical u2if Firmware” added onto the pico - which makes it unmounted and unrecognisable in Thonny. So I’ve just been doing tests in a shell running python3, or running test python scripts.
Any help would be appreciated. Sorry if this is a daft one… and apologies for the long post.