Skip to content

Bugfix Channel Scan #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

codenio
Copy link

@codenio codenio commented May 7, 2021

This PR addresses #31 ,

  • Fixes Bug with Channel scan

Action: To perform i2c scan on a particular channel in TCA9548A

...
# Initialize I2C bus.
i2c = busio.I2C(I2C1_SCL_PIN,I2C1_SDA_PIN)
# default TCA address=0x70
tca = adafruit_tca9548a.TCA9548A(i2c)

print([hex(i) for i in i2c.scan()])
print([hex(i) for i in tca[0].scan()])
...

Bug: It Performs i2c scan on actual i2c bus where TCA9548A is connected

$ python i2c-mux.py 
['0x70']
['0x70']
Press Entre to exit..

Fix: Perform i2c scan on selected channel

$ python i2c-mux.py 
['0x70']
['0x60', '0x70'] #MCP4725 DAC module is connected to channel 0 of TCA9548A
Press Entre to exit..

@jposada202020
Copy link
Contributor

Thanks for your contribution :)

@codenio codenio force-pushed the bug/channel-scan branch from d2d57d6 to 1e52114 Compare May 7, 2021 17:26
@jposada202020
Copy link
Contributor

@codenio I do not have this particular hardware, it seems that you have, is that correct? if so I could take a look at the datasheet and see the changes made,as I could not test. let me know thanks.

@codenio
Copy link
Author

codenio commented May 7, 2021

@codenio I do not have this particular hardware, it seems that you have, is that correct? if so I could take a look at the datasheet and see the changes made,as I could not test. let me know thanks.

yes @jposada202020 , I have this hardware with me, and the Bug and FIx mentioned earlier are results from hardware.

@jposada202020
Copy link
Contributor

Good take a look to the Datasheet tonight to see what we are talking about here. Thanks

@codenio
Copy link
Author

codenio commented May 7, 2021

I can add the entire code used for testing and its results in this thread by tomorrow

@jposada202020
Copy link
Contributor

Yes, as mentioned in the other PR, we like to include new examples that way people coulddiscover the new features.

@jposada202020
Copy link
Contributor

I took a look, at the datasheet, if you have the test code that would be great. Thanks

@codenio codenio force-pushed the bug/channel-scan branch from 1e52114 to 24e2d96 Compare May 8, 2021 16:31
@codenio
Copy link
Author

codenio commented May 8, 2021

Added Text code and added the same in examples.rst 👍

@codenio codenio force-pushed the bug/channel-scan branch from 24e2d96 to 71cb0ff Compare May 8, 2021 17:00
@codenio
Copy link
Author

codenio commented May 8, 2021

Mocked Test Code : examples/tca9548a_channelscan.py
It uses VPi (Virtual-Pi) Package for testing with mock adafruit_tca9548a library

# This example shows scanning of each TCA9548A channels.
try:
  import board
  import busio
  import adafruit_tca9548a
except:
  import VPi.board as board
  import VPi.busio as busio
  import VPi.adafruit_tca9548a as adafruit_tca9548a
    
# Create I2C bus as normal
i2c = busio.I2C(board.SCL, board.SDA)

# Create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

# Scan the Main I2C Channel present in your board
print(f"Scan of Main I2C Channel:{[hex(i) for i in i2c.scan()]}")

# Scan Each TCA9548A channel
for i in range(8):
    print(f"Scan of TCA[{i}] Channel: {[hex(j) for j in tca[i].scan()]}")
$ python examples/tca9548a_channelscan.py
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0xec', '0x70']
Scan of TCA[1] Channel: ['0x55', '0x70']
Scan of TCA[2] Channel: ['0xeb', '0xc5', '0x70']
Scan of TCA[3] Channel: ['0xe0', '0x70']
Scan of TCA[4] Channel: ['0x4a', '0x19', '0x91', '0x70']
Scan of TCA[5] Channel: ['0x14', '0x70']
Scan of TCA[6] Channel: ['0xfe', '0xfd', '0x9a', '0x70']
Scan of TCA[7] Channel: ['0x5b', '0x7', '0x70']

@jposada202020
Copy link
Contributor

