The Python OTOS examples page suggests that one should be able to follow along the XRP process to get this working on Pico with MicroPython. So I gave it a whirl, following the MicroPython installatioin instructions here. I then Googled “using qwiic micropython rp2” and AI told me the default i2c pins are 16 and 17.
To use Qwiic-enabled I2C devices with MicroPython on an RP2040 board, you’ll need to install the SparkFun Qwiic I2C Python package, connect the Qwiic cable to the board’s I2C pins (SDA on GPIO16, SCL on GPIO17), and then use the package’s functions to interact with the devices.
I’ve been pounding away at this for some hours and So far, so bad.
The default pins are on that pinmap/link I sent in your other thread yesterday; is it being detected?
What part are you stuck on? #1? qwiic_otos_py/examples/qwiic_otos_ex1_basic_readings.py at master · sparkfun/qwiic_otos_py · GitHub
When I run any exercise, I get this in Thonny:
Qwiic OTOS Example 1 - Basic Readings
‘id’ argument required
error: failed to connect to i2c bus
The device isn’t connected to the system. Please check your connection
It looks like there is no way for the code to be able to discover which pins are being used to connect the OTOS device. So I began to modify the Exercise 1 code to specify pins 0 & 1.
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# MODIFIED qwiic_otos_ex1_basic_readings.py
import qwiic_i2c
import qwiic_otos
import sys
import time
# Initialize the I2C bus using pin numbers
my_bus = qwiic_i2c.get_i2c_driver(sda=0, scl=1, freq=100000)
def runExample():
print("\nQwiic OTOS Example 1 - Basic Readings\n")
# Create instance of device
myOtos = qwiic_otos.QwiicOTOS(23, my_bus)
# Check if it's connected
if myOtos.is_connected() == False:
print("The device isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
# Initialize the device
myOtos.begin()
This got me a little further along but produced another error:
Qwiic OTOS Example 1 - Basic Readings
Traceback (most recent call last):
File “”, line 65, in
File “”, line 20, in runExample
File “/lib/qwiic_otos.py”, line 255, in is_connected
File “/lib/qwiic_i2c/micropython_i2c.py”, line 145, in readByte
OSError: [Errno 5] EIO
This brings me to the point of wondering whether anyone has actually hooked this device up to a Pico. I’m getting a bit out of my depth tinkering with this code.
Sorry, I didn’t notice the link. I will check it out.
I have studied the pinmap link but I don’t see how that helps me. Having gotten the answer to my earlier question (blue is sda, Yellow is scl), I was able to successfully connect to any pair of I2C pins: 0&1, 2&3, 4&5, …, 20&21. I just needed to specify the pin numbers and the scan found the device.
But with the examples, there is no opportunity to specify which I2C pins the OTOS is connected to. I have tried it on all of them, and I always get the same error message. There doesn’t seem to be a ‘default’ pair of pins to which I can connect the OTOS and have the examples work.
Good news! The error I was getting (OSError: [Errno 5] EIO) went away after I cycled power.
That’s just one of those annoying little quirks that happen with microprocessors.
So that’s it. All I needed to do to get each of the examples to work is to:
- Add one import:
import qwiic_i2c
- Initialize the I2C bus using the pin numbers the OTOS is connected to.
my_bus = qwiic_i2c.get_i2c_driver(sda=0, scl=1, freq=100000)
- Create the device instance using the device address and bus object as parameters.
myOtos = qwiic_otos.QwiicOTOS(23, my_bus)
1 Like
I just wanted to share that I have completed my project using the OTOS on my DIY robot programmed with MicroPython running on a Pico. It works extremely well.
This is super cool to see, thank you for sharing! And glad to hear you’re happy with the performance, I spent a lot of time calibrating that thing 
Sorry to hear you had trouble with the I2C bus, glad you got it figured out! Not sure where pins 16 and 17 came from for being default; for Pico, the default I2C pins are usually 4 and 5, but any pair of pins can be used.
Also, you may have been working on this in the middle of our Qwiic I2C Python refactor. We recently got this pull request merged that allows MicroPython to select the default I2C bus ID for the board in use (by calling machine.I2C()
instead of machine.I2C(id)
). We then subsequently updated our MicroPython Qwiic I2C driver to take advantage of this if no pins are specified (here). However if you’re using older MicroPython firmware, then machine.I2C()
doesn’t work without any parameters, hence the error ‘id’ argument required
. Can resolve that by using the latest 1.25 preview build of MicroPython (though it will default to pins 4 and 5 instead of 0 and 1 like you need, so you’d still need to specify the pins as you do now).