2

Trying to use the Raspberry Pi Pico W and some i2c devices with micropython but running into issues.

When I try to scan one device, it seems fine, but as soon as any more come onto the I2C bus, it never seems consistent with the result, most of the time coming up with no addresses.

This is the code I am using:

from machine import Pin, I2C

i2c = I2C(0, scl=Pin(1), sda=Pin(0))
addrs = [hex(addr) for addr in i2c.scan()]
print(addrs)

and the Schematic.

If anyone has any ideas, please let me know as I have tried rebuilding the circuit about a billion times, and nothing seems to help.

Cheers
Jacob

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Have you tried SoftI2C – Andy Piper Aug 14 '22 at 00:38
  • @AndyPiper thank you for the comment. Why would you use SoftI2C over the hardware I2C for this application? Not putting you down but genuinely intrigued. – jacoboneill2000 Aug 15 '22 at 07:14
  • 1
    Wasn't assuming any ill intent for the question! I've just sometimes found that SoftI2C works or enables you to reassign I2C more easily than hardware I2C which relies on specific configuration of the MicroPython firmware build for the board (also I wasn't near a computer for a longer investigation) - glad you figured it out! – Andy Piper Aug 16 '22 at 16:39

1 Answers1

2

Found an answer from the manufacturer. Turns out that there needed to be a 4.7k resistor on the SDA and SCL lines (was in the docs... oops)

Codes all good tho!

  • Can you provide a link to the docs that mentioned this? – Sterling Oct 05 '22 at 14:59
  • Also, by manufacturer, do you mean the manufacturer of a sensor/peripheral or the manufacturer of the Pico W (i.e. Raspberry Pi Foundation)? – Sterling Oct 05 '22 at 18:28
  • Clear now to me that this is referring to the manufacturer of the peripheral. I'm having trouble getting an [ArduCam 2 MP](https://www.arducam.com/product/arducam-2mp-spi-camera-b0067-arduino/) recognized by the Pico W through I2C. Supposedly there are pull-up resistors on the module, but I wonder if I should get some resistors and add them in. Otherwise pretty stumped.. – Sterling Oct 06 '22 at 16:38
  • Hi Sterling, sorry for the lack of communication. Could you share your code so I can try to help (link to repo would work too) – jacoboneill2000 Oct 07 '22 at 17:29
  • All good. Thank you! Here's the script (lib is `../lib` relative to `scripts/`) https://github.com/sparks-baird/self-driving-lab-demo/blob/main/src/public_mqtt_sdl_demo/scripts/ov2640_basic.py – Sterling Oct 07 '22 at 18:41
  • 1
    So looking at the repo it looks like you have imported the cameras C++ library over to micropython? I couldn't find a micropython library for this however I think this is possible. Either way this is unfortunately out of my range and a thing I find very annoying with suppliers for arduino parts not supporting micropython. – jacoboneill2000 Oct 08 '22 at 16:26
  • 1
    As well as this, as you said, despite the manafacturer saying that pull up resistors where built-in I added my own as a hail mary and of course it worked. I used 4.7kOhm between the VCC, SDA and SCL lines. https://imgur.com/a/WcXnyO3 – jacoboneill2000 Oct 08 '22 at 16:42
  • There's [an officially supported C/CircuitPython library for this](https://github.com/ArduCAM/PICO_SPI_CAM), but no official MicroPython library. The unofficial implementation I was using (needed some modifications for Pico W / RP2040) is https://github.com/namato/micropython-ov2640. I should probably order a Pico H and an ESP32 microcontroller so I can do some more effective troubleshooting. I should probably give the pull-up resistors a try. Thanks for the diagram! :) – Sterling Oct 08 '22 at 17:35
  • It turns out I needed to replace the ribbon cable. Someone else [mentioned receiving a broken cable](https://forum.arducam.com/t/arducam-mini-2mp-bare-minimum-init-process-needed-for-2mp-jpeg-micropython/918), so it seems likely the ribbon cable I received was defective before I began using it. Wasted a lot of time that way. I got it working using CircuitPython, but had trouble with MicroPython variants. According to the post above, even if I got the MicroPython variant working, it would take ~45s to grab a 320x240 image. Unreasonably slow for my application. – Sterling Nov 03 '22 at 02:22
  • 1
    Hey @Sterling I'm glad you solved your problem and yes, ~45s for a low res photo is ridiculous for most applications. I've never dabbled with CircuitPython, will have to do some research if this can help my applications too. – jacoboneill2000 Nov 05 '22 at 13:59