Skip to content

Instantly share code, notes, and snippets.

@jepler
Created August 5, 2022 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepler/e0b1aaae941cc3ab967b24d2dab1c0b6 to your computer and use it in GitHub Desktop.
Save jepler/e0b1aaae941cc3ab967b24d2dab1c0b6 to your computer and use it in GitHub Desktop.
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Take a 10-frame stop motion GIF image.
This example requires:
* `Espressif Kaluga v1.3 <https://www.adafruit.com/product/4729>`_ with compatible LCD display
* `MicroSD card breakout board + <https://www.adafruit.com/product/254>`_ connected as follows:
* CLK to board.IO18
* DI to board.IO14
* DO to board.IO17
* CS to IO12
* GND to GND
* 5V to 5V
* A compatible SD card inserted in the SD card slot
* A compatible camera module (such as OV5640) connected to the camera header
To use:
Insert an SD card and power on.
Set up the first frame using the viewfinder. Click the REC button to take a frame.
Set up the next frame using the viewfinder. The previous and current frames are blended together on the display, which is called an "onionskin". Click the REC button to take the next frame.
After 10 frames are recorded, the GIF is complete and you can begin recording another.
About the Kaluga development kit:
The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is
tested on v1.3.
The audio board must be mounted between the Kaluga and the LCD, it provides the
I2C pull-ups(!)
The v1.3 development kit's LCD can have one of two chips, the ili9341 or
st7789. Furthermore, there are at least 2 ILI9341 variants, which differ
by rotation. This example is written for one if the ILI9341 variants,
the one which usually uses rotation=90 to get a landscape display.
"""
import os
import struct
import time
import adafruit_ticks
import esp32_camera
import analogio
import board
import busio
import bitmaptools
import digitalio
import displayio
from adafruit_st7789 import ST7789
cam = esp32_camera.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=esp32_camera.PixelFormat.RGB565,
frame_size=esp32_camera.FrameSize.R240X240,
i2c=board.I2C(),
external_clock_frequency=20_000_000,
grab_mode=esp32_camera.GrabMode.WHEN_EMPTY)
cam.vflip = True
board.DISPLAY.auto_refresh = False
display_bus = board.DISPLAY.bus
display_bus.send(36, struct.pack(">hh", 0, 239))
display_bus.send(42, struct.pack(">hh", 0, 239))
display_bus.send(43, struct.pack(">hh", 0, 80+239))
t0 = adafruit_ticks.ticks_ms()
while True:
frame = cam.take(1)
if isinstance(frame, displayio.Bitmap):
display_bus.send(44, frame)
t1 = adafruit_ticks.ticks_ms()
fps = 1000 / (t1-t0)
print(f"{fps:3.1f}fps")
t0 = t1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment