Cannot detect an i2c ToF sensor (vl53l1x) that connected to a properly configured i2c Mux (tca9548a)

Vanilla RPi SensorInit failure.txt (14.3 KB)First, before I start. I have carefully reviewed the associated product tutorials and searched both the web and SparkFun’s Forum for any solution to my problem, but to no avail.

Here is some background about what I’m trying to accomplish:

  • I’m using a mix of Sparkfun and Adafruit sensors. The sensors use Qwiic/Stemma QT connectors to connect to the i2c bus on a Raspberry Pi 3B+.


  • I did not use the SparkFun the pre-configured Autonomous image (release date: 2019-09-26). This was because I ran into problems when I tried to install the Adafruit sensors (which are based on Circuit Python) onto the SparkFu image.

    Through experimentation, I found that if I used a vanilla Raspian image, I could successfully install the Adafruit followed by the SparkFun i2c software onto the Raspberry Pi. With the exception of the Qwiic Mux and Time of Flight (ToF) sensor combo, I have been able to use an Adafruit BNO085 IMU sensor and a SparkFun micro OLED display on the same i2c bus.


  • Before I discuss the errors that I’m seeing, here is my configuration:

    Hardware configuration:

  • Raspberry Pi 3B+

  • SparkFun Advanced Autonomous Kit for Sphero RVR kit (KIT-15303)

  • Four additional SparkFun Qwiic ToF sensors ( SEN-14722)

  • SparkFun micro OLED display (LCD-14532)

  • Adafruit BNO085 IMU sensor (PRODUCT ID: 4754)

  • Argon ONE Raspberry Pi Micro USB Cable Power Supply (5.25 Volts 3 Amps)

  • I’m using the SparkFun Advanced Autonomous Kit for Sphero RVR KIT-15303. The configuration has been modified to use a Raspberry Pi 3B+ with four additional SparkFun Qwiic ToF sensors, a micro OLED display and an Adafruit BNO085 IMU. The hardware is powered by an Argon ONE Raspberry Pi Micro USB Cable Power Supply 5.25 Volts 3 Amps. I chose this power supply to avoid any “low voltage issues” which are common with the Raspberry Pi 3B+.
  • Software configuration:

  • Standard Raspbian image (Raspian 10 3.6)

  • I’m using Python 3 and pip3

  • From raspi-config I enabled i2c and spi

  • I ran the following commands to ensure that the system was up to date.

    All commands completed without errors.

    o sudo apt-get update

    o sudo apt-get upgrade

    o sudo apt-get install -y i2c-tools


  • Added the necessary Qwiic Python Libraries using the following pip3 commands in the following order. Each configuration command completed without any errors with the exception of “Requirement already satisfied” messages.

    o pi@raspberrypi:~ $ sudo pip3 install sparkfun-qwiic

    o pi@raspberrypi:~ $ sudo pip3 install sparkfun-qwiic-tca9548a

    o pi@raspberrypi:~ $ sudo pip3 install sparkfun-qwiic-vl53l1x

  • When I run vl53l1x_change_i2c_address.py (from the SparkFun Autonomous kit), I get the following errors. Please note that these errors are repeatable.

  • Error 1 - Error loading module qwiic_kx13x: unicode error) ‘utf-8’ codec can’t decode byte 0xa0 in position 173: invalid start byte (qwiic_kx13x.py, line 334)
  • Error 2 - ‘QwiicVL53L1X’ object has no attribute ‘SensorInit’

    This means is that the program (vl53l1x_change_i2c_address.py) cannot initialize an i2c ToF sensor (vl53l1x) that is connected to a properly configured i2c Mux (tca9548a). By properly configured, I mean the Mux was programmed with the Mux channel where the ToF sensor was attached (before the “Sensor Init” command was issued).

    This problem occurs at line 179 of vl53l1x_change_i2c_address.py.

  • I’ve uploaded the Terminal logs which details:

  • Running the following commands:

    o sudo apt-get update

    o sudo apt-get upgrade

    o sudo apt-get install -y i2c-tools


  • Installation of the SparkFun Python Qwiic libraries:

    o sudo pip3 install sparkfun-qwiic

    o sudo pip3 install sparkfun-qwiic-tca9548a

    o sudo pip3 install sparkfun-qwiic-vl53l1x


  • Execution of the SparkFun test program and associated errors:

    o python3 vl53l1x_change_i2c_address.py

  • Given all of this information, here are my questions:

  • Error 1 - As a comment, I don’t even use qwiic_kx13x sensor.

    a) What is this error?

    b) Does this error cause Error 2?

    c) What is the solution to fix or at worst case, bypass this error?


  • Error 2 -

    a) What is this error?

    b) What is the solution to fix this error?


  • How does the Python Qwiic Library setup differ between my version of Raspian and the pre-configured Autonomous

    image from SparkFun?

  • I’m sorry for the long post.

    What I’m simply asking for is technical assistance to explain why the SparkFun supplied code (vl53l1x_change_i2c_address.py) can’t operate correctly on a basic Raspberry Pi 3B+ that has been loaded with the required Python Qwiic libraries in support of a i2c Time of Flight sensor (vl53l1x) and a i2c multiplexor (tca9548a).

    Thanks in advance for your help with this problem.

    Regards, …Gary White

    So, we are really only equipped to offer support for the image we provide for the product…our first suggestion would be to use it, instead of a modified vanilla image

    That being said, my guess would be that it is running into an addressing conflict somehow or another.

    Error1 is likely from Vanilla not having the UTF version needed to decode a byte in the library…using the SparkFun image might avoid that

    Error2 is likely the result from a separate addressing issue…using the SparkFun image, try changing the ToF sensor’s address while being used by itself…then, perhaps add in a mux, etc, altering the jumpers/code as needed

    Best of luck!

    I found the issue, at least concerning Error 2 (which was the real concern for me). The issue is that the method names for the Vl53l1x sensor differ between the SparkFun Autonomous image and the PyPi sparkfun-qwiic package.

    In the SparkFun Autonomous image the method names for the Vl53l1x sensor are written in a camel case format:

  • SensorInit

  • SetI2CAddress

  • StartRanging

  • GetDistance

  • StopRanging
  • While in the PyPi sparkfun-qwiic (version 1.1.1) package, the method names for the Vl53l1x sensor are written in a lowercase, underscore format:

  • sensor_init

  • set_i2c_address

  • start_ranging

  • get_distance

  • stop_ranging
  • When I changed SparkFun’s vl53l1x_change_i2c_address.py test program to use the PyPi style of method names, everything worked!

    I know you indicated that, you can only provide support related to SparkFun supplied images and associated programs. However, there should be agreement between public class, method and attribute names between the SparkFun provided image and the corresponding PyPi and Github packages. If there are such differences between the release image and the PyPi/Github packages, then they need to be identified in the appropriate SparkFun product documentation.

    If such documentation is not possible, then there should be a tech note that provides general guidance to an end user on how to identify possible variations between a released image and the corresponding PyPi and Github packages. For example, in my case, I issued the following Python3 commands to display the symbol table for the QwiicVL53L1X class.

  • include qwiic

  • ToF= qwiic.QwiicVL53L1X(41)

  • print(f"{dir(ToF)}")

  • With the information from the symbol table, I was able to easily determine the cause of the ‘QwiicVL53L1X’ object has no attribute ‘SensorInit’ error.

    Regards, …Gary White

    Thanks! We’ll pass this along to the software team.

    Happy sparking!

    The changes to the Python package are noted in the latest commit to the repository: https://github.com/sparkfun/Qwiic_VL53L … 7e65b0e977

    That is why there is a difference between the version number of the package you installed (v1.1.1) and the one installed on the custom image (v1.0.1).

    With that said, this is why we recommend customers use the pre-configured image to avoid this type of issue. However, I will throw a note in the troubleshooting section of the hookup guide to assist others.