(Where) is Qwiic demo code available (such as from the webinar)?

For those who want to dive into using Qwiic devices right now, here’s a quick set of instructions that should get you up and running. This is along the lines of how we’re planning to implement it in the next software release (subject to change), except the installation process should be automated once finalized. Please understand that if you choose to do this before the next software release, some things may not work and there will be limited support.

Add Qwiic_I2C_Py Driver

  1. In XRPCode, connect to the XRP. In the filesystem browser, right-click the lib/ folder and click New Folder. Name it qwiic_i2c.
  2. Download 3 files from the Qwiic_I2C_Py package: __init__.py, i2c_driver.py, and micropython_i2c.py
  3. Upload those 3 files to the qwiic_i2c/ folder created in step 1. In XRPCode, click File → Upload to XRP, select the 3 files from your computer (can select all at the same time), then select the qwiic_i2c/ folder on the XRP. The files will be uploaded.
  4. Download __future__.py from here and upload it to the lib/ folder on the XRP. This is needed because the Qwiic_I2C_Py package has backwards compatibility with Python 2, but MicroPython doesn’t include __future__ by default. This is just a dummy implementation that helps prevent things from breaking.
  5. (Optional, to verify installation) In the shell window at the bottom of XRPCode, type import qwiic_i2c, then i2cDriver = qwiic_i2c.getI2CDriver(), then i2cDriver.scan(). If all goes well, there should be no errors, and it should print [107] (that’s the decimal I2C address of the IMU on the control board).

Add Qwiic Device Drivers

  1. Find the Python driver for the device(s) you want to use in this list of drivers.
    • Not all of these have been tested in MicroPython. If you discover a problem, please create an issue in the corresponding repository.
    • Not all Qwiic devices are included in this list. If there’s a device you’d like to have added, please post something on this Discourse thread (we may have a better place for posting these requests in the future, but here is fine for now).
  2. Download the device driver library from the corresponding repository. This is typically a single .py file in the root directory of the repo that closely matches the repo name (eg. in the Qwiic_Relay_Py repo, download qwiic_relay.py)
  3. Upload the device driver files to the lib/ folder on the XRP. In XRPCode, click File → Upload to XRP, select the device driver files from your computer (can select all at the same time), then select the lib/ folder on the XRP. The files will be uploaded.
  4. (Optional) Also download the examples from the device driver repo (in the examples/ folder, grab whichever ones you want) and upload those to the XRP (put them wherever you want, use the root / directory if you’re not sure). You should be able to open these in XRPCode and click the Run button to test them.

Add Qwiic to Your Code

The Qwiic device drivers are all structured similarly to each other, and are designed to be fairly simple to use. For example, here’s the minimum code needed to use the Qwiic Single Relay (because @dangarlen asked :wink:):

# Set up the device, do this once in your code (very similar structure for all Qwiic devices)
import qwiic_relay
myRelay = qwiic_relay.QwiicRelay()
myRelay.begin()

# Use the device (usage differs between devices)
myRelay.set_relay_on()
myRelay.set_relay_off()

Assuming all goes well, this should be enough to get started with Qwiic on the XRP ahead of the official software release. Again, please be aware that some things may not work, and there will be limited support until the official software release. The instructions here are just brief guidance for users who are eager to play with Qwiic devices right now. Hope this helps!

1 Like