Feather RP2040 - Multiple I2C Devices on STEMMA port

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
hvrper
 
Posts: 16
Joined: Wed Aug 28, 2013 4:24 pm

Feather RP2040 - Multiple I2C Devices on STEMMA port

Post by hvrper »

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

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.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

Post by jerryn »

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.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

Post by adafruit_support_carter »

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.

hvrper
 
Posts: 16
Joined: Wed Aug 28, 2013 4:24 pm

Re: Feather RP2040 - Multiple I2C Devices on STEMMA port

Post by hvrper »

Jerryn and Carter that did it!! That duplicate line of code was a giant hurdle for me. Thank you so much!

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”