Skip to content

Commit 07292b9

Browse files
committed
split pico examples to their own files and pylint fixes. Rename to library prepended name.
1 parent 5e82048 commit 07292b9

File tree

2 files changed

+94
-62
lines changed

2 files changed

+94
-62
lines changed

examples/ov5640_pico_simpletest.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Lady Ada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
"""Capture an image from the camera and display it as ASCII art.
6+
7+
This demo is designed to run on the Raspberry Pi Pico, but you can adapt it
8+
to other boards by changing the constructors for `bus` and `cam`
9+
appropriately.
10+
11+
The camera is placed in YUV mode, so the top 8 bits of each color
12+
value can be treated as "greyscale".
13+
14+
It's important that you use a terminal program that can interpret
15+
"ANSI" escape sequences. The demo uses them to "paint" each frame
16+
on top of the previous one, rather than scrolling.
17+
18+
Remember to take the lens cap off!
19+
"""
20+
import sys
21+
import time
22+
import busio
23+
import board
24+
import digitalio
25+
import adafruit_ov5640
26+
27+
print("construct bus")
28+
bus = busio.I2C(board.GP9, board.GP8)
29+
print("construct camera")
30+
reset = digitalio.DigitalInOut(board.GP10)
31+
cam = adafruit_ov5640.OV5640(
32+
bus,
33+
data_pins=(
34+
board.GP12,
35+
board.GP13,
36+
board.GP14,
37+
board.GP15,
38+
board.GP16,
39+
board.GP17,
40+
board.GP18,
41+
board.GP19,
42+
), # [16] [org]
43+
clock=board.GP11, # [15] [blk]
44+
vsync=board.GP7, # [10] [brn]
45+
href=board.GP21, # [27/o14] [red]
46+
mclk=board.GP20, # [16/o15]
47+
shutdown=None,
48+
reset=reset,
49+
size=adafruit_ov5640.OV5640_SIZE_QQVGA,
50+
)
51+
print("print chip id")
52+
print(cam.chip_id)
53+
54+
55+
cam.colorspace = adafruit_ov5640.OV5640_COLOR_YUV
56+
cam.flip_y = True
57+
cam.flip_x = True
58+
cam.test_pattern = False
59+
60+
buf = bytearray(cam.capture_buffer_size)
61+
chars = b" .':-+=*%$#"
62+
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
63+
64+
width = cam.width
65+
row = bytearray(width)
66+
67+
print("capturing")
68+
cam.capture(buf)
69+
print("capture complete")
70+
71+
sys.stdout.write("\033[2J")
72+
while True:
73+
cam.capture(buf)
74+
for j in range(0, cam.height, 2):
75+
sys.stdout.write(f"\033[{j//2}H")
76+
for i in range(cam.width):
77+
row[i] = remap[buf[2 * (width * j + i)]]
78+
sys.stdout.write(row)
79+
sys.stdout.write("\033[K")
80+
sys.stdout.write("\033[J")
81+
time.sleep(0.1)

examples/pico_ov5640_simpletest.py renamed to examples/ov5640_pico_st7789.py

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,18 @@
1-
import sys
2-
import time
3-
import busio
4-
import board
5-
import digitalio
6-
import adafruit_ov5640
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Lady Ada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
74

8-
print("construct bus")
9-
bus = busio.I2C(board.GP9, board.GP8)
10-
print("construct camera")
11-
reset = digitalio.DigitalInOut(board.GP10)
12-
cam = adafruit_ov5640.OV5640(
13-
bus,
14-
data_pins=(board.GP12,board.GP13,board.GP14,board.GP15,board.GP16,board.GP17,board.GP18,board.GP19), # [16] [org]
15-
clock=board.GP11, # [15] [blk]
16-
vsync=board.GP7, # [10] [brn]
17-
href=board.GP21, # [27/o14] [red]
18-
mclk=board.GP20, # [16/o15]
19-
shutdown=None,
20-
reset=reset,
21-
size=adafruit_ov5640.OV5640_SIZE_QQVGA,
22-
)
23-
print("print chip id")
24-
print(cam.chip_id)
25-
26-
27-
cam.colorspace = adafruit_ov5640.OV5640_COLOR_YUV
28-
cam.flip_y = True
29-
cam.flip_x = True
30-
cam.test_pattern = False
31-
32-
buf = bytearray(cam.capture_buffer_size)
33-
chars = b" .':-+=*%$#"
34-
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
35-
36-
width = cam.width
37-
row = bytearray(width)
38-
39-
print("capturing")
40-
cam.capture(buf)
41-
print("capture complete")
42-
43-
sys.stdout.write("\033[2J")
44-
while True:
45-
cam.capture(buf)
46-
for j in range(0, cam.height, 2):
47-
sys.stdout.write(f"\033[{j//2}H")
48-
for i in range(cam.width):
49-
row[i] = remap[buf[2 * (width * j + i)]]
50-
sys.stdout.write(row)
51-
sys.stdout.write("\033[K")
52-
sys.stdout.write("\033[J")
53-
time.sleep(0.1)
5+
"""Capture an images from the camera and display on a ST7789 with
6+
displayio.
547
8+
This demo is designed to run on the Raspberry Pi Pico, but you can adapt it
9+
to other boards by changing the constructors for `bus` and `cam`
10+
appropriately.
5511
12+
Remember to take the lens cap off!
13+
"""
5614
import time
57-
from adafruit_ov7670 import (
58-
OV7670,
59-
OV7670_SIZE_DIV1,
60-
OV7670_SIZE_DIV16,
61-
OV7670_TEST_PATTERN_COLOR_BAR,
62-
OV7670_TEST_PATTERN_SHIFTING_1,
63-
OV7670_TEST_PATTERN_COLOR_BAR_FADE,
64-
)
15+
from adafruit_ov7670 import OV7670, OV7670_SIZE_DIV1, OV7670_SIZE_DIV16
6516
from displayio import (
6617
Bitmap,
6718
Group,
@@ -106,7 +57,7 @@
10657
width = display.width
10758
height = display.height
10859

109-
#cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE
60+
# cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE
11061
bitmap = None
11162
# Select the biggest size for which we can allocate a bitmap successfully, and
11263
# which is not bigger than the display
@@ -126,7 +77,7 @@
12677
if bitmap is None:
12778
raise SystemExit("Could not allocate a bitmap")
12879

129-
g = Group(scale=1, x=(width-cam.width)//2, y=(height-cam.height)//2)
80+
g = Group(scale=1, x=(width - cam.width) // 2, y=(height - cam.height) // 2)
13081
tg = TileGrid(
13182
bitmap, pixel_shader=ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)
13283
)

0 commit comments

Comments
 (0)