Skip to content

Commit 52852b9

Browse files
committed
add lcd viewfinder example
1 parent 0345780 commit 52852b9

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

  • circuitpython-esp32-camera/esp32-s3-eye-lcdview
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: Unlicense
5+
6+
"""
7+
Use the built-in LCD as a viewfinder for the camera
8+
9+
This example requires:
10+
* ESP32-S3-EYE development kit from Espressif
11+
12+
To use:
13+
14+
Copy the project bundle to CIRCUITPY.
15+
"""
16+
17+
import os
18+
import struct
19+
import time
20+
21+
import adafruit_ticks
22+
import esp32_camera
23+
import board
24+
import displayio
25+
from adafruit_st7789 import ST7789
26+
27+
cam = esp32_camera.Camera(
28+
data_pins=board.CAMERA_DATA,
29+
external_clock_pin=board.CAMERA_XCLK,
30+
pixel_clock_pin=board.CAMERA_PCLK,
31+
vsync_pin=board.CAMERA_VSYNC,
32+
href_pin=board.CAMERA_HREF,
33+
pixel_format=esp32_camera.PixelFormat.RGB565,
34+
frame_size=esp32_camera.FrameSize.R240X240,
35+
i2c=board.I2C(),
36+
external_clock_frequency=20_000_000,
37+
framebuffer_count=2,
38+
grab_mode=esp32_camera.GrabMode.WHEN_EMPTY)
39+
40+
cam.vflip = True
41+
42+
board.DISPLAY.auto_refresh = False
43+
display_bus = board.DISPLAY.bus
44+
45+
display_bus.send(36, struct.pack(">hh", 0, 239))
46+
display_bus.send(42, struct.pack(">hh", 0, 239))
47+
display_bus.send(43, struct.pack(">hh", 0, 80+239))
48+
t0 = adafruit_ticks.ticks_ms()
49+
while True:
50+
frame = cam.take(1)
51+
if isinstance(frame, displayio.Bitmap):
52+
display_bus.send(44, frame)
53+
t1 = adafruit_ticks.ticks_ms()
54+
fps = 1000 / adafruit_ticks.ticks_diff(t1, t0)
55+
print(f"{fps:3.1f}fps") # typically runs at about 25fps
56+
t0 = t1

0 commit comments

Comments
 (0)