Help with MPL3115A2 and Raspberry Pi Pico

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
antoniopared
 
Posts: 4
Joined: Tue Oct 26, 2021 1:31 pm

Help with MPL3115A2 and Raspberry Pi Pico

Post by antoniopared »

Hello,

this is my first project with microcontrollers, and i'd like to ask for help in figuring out what i am doing wrong. i connected an MPL3115A2 to a Raspberry Pi Pico running CircuitPython 7.

here is my code:

Code: Select all

import board
import adafruit_mpl3115a2
import busio
import time

scldata = board.GP7
sdadata = board.GP6

i2c = busio.I2C(scldata, sdadata)

sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
and here is the output:

Code: Select all

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
  File "code.py", line 11, in <module>
  File "/lib/adafruit_mpl3115a2.py", line 149, in __init__
  File "/lib/adafruit_mpl3115a2.py", line 194, in _poll_reg1
  File "/lib/adafruit_mpl3115a2.py", line 171, in _read_u8
  File "/lib/adafruit_mpl3115a2.py", line 167, in _read_into
OSError: [Errno 116] ETIMEDOUT

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.
am i missing something? thanks!

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

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by adafruit_support_carter »

Code looks OK. It may be something hardware related. Please post a photo of your setup showing how everything is connected.

User avatar
antoniopared
 
Posts: 4
Joined: Tue Oct 26, 2021 1:31 pm

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by antoniopared »

hello, thank you for the reply. please see below photo and let me know if i need to post a different angle. thank you!
20211029_004346.jpg
20211029_004346.jpg (140.54 KiB) Viewed 610 times

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

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by adafruit_support_carter »

Thanks. That looks generally OK. Does it show up OK in an I2C scan?
https://learn.adafruit.com/scanning-i2c ... cuitpython

You'll want to continue to setup your I2C bus same as you have been (the guide is generic). So keep this past as is:

Code: Select all

scldata = board.GP7
sdadata = board.GP6

i2c = busio.I2C(scldata, sdadata)

User avatar
antoniopared
 
Posts: 4
Joined: Tue Oct 26, 2021 1:31 pm

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by antoniopared »

here is my code now,

Code: Select all

import busio
import board
import adafruit_mpl3115a2
import time

scldata = board.GP7
sdadata = board.GP6

i2c = busio.I2C(scldata, sdadata)


while not i2c.try_lock():
    pass

try:
    while True:
        print("I2C addresses found:", [hex(device_address)
              for device_address in i2c.scan()])
        time.sleep(2)

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
    i2c.unlock()
and it outputs this messge:

Code: Select all

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
I2C addresses found: ['0x60']
I2C addresses found: ['0x60']
I2C addresses found: ['0x60']
I2C addresses found: ['0x60']
Traceback (most recent call last):
  File "code.py", line 19, in <module>
KeyboardInterrupt: 

Code done running.
but if i add these two lines at the end:

Code: Select all

    sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
    print (sensor)
the same error will occur:

Code: Select all

Traceback (most recent call last):
  File "code.py", line 28, in <module>
  File "/lib/adafruit_mpl3115a2.py", line 149, in __init__
  File "/lib/adafruit_mpl3115a2.py", line 194, in _poll_reg1
  File "/lib/adafruit_mpl3115a2.py", line 171, in _read_u8
  File "/lib/adafruit_mpl3115a2.py", line 167, in _read_into
OSError: [Errno 116] ETIMEDOUT
should i try adding a 10k resistor on both the SDA and SCL lines?

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

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by adafruit_support_carter »

OK, set this up and was able to recreate this issue right away. Seeing all same behavior you are - I2C scan works, but get ETIMEDOUT. Not sure what is happening. Opened a new issue for this here:
https://github.com/adafruit/Adafruit_Ci ... /issues/19

User avatar
antoniopared
 
Posts: 4
Joined: Tue Oct 26, 2021 1:31 pm

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by antoniopared »

wow thank you so much for looking and ooening the github issue! i will keep an eye on it as well... :-)

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

Re: Help with MPL3115A2 and Raspberry Pi Pico

Post by adafruit_support_carter »

Hey, sorry this took so long. Turned out to be pretty simple once found. But there was some other quirky behavior that was distracting and looking more involved.

Here's the PR:
https://github.com/adafruit/Adafruit_Ci ... A2/pull/22
And should be a new library release soon as well with this fix in place.

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

Return to “General Project help”