Cannot access I2C on pico via desktop access

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():

    while True:
            "I2C addresses found:",
            [hex(device_address) for device_address in i2c.scan()],

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop

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.

1 Like

I am certainly interested to get this desktop controil process working, however I have also been exploring how to get the data read by the pico on my computer, using the coding running from the pico too.

Using circuitpython initially, I had difficulty finding information on the usb_cdc library and also looked at the hid libraries, but that seemed like overkill.

I’m wondering if this would be easier in micropython, I just would like the full functionality of the adafruit rotary encoder.

I feel like this is really simple, but I’m get tripped up by the many ways to go about this.

1 Like

Hi Leo,

Welcome to the forum!!

A couple of questions about your overall project.
What are you trying to control on your computer? Is it volume, a few values in a custom Python GUI or script?

Adafruit provide all of the examples using their CircuitPython builds so using the encoder would be easiest there. (and if you end up needing HID CircuitPython has the easiest implementation of it)


Hey Liam,

Thanks for your reply. I’m using it to drive various parameters in a program called touchdesigner, which is a realtime graphics program. Once I can read the input, i can link the value change to control various operators.

Hi Leo.
Some time ago I purchased a couple of these to play with. I fitted Bourns PEC11 series encoders and found the device to work very well with Arduino and the appropriate Seesaw library. There is a link on the Core site re Circuit Python code which should shed some light on the problem.

The only down side is the time taken to recover the positional information which is in the order of 1.3mSec. Did not suit what I was trying to do at the time. I did quite a few experiments at the time and post is here if you are interested.

Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Qwiic.

I have since overcome the timing problem with some help from this Forum and a lot of searching and now have a useable pulse generator with an Arduino UNO. I have not built it up as a project as I personally have no use for it (have a very capable function generator) but will publish as a Forum topic soon.
Cheers Bob

1 Like

Hi Bob,

Thanks for the help once again!
As someone without consistent access to a function generator (but very consistent access to some UNOs) I am looking forward to seeing your post.

Hi Jack.
Am rolling it around in my head at the moment, will try to post within the next week.

AHHH, decent multimeter, oscilloscope and function generator you can tackle almost anything. And if you are involved in RF circuits and the tuning of them (a bit of a rarity these days) an analog (yes one with an actual meter movement) is pretty well a must . VTVM is pretty handy also.
Cheers Bob

1 Like