|
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 |
7 | 4 |
|
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. |
54 | 7 |
|
| 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. |
55 | 11 |
|
| 12 | +Remember to take the lens cap off! |
| 13 | +""" |
56 | 14 | 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 |
65 | 16 | from displayio import (
|
66 | 17 | Bitmap,
|
67 | 18 | Group,
|
|
106 | 57 | width = display.width
|
107 | 58 | height = display.height
|
108 | 59 |
|
109 |
| -#cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE |
| 60 | +# cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE |
110 | 61 | bitmap = None
|
111 | 62 | # Select the biggest size for which we can allocate a bitmap successfully, and
|
112 | 63 | # which is not bigger than the display
|
|
126 | 77 | if bitmap is None:
|
127 | 78 | raise SystemExit("Could not allocate a bitmap")
|
128 | 79 |
|
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) |
130 | 81 | tg = TileGrid(
|
131 | 82 | bitmap, pixel_shader=ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)
|
132 | 83 | )
|
|
0 commit comments