Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Can't use external I2C devices
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can't use external I2C devices

by mpc823 on Sat Oct 17, 2020 8:19 pm

I'm trying to run the VL53L0X sample code below, but keep getting the error:

Code: Select all | TOGGLE FULL SIZE
main.py output:
Traceback (most recent call last):
  File "main.py", line 9, in <module>
ValueError: A4 in use


I can't figure out why I can't get use of the I2C clock line.

Code: Select all | TOGGLE FULL SIZE
import time
 
import board
import busio
 
import adafruit_vl53l0x
 
# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
vl53 = adafruit_vl53l0x.VL53L0X(i2c)
 
# Main loop will read the range and print it every second.
while True:
    print("Range: {0}mm".format(vl53.range))
    time.sleep(1.0)

mpc823
 
Posts: 60
Joined: Thu May 05, 2016 9:10 am

Re: Can't use external I2C devices

by dastels on Sat Oct 17, 2020 8:57 pm

What board and version of CircuitPython are you using?

Dave

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't use external I2C devices

by mpc823 on Sat Oct 17, 2020 9:31 pm

I'm using the Bluefruit CPX and Circuit Python 6 beta. But it appears that after I took everything part and repowered the board things are actually working now. Not sure what happened before, but even across reset it wasn't working. I guess it took actually powering down the board.

Its working now, but thanks for the reply.

mpc823
 
Posts: 60
Joined: Thu May 05, 2016 9:10 am

Re: Can't use external I2C devices

by mpc823 on Sun Oct 18, 2020 9:52 am

Looks like it only works right after I power cycle everything. But if I try to save my Circuit Python code after any changes, I get the "A4 in use" error. Frustrating.

mpc823
 
Posts: 60
Joined: Thu May 05, 2016 9:10 am

Re: Can't use external I2C devices

by dastels on Sun Oct 18, 2020 10:42 am

Try using board.I2C to get the i2c object rather than busio and the pins.

Dave

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't use external I2C devices

by dastels on Sun Oct 18, 2020 2:43 pm

I just got word that this is being addressed in an upcoming CP 6 build.

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't use external I2C devices

by mpc823 on Sun Oct 18, 2020 3:59 pm

That seems to work. Thanks. Why does that work and busio does not?

mpc823
 
Posts: 60
Joined: Thu May 05, 2016 9:10 am

Re: Can't use external I2C devices

by dastels on Sun Oct 18, 2020 4:53 pm

I believe board.I2C caches it and so avoid reusing it.

dastels
 
Posts: 3862
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't use external I2C devices

by tannewt on Mon Oct 19, 2020 8:59 pm

mpc823, could you post your latest code and a picture of your setup so I can try and reproduce? The similar error we found on the MatrixPortal was specific to the MatrixPortal build. Thanks!

tannewt
 
Posts: 1849
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.