namato / micropython-ov2640

A MicroPython class for the ov2640 camera.
MIT License
112 stars 25 forks source link

Is this compatible with the Pico W? #6

Open sgbaird opened 2 years ago

sgbaird commented 2 years ago

I'm interested in using the Pico W in an IoT-style with a low framerate video and various sensors. I'm thinking about using the CircuitPython PICO_SPI_CAM https://github.com/ArduCAM/PICO_SPI_CAM/issues/8 with Blinka as a compatibility layer so I can still use MicroPython, or doing a rewrite of my code to switch back to using CircuitPython (since there is now limited WiFi support on the Pico W).

sgbaird commented 2 years ago

This repo isn't compatible with the Pico W in its current form. It's also not maintained (obvious from the user profile and the last commit 5 years ago).

image

What happens is no addresses are found during i2c.scan() (addrs == []), followed by:

Traceback (most recent call last):
  File "<stdin>", line 41, in <module>
  File "<stdin>", line 21, in main
  File "/lib/ov2640/esp8266_ov2640.py", line 36, in __init__
OSError: [Errno 5] EIO

I also tried the PR here for the ESP-32: https://github.com/namato/micropython-ov2640/pull/4

The code hangs instead of producing EIO. I stopped the code after about a minute (note that this was using the 320x240 setting).

This was also after ensuring the proper Pico W pins were being used and changing the SPI IDs to match. I used the wiring described in the ArduCam docs.

sgbaird commented 2 years ago

polarity=1, phase=1 https://github.com/Xraydylan/Arducam-OV2640-Pico-Package/issues/3#issuecomment-1270403365

sgbaird commented 2 years ago

Swapped the Pico W out with a Pico and got the same error:

>>> %Run -c $EDITOR_CONTENT
initializing camera
[48]
i2c device found at address: 48
writing to memory
Traceback (most recent call last):
  File "<stdin>", line 43, in <module>
  File "<stdin>", line 23, in main
  File "/lib/ov2640/ov2640.py", line 63, in __init__
OSError: [Errno 5] EIO
tbbuck commented 1 year ago

Taking my first baby steps with microcontrollers and this camera - please take anything I say with a large grain of salt :)

Plugging into my Pico W, I've just taken my first photo using this library by configuring with these settings:

self.hspi = machine.SPI(0, baudrate=80000000, polarity=0, phase=0, sck=machine.Pin("GP2"), mosi=machine.Pin("GP3"), miso=machine.Pin("GP4"))
self.i2c = machine.I2C(0, scl=machine.Pin("GP9"), sda=machine.Pin("GP8"), freq=1000000)

I've connected the pins according to the suggestion here: https://www.uctronics.com/download/Amazon/B0067-B0068-Pico.pdf

The basics main.py I'm using is:

import time
import ov2640
import gc
import sys

FNAME = 'image2.jpg'

try:
    print("initializing camera")
    cam = ov2640.ov2640()

    clen = cam.capture_to_file(FNAME, True)
    print("captured image is %d bytes" % clen)
    print("image is saved to %s" % FNAME)

    time.sleep(10)
    sys.exit(0)

except KeyboardInterrupt:
    print("exiting...")
    sys.exit(0)
sgbaird commented 1 year ago

@tbbuck, thanks for sharing! I might give this a try.