@codenio I will test this change with hardware on hand at the end of this week, also I want to see if this could help be or not an issue in the VL53L0X library. Also just, after discussion last week, because M0 boards does not have f-strings, we would avoid them in the example code.. We have just change our design guide last week. Thanks and sorry for that last minute change
https://github.com/adafruit/circuitpython/blob/main/docs/design_guide.rst

This Commit,
- Fixes Bug with Channel scan
- Adds tca9548a_channelscan.py example code for testing
- Updates examples.rst
@codenio codenio force-pushed the bug/channel-scan branch from 71cb0ff to 8096252 Compare May 10, 2021 16:10
@codenio
Copy link
Author

codenio commented May 10, 2021

@codenio I will test this change with hardware on hand at the end of this week, also I want to see if this could help be or not an issue in the VL53L0X library. Also just, after discussion last week,

Sure will take a look

because M0 boards does not have f-strings, we would avoid them in the example code.. We have just change our design guide last week. Thanks and sorry for that last minute change
https://github.com/adafruit/circuitpython/blob/main/docs/design_guide.rst

Replaced fstrings with format 👍

@jposada202020
Copy link
Contributor

Thanks I have to re-submit one of my own PRs 😄 . question could you Mock-up test try to mock this issue?
adafruit/Adafruit_CircuitPython_VL53L0X#27. Just asking :)

@codenio
Copy link
Author

codenio commented May 10, 2021

on it already, suggesting some debugging tips there.

Copy link
Contributor

@jposada202020 jposada202020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I review the present code.
I test this with the following hardware

Hardware

  • Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
  • Adafruit TCA9548A
  • Adafruit MMA8451

Procedure:

  1. First I used the followig code modfied from the simpletest to verify was ok
import time
import board
import adafruit_mma8451
import adafruit_tca9548a
# import tca9548a_simpletest

i2c = board.I2C()
tca = adafruit_tca9548a.TCA9548A(i2c)
sensor = adafruit_mma8451.MMA8451(tca[1])

while True:
    x, y, z = sensor.acceleration
    print(
        "Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2".format(x, y, z)
    )
    time.sleep(1)

Results:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548a_simpletest
Acceleration: x=-0.105m/s^2 y=0.962m/s^2 z=9.883m/s^2
Acceleration: x=-0.081m/s^2 y=1.030m/s^2 z=9.807m/s^2
Acceleration: x=-0.053m/s^2 y=1.030m/s^2 z=9.725m/s^2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548a_simpletest.py", line 29, in <module>
KeyboardInterrupt: 
>>> 

After that I used the example provided tca9548a_channelscan.py provided in the PR

Results

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548_scantest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548_scantest.py", line 16, in <module>
RuntimeError: Function requires lock
>>> 

I tried to add i2c.lock, and unlock to allow the bus to do the scan

Results

>>> import tca9548_scantest
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0x70']
Scan of TCA[1] Channel: ['0x70']
Scan of TCA[2] Channel: ['0x70']
Scan of TCA[3] Channel: ['0x70']
Scan of TCA[4] Channel: ['0x70']
Scan of TCA[5] Channel: ['0x70']
Scan of TCA[6] Channel: ['0x8', '0x70']
Scan of TCA[7] Channel: ['0x70']
>>> 

However the MMA8451 is located at [1] as shown in the picture
image

@jposada202020 jposada202020 marked this pull request as draft May 13, 2021 02:04
@codenio
Copy link
Author

codenio commented May 13, 2021

@jposada202020 , happy to see your reviews, I have the following comments

  • is Active Low RESET of TCA9548A is pulled up to 5v with suitable resistor..? without Pulling it up TCA9548A can react abnormally (from my experience) and PFA a clip from Datasheet as it say "MUST BE CONNECTED"
    image

  • it is observable that, connected MMA8451 appears in the 2nd channel, not from first (0th index), but from last(7th Index).

Further Testing Required.

  • can you pullup RESET..? and give it a try
  • can you check its response by connecting MMA8451 to different channels..?

@jposada202020
Copy link
Contributor

  1. You are right it needs a pull-up resistor. Adafruit TCA9548A Breakout already has taken this into consideration. see https://cdn-learn.adafruit.com/assets/assets/000/027/693/original/adafruit_products_schem.png?1442010910
  2. I could for sure. I work on that in the next days.
    Thanks

