-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
Thanks for your contribution :) |
@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. |
Good take a look to the Datasheet tonight to see what we are talking about here. Thanks |
I can add the entire code used for testing and its results in this thread by tomorrow |
Yes, as mentioned in the other PR, we like to include new examples that way people coulddiscover the new features. |
I took a look, at the datasheet, if you have the test code that would be great. Thanks |
Added Text code and added the same in examples.rst 👍 |
Mocked Test Code : examples/tca9548a_channelscan.py # 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'] |
@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 |
This Commit, - Fixes Bug with Channel scan - Adds tca9548a_channelscan.py example code for testing - Updates examples.rst
Sure will take a look
Replaced fstrings with format 👍 |
Thanks I have to re-submit one of my own PRs 😄 . question could you Mock-up test try to mock this issue? |
on it already, suggesting some debugging tips there. |
There was a problem hiding this 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:
- 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
@jposada202020 , happy to see your reviews, I have the following comments
Further Testing Required.
|
|
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. |
Gotcha, we will see |
I did a retake on this WiringResultsThis 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 SAMD51Adafruit 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 RP2040Adafruit 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 nRF52840Adafruit 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 Codeimport 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) |
So basically this work, and there is maybe a bug in the RP2040 |
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
with this PR installed. |
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. |
Yes, I forgot that part, you are correct! |
@caternuson can you configure and access two sensors on the RP2040? |
@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)
>>> |
yikes! the bme680 and tlv4930 work on the rp2040,,,,
|
I surrender... |
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 :) |
still -- no clue why the bht1750 only misbehaves on the RP2040 with the tca9548a.... |
I would suggest a new channelscan example and a new issue regarding the bht1750. |
Normally we include a section in # Kwnow Issues. |
I have a Salea and I can try to dig into the bht1750 tomorrow |
@jerryneedell you said... that you would banish the BHT1750 and forget about this.. ... so I thought the sensor was already in the garbage bin 😄 |
I just gave it to the cat lo play with -- she gave it back. ;-) |
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. |
so -- I tried just the bh1750 on the tca9548a an then the bh1750 direct to the stemma I2c
|
I wonder if it could be something as simple as the wires being too long for the tca. |
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. |
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 :) |
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 --> FAILAdafruit 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 --> OKAdafruit 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 :) |
@jposada202020
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 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 Thought..? |
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. |
Regarding the scan and try_lock, for the normal I2C scan (without the tca9548a) the user must secure the lock manually. If we want it to be done internally, I think the change needs to be made in the core. |
@jerryneedell I have opened #33 . If needed we could move that issue to whatever the issue is. this way we could stop posting here |
I think |
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 |
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. :) |
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. |
This PR addresses #31 ,
Action: To perform i2c scan on a particular channel in TCA9548A
Bug: It Performs i2c scan on actual i2c bus where TCA9548A is connected
Fix: Perform i2c scan on selected channel