Skip to content

Commit 61f071d

Browse files
committed
Add a demo to capture jpeg to internal storage
1 parent 4581f25 commit 61f071d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

examples/ov5640_jpeg_kaluga1_3.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@
1717
powering on or resetting the board.
1818
"""
1919

20+
import time
21+
2022
import board
2123
import busio
2224
import adafruit_ov5640
25+
import microcontroller
2326

27+
try:
28+
with open("/boot_out.txt", "a") as f:
29+
pass
30+
except OSError as e:
31+
print(e)
32+
print(
33+
"A 'read-only filesystem' error occurs if you did not correctly install"
34+
"\nov5640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the"
35+
'\nboard while holding the "mode" button'
36+
)
37+
raise SystemExit
2438

2539
bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
2640
cam = adafruit_ov5640.OV5640(
@@ -30,22 +44,28 @@
3044
vsync=board.CAMERA_VSYNC,
3145
href=board.CAMERA_HREF,
3246
mclk=board.CAMERA_XCLK,
33-
mclk_frequency=20_000_000,
34-
size=adafruit_ov5640.OV5640_SIZE_QVGA,
47+
size=adafruit_ov5640.OV5640_SIZE_SXGA,
3548
)
3649

3750
cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG
51+
cam.quality = 5
3852
b = bytearray(cam.capture_buffer_size)
53+
print(f"Capturing jpeg image of up to {len(b)} bytes")
3954
jpeg = cam.capture(b)
4055

4156
print(f"Captured {len(jpeg)} bytes of jpeg data")
4257
try:
43-
with open("/jpeg.jpg", "wb") as f:
58+
print("Writing to internal storage (this is SLOW)")
59+
with open("/cam.jpg", "wb") as f:
4460
f.write(jpeg)
61+
print("Wrote to CIRCUITPY/cam.jpg")
62+
print("Resetting so computer sees new content of CIRCUITPY")
63+
time.sleep(0.5)
64+
microcontroller.reset()
65+
4566
except OSError as e:
4667
print(e)
4768
print(
4869
"A 'read-only filesystem' error occurs if you did not correctly install"
4970
"\nov5640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the board"
5071
)
51-
print("Wrote to CIRCUITPY/jpeg.jpg")

examples/ov5640_jpeg_kaluga1_3_boot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""Use this file as CIRCUITPY/boot.py in conjunction with ov5640_jpeg_kaluga1_3.py
66
77
It makes the CIRCUITPY filesystem writable to CircuitPython
8-
(and read-only to the PC) unless the "MODE" button on the audio
8+
(and read-only to the PC) if the "MODE" button on the audio
99
daughterboard is held while the board is powered on or reset.
1010
"""
1111

@@ -18,6 +18,6 @@
1818

1919
a = analogio.AnalogIn(board.IO6)
2020
a_voltage = a.value * a.reference_voltage / 65535 # pylint: disable=no-member
21-
if abs(a_voltage - V_MODE) > 0.05: # If mode is NOT pressed...
21+
if abs(a_voltage - V_MODE) < 0.05: # If mode IS pressed...
2222
print("storage writable by CircuitPython")
2323
storage.remount("/", readonly=False)

0 commit comments

Comments
 (0)