@codenio
Copy link
Author

codenio commented May 13, 2021

  1. You are right it needs a pull-up resistor. Adafruit TCA9548A Breakout already has taken this into consideration. see https://cdn-learn.adafruit.com/assets/assets/000/027/693/original/adafruit_products_schem.png?1442010910

I had the same feeling that, it is taken care at the design level until I had issues with the Breakout Board, It would partially detect and would go into reset state in random intervals (may be specific to my environment or setup). so decided to pull it up externally and it started working fine.

@jposada202020
Copy link
Contributor

Gotcha, we will see

@jposada202020
Copy link
Contributor

jposada202020 commented May 23, 2021

I did a retake on this

Wiring

image

Results

This PR works, with a SAMD51, and the nRF52840, however it does not work for the RP2040. I tested this with the code mentioned above, and with a modified simpletest to include two sensor and not one. Sensor were a BH1750 and a MMA8451

SAMD51

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather M4 Express with samd51j19
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0x70']
Scan of TCA[1] Channel: ['0x1d', '0x70']
Scan of TCA[2] Channel: ['0x70']
Scan of TCA[3] Channel: ['0x70']
Scan of TCA[4] Channel: ['0x23', '0x70']
Scan of TCA[5] Channel: ['0x70']
Scan of TCA[6] Channel: ['0x70']
Scan of TCA[7] Channel: ['0x70']
>>> import tca9548a_simpletest
Acceleration: x=-0.283m/s^2 y=1.097m/s^2 z=9.821m/s^2
346.67 Lux
Acceleration: x=-0.354m/s^2 y=1.087m/s^2 z=9.797m/s^2
345.83 Lux

RP2040

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0x70']
Scan of TCA[1] Channel: ['0x70']
Scan of TCA[2] Channel: ['0x70']
Scan of TCA[3] Channel: ['0x70']
Scan of TCA[4] Channel: ['0x70']
Scan of TCA[5] Channel: ['0x70']
Scan of TCA[6] Channel: ['0x70']
Scan of TCA[7] Channel: ['0x70']
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548a_simpletest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548a_simpletest.py", line 11, in <module>
  File "/lib/adafruit_bh1750.py", line 164, in __init__
ValueError: No I2C device at address: 23

nRF52840

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather nRF52840 Express with nRF52840
>>> import tca9548a_simpletest
Acceleration: x=-0.273m/s^2 y=1.135m/s^2 z=9.802m/s^2
322.08 Lux
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather nRF52840 Express with nRF52840
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x8', '0x70']
Scan of TCA[0] Channel: ['0x8', '0x70']
Scan of TCA[1] Channel: ['0x8', '0x1d', '0x70']
Scan of TCA[2] Channel: ['0x8', '0x70']
Scan of TCA[3] Channel: ['0x8', '0x70']
Scan of TCA[4] Channel: ['0x8', '0x23', '0x70']
Scan of TCA[5] Channel: ['0x8', '0x70']
Scan of TCA[6] Channel: ['0x8', '0x70']
Scan of TCA[7] Channel: ['0x8', '0x70']
>>> 

Test Code

import time
import board
import adafruit_mma8451
import adafruit_tca9548a
import adafruit_bh1750

i2c = board.I2C()
tca = adafruit_tca9548a.TCA9548A(i2c)
sensor = adafruit_mma8451.MMA8451(tca[1])
sensor2 = adafruit_bh1750.BH1750(tca[4])

while True:
    x, y, z = sensor.acceleration
    print(
        "Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2".format(x, y, z)
    )
    time.sleep(1)
    print("%.2f Lux" % sensor2.lux)
    time.sleep(1)

@jposada202020 jposada202020 marked this pull request as ready for review May 23, 2021 01:51
@jposada202020
Copy link
Contributor

So basically this work, and there is maybe a bug in the RP2040

@jerryneedell
Copy link

I am trying to run this PR on a feather m4 express and a feather rp2040 but I am a bit confused about actual code used for the "scantest" When I try the tca9548a_channelscan.py from the repository on the Feather_m4 I get

