Skip to content

Commit 2db00ad

Browse files
authored
Merge pull request #11 from adafruit/enhance
Enhance
2 parents 51cf2d7 + cc5eb83 commit 2db00ad

12 files changed

+571
-37
lines changed

adafruit_ov2640.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,3 +1334,22 @@ def _set_window(
13341334
# Reestablish test pattern
13351335
if self._test_pattern:
13361336
self.test_pattern = self._test_pattern
1337+
1338+
@property
1339+
def exposure(self):
1340+
"""The exposure level of the sensor"""
1341+
aec_9_2 = self._get_reg_bits(_BANK_SENSOR, _AEC, 0, 0xFF)
1342+
aec_15_10 = self._get_reg_bits(_BANK_SENSOR, _REG45, 0, 0b111111)
1343+
aec_1_0 = self._get_reg_bits(_BANK_SENSOR, _REG04, 0, 0b11)
1344+
1345+
return aec_1_0 | (aec_9_2 << 2) | (aec_15_10 << 10)
1346+
1347+
@exposure.setter
1348+
def exposure(self, exposure):
1349+
aec_1_0 = exposure & 0x11
1350+
aec_9_2 = (exposure >> 2) & 0b11111111
1351+
aec_15_10 = exposure >> 10
1352+
1353+
self._set_reg_bits(_BANK_SENSOR, _AEC, 0, 0xFF, aec_9_2)
1354+
self._set_reg_bits(_BANK_SENSOR, _REG45, 0, 0b111111, aec_15_10)
1355+
self._set_reg_bits(_BANK_SENSOR, _REG04, 0, 0b11, aec_1_0)

docs/examples.rst

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,93 @@ Simple test
44
Ensure your device works with this simple test.
55

66
.. literalinclude:: ../examples/ov2640_simpletest.py
7-
:caption: examples/ov2640_simpletest.py
7+
:caption: ov2640_simpletest.py
88
:linenos:
99

10+
11+
LCD tests
12+
---------
13+
14+
Kaluga 1.3 with ili9341
15+
~~~~~~~~~~~~~~~~~~~~~~~
16+
1017
Display an image from the camera on the Kaluga 1.3 board, if it is fitted with an ili9341 display.
1118

1219
.. literalinclude:: ../examples/ov2640_displayio_kaluga1_3_ili9341.py
13-
:caption: ../examples/ov2640_displayio_kaluga1_3_ili9341.py
20+
:caption: ov2640_displayio_kaluga1_3_ili9341.py
1421
:linenos:
1522

23+
Kaluga 1.3 with st7789
24+
~~~~~~~~~~~~~~~~~~~~~~
25+
1626
Display an image from the camera on the Kaluga 1.3 board, if it is fitted with an st7789 display.
1727

1828
.. literalinclude:: ../examples/ov2640_displayio_kaluga1_3_st7789.py
19-
:caption: ../examples/ov2640_displayio_kaluga1_3_st7789.py
29+
:caption: ov2640_displayio_kaluga1_3_st7789.py
2030
:linenos:
2131

32+
Raspberry Pi Pico with st7789
33+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
2235
Display an image from the camera connected to a Raspberry Pi Pico with an st7789 2" display
2336

2437
.. literalinclude:: ../examples/ov2640_displayio_pico_st7789_2in.py
25-
:caption: ../examples/ov2640_displayio_pico_st7789_2in.py
38+
:caption: ov2640_displayio_pico_st7789_2in.py
2639
:linenos:
2740

28-
Save an image to internal flash on Kaluga 1.3
41+
Kaluga 1.3 with ili9341, direct display
42+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
44+
Preview images on LCD, bypassing displayio for slightly higher framerate
45+
46+
.. literalinclude:: ../examples/ov2640_directio_kaluga1_3_ili9341.py
47+
:caption: ../examples/ov2640_directio_kaluga1_3_ili9341.py
48+
:linenos:
49+
50+
51+
Image-saving tests
52+
------------------
53+
54+
Kaluga 1.3 with ili9341, internal flash, JPEG
55+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56+
57+
Preview images on LCD t hen save JPEG images to internal flash on Kaluga 1.3. Requires the second snippet of
58+
code to be saved as ``boot.py``.
2959

3060
.. literalinclude:: ../examples/ov2640_jpeg_kaluga1_3.py
31-
:caption: ../examples/ov2640_jpeg_kaluga1_3.py
61+
:caption: ov2640_jpeg_kaluga1_3.py
3262
:linenos:
3363

3464
``boot.py`` for the above program
3565

3666
.. literalinclude:: ../examples/ov2640_jpeg_kaluga1_3_boot.py
37-
:caption: ../examples/ov2640_jpeg_kaluga1_3_boot.py
67+
:caption: ov2640_jpeg_kaluga1_3_boot.py
3868
:linenos:
3969

40-
Preview images on LCD then save to SD on Kaluga 1.3 fitted with an ili9341 display
70+
Kaluga 1.3 with ili9341, external SD card, JPEG
71+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
73+
Preview images on LCD then save JPEG images to SD on Kaluga 1.3 fitted with an ili9341 display.
4174

4275
.. literalinclude:: ../examples/ov2640_jpeg_sd_kaluga1_3.py
43-
:caption: ../examples/ov2640_jpeg_sd_kaluga1_3.py
76+
:caption: ov2640_jpeg_sd_kaluga1_3.py
77+
:linenos:
78+
79+
Kaluga 1.3 with ili9341, external SD card, BMP
80+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
82+
Preview images on LCD then save BMP images to SD on Kaluga 1.3 fitted with an ili9341 display.
83+
84+
.. literalinclude:: ../examples/ov2640_bmp_sd_kaluga1_3.py
85+
:caption: ov2640_bmp_sd_kaluga1_3.py
86+
:linenos:
87+
88+
89+
Kaluga 1.3 with Adafruit IO
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
Upload JPEG images to Adafruit IO. Requires that WIFI and Adafruit IO be configured in ``secrets.py``.
93+
94+
.. literalinclude:: ../examples/ov2640_aio_kaluga1_3.py
95+
:caption: ov2640_aio_kaluga1_3.py
4496
:linenos:

examples/ov2640_aio_kaluga1_3.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.
9+
10+
The audio board must be mounted between the Kaluga and the LCD, it provides the
11+
I2C pull-ups(!)
12+
13+
This example requires that your WIFI and Adafruit IO credentials be configured
14+
in CIRCUITPY/secrets.py, and that you have created a feed called "image" with
15+
history disabled.
16+
17+
The maximum image size is 100kB after base64 encoding, or about 65kB before
18+
base64 encoding. In practice, "SVGA" (800x600) images are typically around
19+
40kB even though the "capture_buffer_size" (theoretical maximum size) is
20+
(width*height/5) bytes or 96kB.
21+
"""
22+
23+
import binascii
24+
import ssl
25+
import time
26+
from secrets import secrets # pylint: disable=no-name-in-module
27+
28+
import board
29+
import busio
30+
import wifi
31+
import socketpool
32+
import adafruit_minimqtt.adafruit_minimqtt as MQTT
33+
from adafruit_io.adafruit_io import IO_MQTT
34+
import adafruit_ov2640
35+
36+
feed_name = "image"
37+
38+
print("Connecting to WIFI")
39+
wifi.radio.connect(secrets["ssid"], secrets["password"])
40+
pool = socketpool.SocketPool(wifi.radio)
41+
42+
print("Connecting to Adafruit IO")
43+
mqtt_client = MQTT.MQTT(
44+
broker="io.adafruit.com",
45+
username=secrets["aio_username"],
46+
password=secrets["aio_key"],
47+
socket_pool=pool,
48+
ssl_context=ssl.create_default_context(),
49+
)
50+
mqtt_client.connect()
51+
io = IO_MQTT(mqtt_client)
52+
53+
bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
54+
cam = adafruit_ov2640.OV2640(
55+
bus,
56+
data_pins=board.CAMERA_DATA,
57+
clock=board.CAMERA_PCLK,
58+
vsync=board.CAMERA_VSYNC,
59+
href=board.CAMERA_HREF,
60+
mclk=board.CAMERA_XCLK,
61+
mclk_frequency=20_000_000,
62+
size=adafruit_ov2640.OV2640_SIZE_QVGA,
63+
)
64+
65+
cam.flip_x = False
66+
cam.flip_y = False
67+
cam.test_pattern = False
68+
69+
cam.size = adafruit_ov2640.OV2640_SIZE_SVGA
70+
cam.colorspace = adafruit_ov2640.OV2640_COLOR_JPEG
71+
jpeg_buffer = bytearray(cam.capture_buffer_size)
72+
while True:
73+
jpeg = cam.capture(jpeg_buffer)
74+
print(f"Captured {len(jpeg)} bytes of jpeg data")
75+
76+
# b2a_base64() appends a trailing newline, which IO does not like
77+
encoded_data = binascii.b2a_base64(jpeg).strip()
78+
print(f"Expanded to {len(encoded_data)} for IO upload")
79+
80+
io.publish("image", encoded_data)
81+
82+
print("Waiting 3s")
83+
time.sleep(3)

0 commit comments

Comments
 (0)