YD-ESP32-S3-EYE/CircuitPython 8, control LCD and Camera.

With CircuitPython 8.2.8 installed on YD-ESP32-S3-EYE,  Here are exercises to access LCD and camera on YD-ESP32-S3-EYE.

Exercise to test LCD/Color on LCD, cpyS3EYE_LCD_color.py.
"""
LCD/Color test on
YD-ESP32-S3-EYE/CircuitPython 8.2.8
"""
import os, sys
import board
import time
import displayio
import terminalio
from adafruit_display_text import label

display = board.DISPLAY

#=======================================
info = os.uname()[4] + "\n" + \
       sys.implementation[0] + " " + os.uname()[3] + "\n" + \
       "board.DISPLAY: " + str(display.width) + "x" + str(display.height)
print("=======================================")
print(info)
print("=======================================")
print()

# Make the display context
bgGroup = displayio.Group()
display.show(bgGroup)

bg_bitmap = displayio.Bitmap(display.width, display.height, 1)  # with one color
bg_palette = displayio.Palette(1)
bg_palette[0] = 0xFFFFFF  # White
bg_sprite = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette, x=0, y=0)
bgGroup.append(bg_sprite)

colorSet = ((0xFF0000, "RED"),
            (0x00FF00, "GREEN"),
            (0x0000FF, "BLUE"),
            (0xFFFFFF, "WHITE"),
            (0x000000, "BLACK"))

color_bitmap = displayio.Bitmap(display.width-2, display.height-2, 1)  # with one color
color_palette = displayio.Palette(1)
color_palette[0] = 0x000000  # BLACK
color_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=1, y=1)
bgGroup.append(color_sprite)

# Draw label
text_group = displayio.Group(scale=1, x=20, y=120)
text = "Hello\n" + os.uname()[4]
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF)
text_group.append(text_area)  # Subgroup for text scaling
bgGroup.append(text_group)

time.sleep(2)
text_group.scale = 2
time.sleep(2)
text_group.scale = 3

while True:
    for i in colorSet:
        time.sleep(2)
        color_palette[0] = i[0]
        text_area.text = i[1]
        text_area.color = i[0] ^ 0xFFFFFF
        




Exercise to read from OV2640 camera and display on LCD, using espcamera. espcamera is a wrapper for the espcamera library. 

cpS3EYE_espcamera_displayio.py
"""
Exercise of espcamera run on
YD-ESP32-S3-EYE/CircuitPython 8.2.8
with:
cam:     OV2640
display: 240x240

ref:
https://docs.circuitpython.org/en/8.2.x/shared-bindings/espcamera
"""
import os, sys

import board
import busio
import espcamera

from displayio import (
    Bitmap,
    Group,
    TileGrid,
    ColorConverter,
    Colorspace,
)

display = board.DISPLAY

info = os.uname()[4] + "\n" + \
       sys.implementation[0] + " " + os.uname()[3] + "\n" + \
       "board.DISPLAY: " + str(display.width) + "x" + str(display.height)
print("=======================================")
print(info)
print("=======================================")
print()

i2c = busio.I2C(scl=board.SCL, sda=board.SDA)
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=i2c,
    framebuffer_count=2)

bitmap = Bitmap(cam.width, cam.height, 65536)
if bitmap is None:
    raise SystemExit("Could not allocate a bitmap")

#cam.colorbar = True
#cam.special_effect = 0
#0 - No Effect
#1 - Negative
#2 - Grayscale
#3 - Red Tint
#4 - Green Tint
#5 - Blue Tint
#6 - Sepia
cam.vflip = True

print()
print("pixel_format:\t", cam.pixel_format)
print("frame_size:\t", cam.frame_size)
print("contrast:\t", cam.contrast)
print("brightness:\t", cam.brightness)
print("saturation:\t", cam.saturation)
print("sharpness:\t", cam.sharpness)
print("denoise:\t", cam.denoise)
print("gain_ceiling:\t", cam.gain_ceiling)
print("quality:\t", cam.quality)
print("whitebal:\t", cam.whitebal)
print("gain_ctrl:\t", cam.gain_ctrl)
print("exposure_ctrl:\t", cam.exposure_ctrl)
print("hmirror:\t", cam.hmirror)
print("vflip:\t\t", cam.vflip)
print("aec2:\t\t", cam.aec2)
print("awb_gain:\t", cam.awb_gain)
print("agc_gain:\t", cam.agc_gain)
print("aec_value:\t", cam.aec_value)
print("special_effect:\t", cam.special_effect)
print("wb_mode:\t", cam.wb_mode)
print("ae_level:\t", cam.ae_level)
print("dcw:\t\t", cam.dcw)
print("bpc:\t\t", cam.bpc)
print("wpc:\t\t", cam.wpc)
print("raw_gma:\t", cam.raw_gma)
print("lenc:\t\t", cam.lenc)
print("max_frame_size:\t", cam.max_frame_size)
print("address:\t", hex(cam.address))
print("sensor_name:\t", cam.sensor_name)
print("supports_jpeg:\t", cam.supports_jpeg)
print("height:\t\t", cam.height);
print("width:\t\t", cam.width)
print("grab_mode:\t", cam.grab_mode)
print("framebuffer_count:\t", cam.framebuffer_count)

g = Group(scale=1, x=(display.width - cam.width) // 2, y=(display.height - cam.height) // 2)

#colorspace = Colorspace.BGR555
#colorspace = Colorspace.BGR555_SWAPPED
#colorspace = Colorspace.RGB565
#colorspace = Colorspace.BGR565_SWAPPED
#colorspace = Colorspace.L8
#colorspace = Colorspace.RGB555
#colorspace = Colorspace.RGB555_SWAPPED
#colorspace = Colorspace.RGB565
colorspace = Colorspace.RGB565_SWAPPED
#colorspace = Colorspace.RGB888

tg = TileGrid(
    bitmap,
    pixel_shader=ColorConverter(input_colorspace=colorspace)
)

g.append(tg)
display.show(g)

display.auto_refresh = True
while True:
    if cam.frame_available:
        tg.bitmap = cam.take()




Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.