0

I'm building my hobby project (not business or educations) using a Raspberry Pi Pico and an ov7670 camera. I want to take one photo and save its code to txt file. In order to take it, I use the library https://github.com/adafruit/Adafruit_CircuitPython_OV7670

I wrote my code.py file in circuitpython, and in the lib folder I put the adafruit_ov7670.py file. I don't see the file, what am I doing wrong?

import board
from adafruit_ov7670 import OV7670
import time
import digitalio

cam = OV7670(
    bus,
    data_pins=[board.PCC_D0, board.PCC_D1, board.PCC_D2, board.PCC_D3, board.PCC_D4, board.PCC_D5, board.PCC_D6, board.PCC_D7],
    clock=board.PCC_CLK,
    vsync=board.PCC_DEN1,
    href=board.PCC_DEN2,
    mclk=board.D29,
    shutdown=board.D39,
    reset=board.D38,
)
cam.size = OV7670_SIZE_DIV16

buf = bytearray(2 * cam.width * cam.height)

try:
    with open("/photobin.txt", "a") as photo:
        while True:
            temp = cam.capture(buf)
            photo.write(temp)
            photo.flush()
            time.sleep(1)
except OSError as e:
    print("error")

`

Anton9101
  • 11
  • 3

1 Answers1

0

I am not familiar with that library, or camera, but as you are creating a buffer of 2 * w * h bytes, I assume you are trying to acquire RGB565 (i.e. 16-bit) data. So I assume the data is binary, rather than ASCII, so I would suggest you use the following to open a binary file:

with open("photobin.txt", "wb") as photo:

I have also removed the leading slash, so the file gets written in the current working directory where you appear to be expecting to find it.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432