Skip to content

Enhance #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions adafruit_ov2640.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,3 +1334,22 @@ def _set_window(
# Reestablish test pattern
if self._test_pattern:
self.test_pattern = self._test_pattern

@property
def exposure(self):
"""The exposure level of the sensor"""
aec_9_2 = self._get_reg_bits(_BANK_SENSOR, _AEC, 0, 0xFF)
aec_15_10 = self._get_reg_bits(_BANK_SENSOR, _REG45, 0, 0b111111)
aec_1_0 = self._get_reg_bits(_BANK_SENSOR, _REG04, 0, 0b11)

return aec_1_0 | (aec_9_2 << 2) | (aec_15_10 << 10)

@exposure.setter
def exposure(self, exposure):
aec_1_0 = exposure & 0x11
aec_9_2 = (exposure >> 2) & 0b11111111
aec_15_10 = exposure >> 10

self._set_reg_bits(_BANK_SENSOR, _AEC, 0, 0xFF, aec_9_2)
self._set_reg_bits(_BANK_SENSOR, _REG45, 0, 0b111111, aec_15_10)
self._set_reg_bits(_BANK_SENSOR, _REG04, 0, 0b11, aec_1_0)
70 changes: 61 additions & 9 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,93 @@ Simple test
Ensure your device works with this simple test.

.. literalinclude:: ../examples/ov2640_simpletest.py
:caption: examples/ov2640_simpletest.py
:caption: ov2640_simpletest.py
:linenos:


LCD tests
---------

Kaluga 1.3 with ili9341
~~~~~~~~~~~~~~~~~~~~~~~

Display an image from the camera on the Kaluga 1.3 board, if it is fitted with an ili9341 display.

.. literalinclude:: ../examples/ov2640_displayio_kaluga1_3_ili9341.py
:caption: ../examples/ov2640_displayio_kaluga1_3_ili9341.py
:caption: ov2640_displayio_kaluga1_3_ili9341.py
:linenos:

Kaluga 1.3 with st7789
~~~~~~~~~~~~~~~~~~~~~~

Display an image from the camera on the Kaluga 1.3 board, if it is fitted with an st7789 display.

.. literalinclude:: ../examples/ov2640_displayio_kaluga1_3_st7789.py
:caption: ../examples/ov2640_displayio_kaluga1_3_st7789.py
:caption: ov2640_displayio_kaluga1_3_st7789.py
:linenos:

Raspberry Pi Pico with st7789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Display an image from the camera connected to a Raspberry Pi Pico with an st7789 2" display

.. literalinclude:: ../examples/ov2640_displayio_pico_st7789_2in.py
:caption: ../examples/ov2640_displayio_pico_st7789_2in.py
:caption: ov2640_displayio_pico_st7789_2in.py
:linenos:

Save an image to internal flash on Kaluga 1.3
Kaluga 1.3 with ili9341, direct display
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Preview images on LCD, bypassing displayio for slightly higher framerate

.. literalinclude:: ../examples/ov2640_directio_kaluga1_3_ili9341.py
:caption: ../examples/ov2640_directio_kaluga1_3_ili9341.py
:linenos:


Image-saving tests
------------------

Kaluga 1.3 with ili9341, internal flash, JPEG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Preview images on LCD t hen save JPEG images to internal flash on Kaluga 1.3. Requires the second snippet of
code to be saved as ``boot.py``.

.. literalinclude:: ../examples/ov2640_jpeg_kaluga1_3.py
:caption: ../examples/ov2640_jpeg_kaluga1_3.py
:caption: ov2640_jpeg_kaluga1_3.py
:linenos:

``boot.py`` for the above program

.. literalinclude:: ../examples/ov2640_jpeg_kaluga1_3_boot.py
:caption: ../examples/ov2640_jpeg_kaluga1_3_boot.py
:caption: ov2640_jpeg_kaluga1_3_boot.py
:linenos:

Preview images on LCD then save to SD on Kaluga 1.3 fitted with an ili9341 display
Kaluga 1.3 with ili9341, external SD card, JPEG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Preview images on LCD then save JPEG images to SD on Kaluga 1.3 fitted with an ili9341 display.

.. literalinclude:: ../examples/ov2640_jpeg_sd_kaluga1_3.py
:caption: ../examples/ov2640_jpeg_sd_kaluga1_3.py
:caption: ov2640_jpeg_sd_kaluga1_3.py
:linenos:

Kaluga 1.3 with ili9341, external SD card, BMP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Preview images on LCD then save BMP images to SD on Kaluga 1.3 fitted with an ili9341 display.

.. literalinclude:: ../examples/ov2640_bmp_sd_kaluga1_3.py
:caption: ov2640_bmp_sd_kaluga1_3.py
:linenos:


Kaluga 1.3 with Adafruit IO
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Upload JPEG images to Adafruit IO. Requires that WIFI and Adafruit IO be configured in ``secrets.py``.

.. literalinclude:: ../examples/ov2640_aio_kaluga1_3.py
:caption: ov2640_aio_kaluga1_3.py
:linenos:
83 changes: 83 additions & 0 deletions examples/ov2640_aio_kaluga1_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

"""
The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is
tested on v1.3.

The audio board must be mounted between the Kaluga and the LCD, it provides the
I2C pull-ups(!)

This example requires that your WIFI and Adafruit IO credentials be configured
in CIRCUITPY/secrets.py, and that you have created a feed called "image" with
history disabled.

The maximum image size is 100kB after base64 encoding, or about 65kB before
base64 encoding. In practice, "SVGA" (800x600) images are typically around
40kB even though the "capture_buffer_size" (theoretical maximum size) is
(width*height/5) bytes or 96kB.
"""

import binascii
import ssl
import time
from secrets import secrets # pylint: disable=no-name-in-module

import board
import busio
import wifi
import socketpool
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT
import adafruit_ov2640

feed_name = "image"

print("Connecting to WIFI")
wifi.radio.connect(secrets["ssid"], secrets["password"])
pool = socketpool.SocketPool(wifi.radio)

print("Connecting to Adafruit IO")
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl.create_default_context(),
)
mqtt_client.connect()
io = IO_MQTT(mqtt_client)

bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
cam = adafruit_ov2640.OV2640(
bus,
data_pins=board.CAMERA_DATA,
clock=board.CAMERA_PCLK,
vsync=board.CAMERA_VSYNC,
href=board.CAMERA_HREF,
mclk=board.CAMERA_XCLK,
mclk_frequency=20_000_000,
size=adafruit_ov2640.OV2640_SIZE_QVGA,
)

cam.flip_x = False
cam.flip_y = False
cam.test_pattern = False

cam.size = adafruit_ov2640.OV2640_SIZE_SVGA
cam.colorspace = adafruit_ov2640.OV2640_COLOR_JPEG
jpeg_buffer = bytearray(cam.capture_buffer_size)
while True:
jpeg = cam.capture(jpeg_buffer)
print(f"Captured {len(jpeg)} bytes of jpeg data")

# b2a_base64() appends a trailing newline, which IO does not like
encoded_data = binascii.b2a_base64(jpeg).strip()
print(f"Expanded to {len(encoded_data)} for IO upload")

io.publish("image", encoded_data)

print("Waiting 3s")
time.sleep(3)
Loading