-
Notifications
You must be signed in to change notification settings - Fork 16
While accesing sensors on the RP2040 give results that are not as expected when not using the REPL #33
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
Comments
Just to add some more information -- I have a BH1750 and a BME680 attached via a tca9548a to a feather_rp2040
just the bme680
just the bh1750
First try accessing both works OK --
next run fails -- after soft reboot
Note that it failed accessing the second sensor -- the bme680 -- it read from the bh1750
If I use a feather_m4 express, I have not seen any errors. Same code. |
This works without a problen when using the REPL on the RP2040 >>> import test_two_sensors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test_two_sensors.py", line 12, in <module>
File "/lib/adafruit_mma8451.py", line 120, in __init__
ValueError: No I2C device at address: 1d
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
hello Jose
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
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
>>> import adafruit_mpl3115a2
>>> i2c = board.I2C()
>>> tca = adafruit_tca9548a.TCA9548A(i2c)
>>> sensor2 = adafruit_bh1750.BH1750(tca[4])
>>> sensor = adafruit_mma8451.MMA8451(tca[1])
>>> sensor3 = adafruit_mpl3115a2.MPL3115A2(tca[2])
>>> sensor3.sealevel_pressure = 102250
>>> 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)
... pressure = sensor3.pressure
... print("Pressure: {0:0.3f} pascals".format(pressure))
...
Acceleration: x=-0.120m/s^2 y=-0.144m/s^2 z=9.869m/s^2
122.92 Lux
Pressure: 100828.254 pascals
Acceleration: x=-0.158m/s^2 y=-0.053m/s^2 z=9.807m/s^2
125.83 Lux |
The BHT1750 is not the problem here as shown here 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 9, in <module>
File "/lib/adafruit_mpl3115a2.py", line 135, in __init__
ValueError: No I2C device at address: 60
>>> import time
>>> import board
>>> import adafruit_mma8451
>>> import adafruit_tca9548a
>>> import adafruit_mpl3115a2
>>> i2c = board.I2C()
>>> tca = adafruit_tca9548a.TCA9548A(i2c)
>>> sensor = adafruit_mma8451.MMA8451(tca[1])
>>> sensor3 = adafruit_mpl3115a2.MPL3115A2(tca[2])
>>> sensor3.sealevel_pressure = 102250
>>> 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)
... pressure = sensor3.pressure
... print("Pressure: {0:0.3f} pascals".format(pressure))
...
Acceleration: x=-0.105m/s^2 y=-0.326m/s^2 z=9.902m/s^2
Pressure: 100857.747 pascals
Acceleration: x=-0.110m/s^2 y=-0.239m/s^2 z=9.778m/s^2
Pressure: 100855.494 pascals
Acceleration: x=-0.120m/s^2 y=-0.244m/s^2 z=9.859m/s^2
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
KeyboardInterrupt: |
Tested in the RP PIco same results Adafruit CircuitPython 6.2.0 on 2021-04-05; Raspberry Pi Pico with rp2040
>>> import two_sensors_test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "two_sensors_test.py", line 10, in <module>
File "/lib/adafruit_mpl3115a2.py", line 136, in __init__
ValueError: No I2C device at address: 60
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
hello
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 6.2.0 on 2021-04-05; Raspberry Pi Pico with rp2040
>>> import time
>>> import board
>>> import busio
>>> import adafruit_mma8451
>>> import adafruit_tca9548a
>>> import adafruit_mpl3115a2
>>> i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA
>>> tca = adafruit_tca9548a.TCA9548A(i2c)
>>> sensor = adafruit_mma8451.MMA8451(tca[1])
>>> sensor3 = adafruit_mpl3115a2.MPL3115A2(tca[2])
>>> sensor3.sealevel_pressure = 102250
>>> 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)
... pressure = sensor3.pressure
... print("Pressure: {0:0.3f} pascals".format(pressure))
...
Acceleration: x=-0.139m/s^2 y=0.546m/s^2 z=9.831m/s^2
Pressure: 100858.498 pascals
Acceleration: x=-0.105m/s^2 y=0.532m/s^2 z=9.859m/s^2
Pressure: 100860.000 pascals
Acceleration: x=-0.120m/s^2 y=0.536m/s^2 z=9.826m/s^2
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
KeyboardInterrupt: |
Now - I reversed the order in which the sensors are accessed
the second time it fails, but on the second sensor again -- this time the bh1750 fails, it reads from the bme680
also I occasionally get this response ...
|
More information this is the nature of the same transaction wthe the rp2040 You can see that the writes are different -- the m4 has an additional write to 0x70 ( the tca9548a) of data value 0x02 that is missing from the rp2040 write. This would explain the failure but it is not clear why the write is missing.... |
Could you try it in the REPL? to see why in writing the code in the REPL it does work? |
but next time I tried it, it did work, but I did not capture it. One difference is I did not read from the bme680 in between. but I think it is just intermittent. I will do more runs do see if I can find a reproducible pattern. |
That's about all the fun I can have today -- I will continue testing this tomorrow. |
I'm wondering if this might have self healed with some CP firmware update(s) since initially posted? I'm testing on a Feather RP2040 with a BH1750 and MMA8451 connected thru a TCA9548A running the test code in first post above. It seems to run fine. Adafruit CircuitPython 8.2.7 on 2023-10-19; Adafruit Feather RP2040 with rp2040
>>> import test.py
Acceleration: x=0.048m/s^2 y=0.110m/s^2 z=9.840m/s^2
67.50 Lux
Acceleration: x=0.029m/s^2 y=0.019m/s^2 z=9.740m/s^2
10.42 Lux
Acceleration: x=0.139m/s^2 y=0.086m/s^2 z=9.773m/s^2
56.67 Lux
Acceleration: x=-3.285m/s^2 y=-3.314m/s^2 z=7.211m/s^2
47.50 Lux
Acceleration: x=0.010m/s^2 y=-0.661m/s^2 z=9.725m/s^2
81.25 Lux
Acceleration: x=0.024m/s^2 y=-0.651m/s^2 z=9.754m/s^2
81.25 Lux |
Closing. Can't recreate issue with current versions of CP firmware. Can reopen if issue is confirmed to still exist. |
While accessing two sensors in this case:
BH1750
MMA8451
This is seeing mostly in the RP2040. Have tested with the SAMD51 and the nRF52840 without seeing this issue.
Error
test code
Other Information
The text was updated successfully, but these errors were encountered: