adafruit / Adafruit_CircuitPython_MPL3115A2

CircuitPython module for the MPL3115A2 barometric pressure & temperature sensor.
MIT License
5 stars 8 forks source link

Getting ETIMEDOUT on Pi Pico (others?) #19

Closed caternuson closed 2 years ago

caternuson commented 2 years ago

Re this thread: https://forums.adafruit.com/viewtopic.php?f=8&t=184555

Recreated:

Adafruit CircuitPython 7.0.0 on 2021-09-20; Raspberry Pi Pico with rp2040
>>> import board
>>> import busio
>>> import adafruit_mpl3115a2
>>> scldata = board.GP7
>>> sdadata = board.GP6
>>> i2c = busio.I2C(scldata, sdadata)
>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mpl3115a2.py", line 149, in __init__
  File "adafruit_mpl3115a2.py", line 194, in _poll_reg1
  File "adafruit_mpl3115a2.py", line 171, in _read_u8
  File "adafruit_mpl3115a2.py", line 167, in _read_into
OSError: [Errno 116] ETIMEDOUT
>>> 
caternuson commented 2 years ago

Works OK on Itsy M4:

Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_mpl3115a2
>>> sensor = adafruit_mpl3115a2.MPL3115A2(board.I2C())
>>> sensor.pressure
100641.0
>>> 
caecilliusinhorto commented 2 years ago

I think it's an RP2040 specific error, getting the same error on a Feather RP2040

caecilliusinhorto commented 2 years ago

Works on circuitpython 6.2 though.

ladyada commented 2 years ago

@caecilliusinhorto can you try the very latest release?

caternuson commented 2 years ago

