Skip to content

Commit 6546574

Browse files
committed
Add example for Kaluga
1 parent cce85fa commit 6546574

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is
8+
tested on v1.3. It probably won't work on v1.2 without modification.
9+
10+
The v1.3 development kit's LCD can have one of two chips, the ili9341 or
11+
st7789. Furthermore, there are at least 2 ILI9341 variants, one of which needs
12+
rotation=90! This demo is for the ili9341. If the display is garbled, try adding
13+
rotation=90, or try modifying it to use ST7799.
14+
15+
The camera included with the Kaluga development kit is the incompatible OV2640,
16+
it won't work.
17+
18+
The audio board must be mounted between the Kaluga and the LCD, it provides the
19+
I2C pull-ups(!)
20+
"""
21+
22+
import time
23+
import board
24+
import busio
25+
import displayio
26+
from adafruit_ili9341 import ILI9341
27+
from adafruit_ov7670 import ( # pylint: disable=unused-import
28+
OV7670,
29+
OV7670_TEST_PATTERN_COLOR_BAR,
30+
OV7670_SIZE_DIV2,
31+
OV7670_NIGHT_MODE_2,
32+
)
33+
34+
# Pylint is unable to see that the "size" property of OV7670_GrandCentral exists
35+
# pylint: disable=attribute-defined-outside-init
36+
37+
# Release any resources currently in use for the displays
38+
displayio.release_displays()
39+
40+
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
41+
display_bus = displayio.FourWire(
42+
spi, command=board.LCD_D_C, chip_select=board.LCD_CS, reset=board.LCD_RST
43+
)
44+
display = ILI9341(display_bus, width=320, height=240)
45+
46+
bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
47+
cam = OV7670(
48+
bus,
49+
data_pins=board.CAMERA_DATA,
50+
clock=board.CAMERA_PCLK,
51+
vsync=board.CAMERA_VSYNC,
52+
href=board.CAMERA_HREF,
53+
mclk=board.CAMERA_XCLK,
54+
mclk_frequency=20_000_000,
55+
)
56+
57+
cam.size = OV7670_SIZE_DIV2
58+
cam.flip_x = False
59+
cam.flip_y = True
60+
pid = cam.product_id
61+
ver = cam.product_version
62+
print(f"Detected pid={pid:x} ver={ver:x}")
63+
# cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR
64+
65+
g = displayio.Group(scale=1)
66+
bitmap = displayio.Bitmap(320, 240, 65536)
67+
tg = displayio.TileGrid(
68+
bitmap,
69+
pixel_shader=displayio.ColorConverter(
70+
input_colorspace=displayio.Colorspace.RGB565_SWAPPED
71+
),
72+
)
73+
g.append(tg)
74+
display.show(g)
75+
76+
t0 = time.monotonic_ns()
77+
display.auto_refresh = False
78+
while True:
79+
cam.capture(bitmap)
80+
bitmap.dirty()
81+
display.refresh(minimum_frames_per_second=0)
82+
t1 = time.monotonic_ns()
83+
print("fps", 1e9 / (t1 - t0))
84+
t0 = t1
85+
86+
cam.deinit()

0 commit comments

Comments
 (0)