diff --git a/examples/pico_ov5640_simpletest.py b/examples/pico_ov5640_simpletest.py new file mode 100644 index 0000000..e7b9eba --- /dev/null +++ b/examples/pico_ov5640_simpletest.py @@ -0,0 +1,144 @@ +import sys +import time +import busio +import board +import digitalio +import adafruit_ov5640 + +print("construct bus") +bus = busio.I2C(board.GP9, board.GP8) +print("construct camera") +reset = digitalio.DigitalInOut(board.GP10) +cam = adafruit_ov5640.OV5640( + bus, + data_pins=(board.GP12,board.GP13,board.GP14,board.GP15,board.GP16,board.GP17,board.GP18,board.GP19), # [16] [org] + clock=board.GP11, # [15] [blk] + vsync=board.GP7, # [10] [brn] + href=board.GP21, # [27/o14] [red] + mclk=board.GP20, # [16/o15] + shutdown=None, + reset=reset, + size=adafruit_ov5640.OV5640_SIZE_QQVGA, +) +print("print chip id") +print(cam.chip_id) + + +cam.colorspace = adafruit_ov5640.OV5640_COLOR_YUV +cam.flip_y = True +cam.flip_x = True +cam.test_pattern = False + +buf = bytearray(cam.capture_buffer_size) +chars = b" .':-+=*%$#" +remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)] + +width = cam.width +row = bytearray(width) + +print("capturing") +cam.capture(buf) +print("capture complete") + +sys.stdout.write("\033[2J") +while True: + cam.capture(buf) + for j in range(0, cam.height, 2): + sys.stdout.write(f"\033[{j//2}H") + for i in range(cam.width): + row[i] = remap[buf[2 * (width * j + i)]] + sys.stdout.write(row) + sys.stdout.write("\033[K") + sys.stdout.write("\033[J") + time.sleep(0.1) + + +import time +from adafruit_ov7670 import ( + OV7670, + OV7670_SIZE_DIV1, + OV7670_SIZE_DIV16, + OV7670_TEST_PATTERN_COLOR_BAR, + OV7670_TEST_PATTERN_SHIFTING_1, + OV7670_TEST_PATTERN_COLOR_BAR_FADE, +) +from displayio import ( + Bitmap, + Group, + TileGrid, + FourWire, + release_displays, + ColorConverter, + Colorspace, +) +from adafruit_st7789 import ST7789 +import board +import busio +import digitalio + +# Set up the display (You must customize this block for your display!) +release_displays() +spi = busio.SPI(clock=board.GP2, MOSI=board.GP3) +display_bus = FourWire(spi, command=board.GP0, chip_select=board.GP1, reset=None) +display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=270) + + +# Ensure the camera is shut down, so that it releases the SDA/SCL lines, +# then create the configuration I2C bus + +with digitalio.DigitalInOut(board.GP10) as reset: + reset.switch_to_output(False) + time.sleep(0.001) + bus = busio.I2C(board.GP9, board.GP8) + +# Set up the camera (you must customize this for your board!) +cam = OV7670( + bus, + data0=board.GP12, # [16] [org] + clock=board.GP11, # [15] [blk] + vsync=board.GP7, # [10] [brn] + href=board.GP21, # [27/o14] [red] + mclk=board.GP20, # [16/o15] + shutdown=None, + reset=board.GP10, +) # [14] + +width = display.width +height = display.height + +#cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE +bitmap = None +# Select the biggest size for which we can allocate a bitmap successfully, and +# which is not bigger than the display +for size in range(OV7670_SIZE_DIV1, OV7670_SIZE_DIV16 + 1): + cam.size = size + if cam.width > width: + continue + if cam.height > height: + continue + try: + bitmap = Bitmap(cam.width, cam.height, 65535) + break + except MemoryError: + continue + +print(width, height, cam.width, cam.height) +if bitmap is None: + raise SystemExit("Could not allocate a bitmap") + +g = Group(scale=1, x=(width-cam.width)//2, y=(height-cam.height)//2) +tg = TileGrid( + bitmap, pixel_shader=ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED) +) +g.append(tg) +display.show(g) + +t0 = time.monotonic_ns() +display.auto_refresh = False +while True: + cam.capture(bitmap) + bitmap.dirty() + display.refresh(minimum_frames_per_second=0) + t1 = time.monotonic_ns() + print("fps", 1e9 / (t1 - t0)) + t0 = t1