Just tried with 7.2.0. Still looking sad :(

Adafruit CircuitPython 7.2.0 on 2022-02-24; Raspberry Pi Pico with rp2040
>>> import board
>>> import busio
>>> import adafruit_mpl3115a2
>>> scldata = board.GP7
>>> sdadata = board.GP6
>>> i2c = busio.I2C(scldata, sdadata)
>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mpl3115a2.py", line 144, in __init__
  File "adafruit_mpl3115a2.py", line 189, in _poll_reg1
  File "adafruit_mpl3115a2.py", line 166, in _read_u8
  File "adafruit_mpl3115a2.py", line 162, in _read_into
OSError: [Errno 116] ETIMEDOUT
>>> 

Shows up in scan at least:

Adafruit CircuitPython 7.2.0 on 2022-02-24; Raspberry Pi Pico with rp2040
>>> import board
>>> import busio
>>> i2c = busio.I2C(board.GP7, board.GP6)
>>> i2c.try_lock()
True
>>> i2c.scan()
[96]
>>> i2c.scan()
[96]
>>> 
ladyada commented 2 years ago

@caternuson can ya try bitbangio and also dump a saleae trace for @dhalbert

caternuson commented 2 years ago

A little closer with bitbang, but still has issues:

Adafruit CircuitPython 7.2.0 on 2022-02-24; Raspberry Pi Pico with rp2040
>>> import board
>>> import bitbangio
>>> import adafruit_mpl3115a2
>>> scldata = board.GP7
>>> sdadata = board.GP6
>>> i2c = bitbangio.I2C(scldata, sdadata)
>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
>>> sensor.pressure
101330.0
>>> sensor.temperature

last call is frozen, probably stuck on this wait loop: https://github.com/adafruit/Adafruit_CircuitPython_MPL3115A2/blob/fcd304ec51b8bb19161f36a05875abb00f3e0fad/adafruit_mpl3115a2.py#L252-L256

Will saleae next.

caternuson commented 2 years ago

Switched back to hardware I2C for saleae testing and also simplified code a bit:

Adafruit CircuitPython 7.2.0 on 2022-02-24; Raspberry Pi Pico with rp2040
>>> import board
>>> import busio
>>> import adafruit_mpl3115a2
>>> i2c = busio.I2C(board.GP7, board.GP6)
>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mpl3115a2.py", line 144, in __init__
  File "adafruit_mpl3115a2.py", line 189, in _poll_reg1
  File "adafruit_mpl3115a2.py", line 166, in _read_u8
  File "adafruit_mpl3115a2.py", line 162, in _read_into
OSError: [Errno 116] ETIMEDOUT
>>> 

Seems to be having issues coming back up after the software reset. There's an intentional 10ms delay after the reset: Screenshot from 2022-03-05 09-23-45

but the first query attempt in _poll_reg1 fails: Screenshot from 2022-03-05 09-25-01

ladyada commented 2 years ago

@caternuson what if retry it? could be we have to 'wake up' the i2c?

caternuson commented 2 years ago

Quick hack change:

        # Poll for the reset to finish.
        try:
          self._poll_reg1(_MPL3115A2_CTRL_REG1_RST)
        except:
          self._poll_reg1(_MPL3115A2_CTRL_REG1_RST)

It at least can init the sensor:

Adafruit CircuitPython 7.2.0 on 2022-02-24; Raspberry Pi Pico with rp2040
>>> import board
>>> import busio
>>> import adafruit_mpl3115a2
>>> i2c = busio.I2C(board.GP7, board.GP6)
>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
>>> 

Here's the trace: Screenshot from 2022-03-05 12-02-06 Second attempt is after the long SCL low period. Zooming in there: Screenshot from 2022-03-05 12-02-21 So it at least comes back to life that way.

Can also get a pressure reading, but temperature hangs same as above with bitbang:

>>> sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
>>> sensor.pressure
101482.0
>>> sensor.temperature
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_mpl3115a2.py", line 259, in temperature
  File "/lib/adafruit_mpl3115a2.py", line 169, in _read_u8
  File "/lib/adafruit_mpl3115a2.py", line 165, in _read_into
KeyboardInterrupt: 
>>> 

Here's saleae of the temperature read: Screenshot from 2022-03-05 12-06-21 It's stuck waiting for some status that never changes. Each attempt is this: Screenshot from 2022-03-05 12-12-31

ladyada commented 2 years ago

!? and the same exact code runs on an m4?

caternuson commented 2 years ago

Interesting. It does not. The previous test earlier only grabbed pressure. But even Itsy M4 is hanging on temperature.

Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_mpl3115a2
>>> sensor = adafruit_mpl3115a2.MPL3115A2(board.I2C())
>>> sensor.pressure
101466.0
>>> sensor.temperature
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mpl3115a2.py", line 256, in temperature
KeyboardInterrupt:
>>> 

Same I2C traffic: Screenshot from 2022-03-05 12-39-17 Screenshot from 2022-03-05 12-40-53

So may be multiple issues happening:

millerm22 commented 2 years ago

Any progress on this issue? I am a HS teacher and just ran into this same issue on a RPi Pico running circuitpython 7.3.2. We transitioned over to the Pico from the Zero for the coming year due to supply chain issues. We were using the MPL3115A2 board in the curriculum before. Any advice (should we look at other altimeter options?) would be much appreciated.

caternuson commented 2 years ago

@millerm22 Possibly resolved! Got a chance to take another look at this today and might have finally found the main issue. If you know how / want to test some PR code, proposed fix is here: https://github.com/adafruit/Adafruit_CircuitPython_MPL3115A2/pull/22

millerm22 commented 2 years ago

@millerm22 Possibly resolved! Got a chance to take another look at this today and might have finally found the main issue. If you know how / want to test some PR code, proposed fix is here: #22

Wow yall are awesome. Thanks so much for looking into this. I'd be happy to try out the new code, but I'm not sure how the process works. Will the updated code be rolled out in tomorrow's autorelease?

caternuson commented 2 years ago

OK, went ahead and made a new release: https://github.com/adafruit/Adafruit_CircuitPython_MPL3115A2/releases/tag/2.0.0 So it should be in the next autorelease bundle.

millerm22 commented 2 years ago

@caternuson It works perfectly!! Thanks again for all of your help.

caternuson commented 2 years ago

woot! awesome. glad that fixed it. thanks for letting us know. good luck with the class!