Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Feather RP2040 - Multiple I2C Devices on STEMMA port
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather RP2040 - Multiple I2C Devices on STEMMA port

by hvrper on Mon Oct 18, 2021 2:50 am

Is it possible to daisy chain multiple devices to the STEMMA port on the Feather RP2040? The code I am running runs on the Pi 4 but when I run it on the Feather RP2040 I get this error:

"ValueError:SCL in use"

For testing I am using two Adafruit I2C devices, the I2C QT Rotary Encoder and the MPRLS Pressure Sensor. When I run "i2cdetect -y 1" from the terminal it shows they have different addresses.

In case it helps, here is the code that I am using:

Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
import adafruit_mprls
i2c = busio.I2C(board.SCL, board.SDA)
mpr = adafruit_mprls.MPRLS(i2c, psi_min=0, psi_max=25)

from rainbowio import colorwheel
from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio
i2c = busio.I2C(board.SCL, board.SDA)
seesaw = seesaw.Seesaw(i2c, 0x36)

encoder = rotaryio.IncrementalEncoder(seesaw)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
switch = digitalio.DigitalIO(seesaw, 24)

pixel = neopixel.NeoPixel(seesaw, 6, 1)
pixel.brightness = 0.5

last_position = -1
color = 9  # start at red plus 9

while True:

    # negate the position to make clockwise rotation positive
    position = -encoder.position
    print("Pressure (hPa):", mpr.pressure)
    if position != last_position:
        print(position)

        if switch.value:
            # Change the LED color.
            if position > last_position:  # Advance forward through the colorwheel.
                color += 1
            else:
                color -= 1  # Advance backward through the colorwheel.
            color = (color + 256) % 256  # wrap around to 0-256
            pixel.fill(colorwheel(color))

        else:  # If the button is pressed...
            # ...change the brightness.
            if position > last_position:  # Increase the brightness.
                pixel.brightness = min(1.0, pixel.brightness + 0.1)
            else:  # Decrease the brightness.
                pixel.brightness = max(0, pixel.brightness - 0.1)

    last_position = position




print("Pressure (hPa):", mpr.pressure)

# You can also specify both reset and eoc pins
"""
#import digitalio
#reset = digitalio.DigitalInOut(board.D5)
#eoc = digitalio.DigitalInOut(board.D6)
#mpr = adafruit_mprls.MPRLS(i2c, eoc_pin=eoc, reset_pin=reset,
#                           psi_min=0, psi_max=25)
"""

while True:
    print((mpr.pressure,))
    time.sleep(.001)



Any insight would be helpful. Thanks in advance.
hvrper
 
Posts: 6
Joined: Wed Aug 28, 2013 4:24 pm

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

by jerryn on Mon Oct 18, 2021 6:18 am

You should only create the "i2c" device once -- remove the second line "i2c = busio.I2C(board.SCL, board.SDA)"
Both devices are using the same instance of the i2c bus.

Note: I do not represent Adafruit. Just trying to help.

jerryn
 
Posts: 1583
Joined: Sat Sep 14, 2013 9:05 am

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

by adafruit_support_carter on Mon Oct 18, 2021 2:51 pm

Yep, what jerryn said.

I2C allows more than one device on the same bus as long as each has a unique I2C address - which is what you'll see in the scan.

So just create a single bus instance and pass that in for each device.

adafruit_support_carter
 
Posts: 21891
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

by hvrper on Tue Oct 19, 2021 8:37 pm

Jerryn and Carter that did it!! That duplicate line of code was a giant hurdle for me. Thank you so much!
hvrper
 
Posts: 6
Joined: Wed Aug 28, 2013 4:24 pm

Please be positive and constructive with your questions and comments.