Adafruit CircuitPython 7.0.0-alpha.2-646-g7df5d74d9 on 2021-05-23; Adafruit Feather M4 Express with samd51j19
>>> 
>>> import tca9548a_channelscan
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548a_channelscan.py", line 16, in <module>
RuntimeError: Function requires lock
>>> 

with this PR installed.
What code are you using for the test?

@caternuson
Copy link
Contributor

I believe so. Adding a new example, and maybe a doc update, might help though?

Is the BH1750 the suspect sensor here? I'm not having any issues with TLV4930, BME680, AHT20, MSA301, MMA8451. All being used with Feather RP2040 and 6.2.0 release of CP.

@jposada202020
Copy link
Contributor

Yes, I forgot that part, you are correct!

@jerryneedell
Copy link

@caternuson can you configure and access two sensors on the RP2040?

@caternuson
Copy link
Contributor

@jerryneedell seems like it.

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import board
>>> import adafruit_tca9548a
>>> import adafruit_tlv493d
>>> import adafruit_msa301
>>> tca = adafruit_tca9548a.TCA9548A(board.I2C())
>>> tlv = adafruit_tlv493d.TLV493D(tca[3])
>>> msa = adafruit_msa301.MSA301(tca[5])
>>> tlv.magnetic
(0.196, -0.196, 0.0)
>>> msa.acceleration
(0.871432, 3.95975, 10.4572)
>>> 

@jerryneedell
Copy link

yikes! the bme680 and tlv4930 work on the rp2040,,,,

Adafruit CircuitPython 7.0.0-alpha.2-646-g7df5d74d9 on 2021-05-23; Adafruit Feather RP2040 with rp2040
>>> import tca9548a_test
X: 0.098, Y: 0.196, Z: -0.098 mT
24.25 temperature
X: -0.098, Y: 0.0, Z: 0.0 mT
24.27 temperature
X: 0.0, Y: 0.0, Z: 0.0 mT

@jerryneedell
Copy link

I surrender...
I will banish the bh1750 and forget this ever happened

@jposada202020
Copy link
Contributor

So I think we all agree, if you all agree I could make a PR to clarify the documentation, to mentions the BH1750 (I would retest to be 100% sure), and add a new example trying to reflect all this discussion. let me know if you agree :)

@jerryneedell
Copy link

still -- no clue why the bht1750 only misbehaves on the RP2040 with the tca9548a....
not sure how to document that...

@jerryneedell
Copy link

I would suggest a new channelscan example and a new issue regarding the bht1750.

@jposada202020
Copy link
Contributor

Normally we include a section in # Kwnow Issues.
I do not have a Saleae, and Cater does not have the sensor, so in the meantime we could do this

@jerryneedell
Copy link

I have a Salea and I can try to dig into the bht1750 tomorrow

@jposada202020
Copy link
Contributor

@jerryneedell you said... that you would banish the BHT1750 and forget about this.. ... so I thought the sensor was already in the garbage bin 😄

@jerryneedell
Copy link

I just gave it to the cat lo play with -- she gave it back. ;-)

@caternuson
Copy link
Contributor

Yep. I generally agree with above. It looks like this all started with an issue about being able to do I2C scans with TCA, and I think it could, just wasn't obvious how - so a new example will help with that.

For the BHT1750 - yah, who knows. I'll order one up and can test when I get it. But that should be a new issue.

@jerryneedell
Copy link

jerryneedell commented May 25, 2021

so -- I tried just the bh1750 on the tca9548a an then the bh1750 direct to the stemma I2c

Adafruit CircuitPython 7.0.0-alpha.2-646-g7df5d74d9 on 2021-05-23; Adafruit Feather RP2040 with rp2040
>>> 
>>> import tca9548a_test3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548a_test3.py", line 20, in <module>
  File "adafruit_bh1750.py", line 191, in __init__
  File "adafruit_bh1750.py", line 196, in initialize
  File "adafruit_bh1750.py", line 116, in __set__
  File "adafruit_bh1750.py", line 205, in _settings
  File "adafruit_bh1750.py", line 235, in _write
  File "adafruit_tca9548a.py", line 54, in unlock
