Adafruit_Learning_System_Gu.../CircuitPython_ESP32_Camera/esp32-s3-eye-qrio-repl/code.py
Jeff Epler d6fafcb2d0
Correct references to "esp32_camera"
This was renamed during the development of 8.x but examples weren't
fixed.
2024-01-15 14:43:18 -06:00

54 lines
1.5 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2022 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
This demo is designed for the Kaluga development kit version 1.3 with the
ILI9341 display.
"""
import struct
import board
import espcamera
import qrio
print("Initializing camera")
cam = espcamera.Camera(
data_pins=board.CAMERA_DATA,
external_clock_pin=board.CAMERA_XCLK,
pixel_clock_pin=board.CAMERA_PCLK,
vsync_pin=board.CAMERA_VSYNC,
href_pin=board.CAMERA_HREF,
pixel_format=espcamera.PixelFormat.RGB565,
frame_size=espcamera.FrameSize.R240X240,
i2c=board.I2C(),
external_clock_frequency=20_000_000,
framebuffer_count=2)
cam.vflip = True
cam.hmirror = True
board.DISPLAY.auto_refresh = False
display_bus = board.DISPLAY.bus
print(cam.width, cam.height)
qrdecoder = qrio.QRDecoder(cam.width, cam.height)
print(qrdecoder.width, qrdecoder.height)
#raise SystemExit
ow = (board.DISPLAY.width - cam.width) // 2
oh = (board.DISPLAY.height - cam.height) // 2
display_bus.send(42, struct.pack(">hh", ow, cam.width + ow - 1))
display_bus.send(43, struct.pack(">hh", oh, cam.height + ow - 1))
while True:
frame = cam.take(1)
display_bus.send(44, frame)
for row in qrdecoder.decode(frame, qrio.PixelPolicy.RGB565_SWAPPED):
payload = row.payload
try:
payload = payload.decode("utf-8")
except UnicodeError:
payload = str(payload)
print(payload)
print(end=".")