[Guide] SparkFun Qwiic / Adafruit STEMMA QT

Hi,
I’ll share how to use these I2C sensors in python with Radxa zero.

OS:
Official Debian (Linux radxa-zero 5.10.69-9-amlogic-g7c418f844e4b)

Qwiic connector:
SparkFun Qwiic SHIM for Raspberry Pi (https://www.sparkfun.com/products/15794)
Raspberry Pi QWIIC connector and cable (https://ozzmaker.com/product/raspberry-pi-qwiic-connector-and-cable/)

Sensor:
some sensor

  1. Enable I2C

Add overlay in /boot/uEnv.txt.
overlays=meson-g12a-i2c-ee-m3-gpioa-14-gpioa-15

If you want to turn on several functions, use a space as a delimiter.
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-i2c-ee-m3-gpioa-14-gpioa-15 meson-g12a-spi-spidev

  1. Connect sensor and boot

Check if /dev/i2c-3 exists.

  1. Install package

$ sudo apt install python3-libgpiod

For example, Adafruit BMP388 Precision Barometric Pressure and Altimeter
$ sudo pip3 install adafruit-circuitpython-bmp3xx

  1. Quick hack

$ sudo vim /usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py

Line 127
#alias = get_dts_alias(“ffd1d000.i2c”) #comment out this line
alias = get_dts_alias(“ffd1c000.i2c”) #add this line

Then, you can use many sensors available with qwiic ecosystems!
Many sensors are supported in adafruit circuitpython.

I finally got to work with I2C sensor, GPS and SPI display (MIP reflective display) as same as Raspberry Pi Zero.
I can start working on improving my bike computer.

1 Like

Nice, thanks for sharing.

In case others encounter the same issue, I’m adding to this thread with some additional changes I needed to make to get the Adafruit I2C drivers working on Armbian (6.1.11-meson64).

It appears the Armbian device tree maps I2C to bus 0 instead of bus 3:

$ i2cdetect -l
i2c-0	unknown   	Meson I2C adapter               	N/A
i2c-1	unknown   	DesignWare HDMI                 	N/A

Since the Adafruit driver expects devices on I2C bus 3, we need to make a change in the following file:

$ sudo vim /usr/local/lib/python3.10/dist-packages/adafruit_blinka/microcontroller/amlogic/s905y2/pin.py

Toward the bottom of the file are the I2C mappings. Change the second line to map bus 0 to the I2C3_SCL and I2C3_SDA pins.

i2cPorts = (
    (1, I2C1_SCL, I2C1_SDA),
    (0, I2C3_SCL, I2C3_SDA), # changed 3 to 0
    (4, I2C4_SCL, I2C4_SDA),
)