OSError: [Errno 19] Unsupported operation
>>> 
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Hello World!

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.2-646-g7df5d74d9 on 2021-05-23; Adafruit Feather RP2040 with rp2040
>>> import bh1750_simpletest
12.92 Lux
12.92 Lux

@jerryneedell
Copy link

jerryneedell commented May 25, 2021

I wonder if it could be something as simple as the wires being too long for the tca.
but then why does it work on the M4....sigh

@jerryneedell
Copy link

I'll be happy to try hooking up my salea to the bht1750 tomorrow and see if I can learn anything. I will also create a new issue for it after I clean up my test code (and my bench). Or @jposada202020 since you have the bh1750 -- you are welcome to create an issue and I'll add to it.

@jposada202020
Copy link
Contributor

Will do @jerryneedell I ll create the issue, I just want to test one more time to be 100%, and maybe try some other random sensors :) maybe the ADT7410.. who knows :)

@jposada202020
Copy link
Contributor

So after I successful test this fails again.

However, there is a difference between testing in the REPL as @caternuson does and doing it with a File as @jerryneedell and myself do

File --> FAIL

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import test_two_sensors
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test_two_sensors.py", line 13, in <module>
  File "/lib/adafruit_bh1750.py", line 164, in __init__
ValueError: No I2C device at address: 23

REPL --> OK

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import time
>>> import board
>>> import adafruit_mma8451
>>> import adafruit_tca9548a
>>> import adafruit_bh1750
>>> i2c = board.I2C()
>>> tca = adafruit_tca9548a.TCA9548A(i2c)
>>> sensor = adafruit_mma8451.MMA8451(tca[1])
>>> sensor2 = adafruit_bh1750.BH1750(tca[4])
>>> while True:
...     x, y, z = sensor.acceleration
...     print("Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2".format(x, y, z))
...     print("%.2f Lux" % sensor2.lux)
...     time.sleep(1)
... 
Acceleration: x=-0.192m/s^2 y=0.350m/s^2 z=9.783m/s^2
1152.92 Lux
Acceleration: x=-0.249m/s^2 y=0.388m/s^2 z=9.778m/s^2
1152.08 Lux
Acceleration: x=-0.268m/s^2 y=0.378m/s^2 z=9.831m/s^2
1152.92 Lux

Could this be related to the clock on the RP2040?

And have a good night... I could not go to bed with this :)

@codenio
Copy link
Author

codenio commented May 25, 2021

So it is fair to say that conclusions so far:

  1. PR is not needed to scan the channels

@jposada202020
yes, if you suggest ppl to use try_lock() and unlock() consciously while scanning any channel, at any time and every time.

Keep in mind the boiler plate I2C scan code without a mux involved:

import board
i2c = board.I2C()
i2c.try_lock()
i2c.scan()
i2c.unlock()

@caternuson This PR does exactly the same, but in an abstract way by including try_lock and unlock inside the channel.scan function itself.

It couldn't find such requirements of explicit locking and unlocking with writing data into or read data from an i2c device (as they are abstracted within them).

I feel that try_lock() and unlock() need to be abstracted inside the channel.scan function.

Thought..?

@jerryneedell
Copy link

In some quick tests this morning, I am finding that I can access either the bh1750 or the bme680 individually via the tca9548a but I get failures when I try to access both. In most cases the failure is on the one I attempt to configure second.
Sometimes the system get in a bad state ( gives "unsupported operation error) and I have to do a hard reset to get it working normally again.
This has nothing to do with this PR so I will stop posting to this PR after this and will see if I can come up with a coherent new issue.

@jerryneedell
Copy link

Regarding the scan and try_lock, for the normal I2C scan (without the tca9548a) the user must secure the lock manually.
I don't know the history for why is is not done by the scan function but I suggest we keep it consistent.
the busio scan function checks for the lock https://github.com/adafruit/circuitpython/blob/main/shared-bindings/busio/I2C.c#L139

If we want it to be done internally, I think the change needs to be made in the core.
I am not advocating that just pointing it out.

@jposada202020
Copy link
Contributor

@jerryneedell I have opened #33 . If needed we could move that issue to whatever the issue is. this way we could stop posting here

@caternuson
Copy link
Contributor

I think tca[n].scan() should behave the same as i2c.scan(). So the need to manually lock/unlock the bus should be retained. Which agrees with @jerryneedell comments above about same.

@jposada202020
Copy link
Contributor

So after all this discussion I think this PR is no longer required. The issue is already raise, I will add another issue, to keep track of adding the new example to reflect our findings in here
@codenio Thanks this was a helpful and constructive discussion

@caternuson caternuson mentioned this pull request May 27, 2021
@evaherrada evaherrada changed the base branch from master to main June 2, 2021 18:14
@caternuson
Copy link
Contributor

So after all this discussion I think this PR is no longer required.

I agree. There seems to be some other potentially tangential issues that have been raised above, but those should be dealt with separately. Closing this PR for now. Thanks for the work on this. Lots of good discussion in this thread. :)

@caternuson caternuson closed this Jun 14, 2021
@Wongolini
Copy link

Wongolini commented Jun 8, 2024

I did a retake on this

Wiring

image

Results

This PR works, with a SAMD51, and the nRF52840, however it does not work for the RP2040. I tested this with the code mentioned above, and with a modified simpletest to include two sensor and not one. Sensor were a BH1750 and a MMA8451

SAMD51

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather M4 Express with samd51j19
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0x70']
Scan of TCA[1] Channel: ['0x1d', '0x70']
Scan of TCA[2] Channel: ['0x70']
Scan of TCA[3] Channel: ['0x70']
Scan of TCA[4] Channel: ['0x23', '0x70']
Scan of TCA[5] Channel: ['0x70']
Scan of TCA[6] Channel: ['0x70']
Scan of TCA[7] Channel: ['0x70']
>>> import tca9548a_simpletest
Acceleration: x=-0.283m/s^2 y=1.097m/s^2 z=9.821m/s^2
346.67 Lux
Acceleration: x=-0.354m/s^2 y=1.087m/s^2 z=9.797m/s^2
345.83 Lux

RP2040

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x70']
Scan of TCA[0] Channel: ['0x70']
Scan of TCA[1] Channel: ['0x70']
Scan of TCA[2] Channel: ['0x70']
Scan of TCA[3] Channel: ['0x70']
Scan of TCA[4] Channel: ['0x70']
Scan of TCA[5] Channel: ['0x70']
Scan of TCA[6] Channel: ['0x70']
Scan of TCA[7] Channel: ['0x70']
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import tca9548a_simpletest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tca9548a_simpletest.py", line 11, in <module>
  File "/lib/adafruit_bh1750.py", line 164, in __init__
ValueError: No I2C device at address: 23

nRF52840

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather nRF52840 Express with nRF52840
>>> import tca9548a_simpletest
Acceleration: x=-0.273m/s^2 y=1.135m/s^2 z=9.802m/s^2
322.08 Lux
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather nRF52840 Express with nRF52840
>>> import tca9548_scantest
Scan of Main I2C Channel:['0x8', '0x70']
Scan of TCA[0] Channel: ['0x8', '0x70']
Scan of TCA[1] Channel: ['0x8', '0x1d', '0x70']
Scan of TCA[2] Channel: ['0x8', '0x70']
Scan of TCA[3] Channel: ['0x8', '0x70']
Scan of TCA[4] Channel: ['0x8', '0x23', '0x70']
Scan of TCA[5] Channel: ['0x8', '0x70']
Scan of TCA[6] Channel: ['0x8', '0x70']
Scan of TCA[7] Channel: ['0x8', '0x70']
>>> 

Test Code

import time
import board
import adafruit_mma8451
import adafruit_tca9548a
import adafruit_bh1750

i2c = board.I2C()
tca = adafruit_tca9548a.TCA9548A(i2c)
sensor = adafruit_mma8451.MMA8451(tca[1])
sensor2 = adafruit_bh1750.BH1750(tca[4])

while True:
    x, y, z = sensor.acceleration
    print(
        "Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2".format(x, y, z)
    )
    time.sleep(1)
    print("%.2f Lux" % sensor2.lux)
    time.sleep(1)

Has anyone found a reason this does not work for RP2040? I wanted to use this with a RasperryPi Pico but was disappointed to reproduce this error. It also appears to not work with ATSAMD21G18 on metro express.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants