Skip to content

Commit ee855e1

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-effects-modes
2 parents 829f16e + 8cd38a6 commit ee855e1

File tree

5 files changed

+81
-24
lines changed

5 files changed

+81
-24
lines changed

adafruit_ov5640.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ def _set_size_and_colorspace(self): # pylint: disable=too-many-locals
10651065
sys_mul = 180
10661066
self._set_pll(False, sys_mul, 4, 2, False, 2, True, 4)
10671067
else:
1068-
self._set_pll(False, 8, 1, 1, False, 1, True, 4)
1068+
self._set_pll(False, 32, 1, 1, False, 1, True, 4)
10691069

10701070
self._set_colorspace()
10711071

@@ -1165,14 +1165,14 @@ def effect(self, value):
11651165

11661166
@property
11671167
def quality(self):
1168-
"""Controls the JPEG quality. Valid range is from 5..55 inclusive"""
1168+
"""Controls the JPEG quality. Valid range is from 2..55 inclusive"""
11691169
return self._read_register(_COMPRESSION_CTRL07) & 0x3F
11701170

11711171
@quality.setter
11721172
def quality(self, value: int):
1173-
if not 5 <= value < 55:
1173+
if not 2 <= value < 55:
11741174
raise ValueError(
1175-
f"Invalid quality value {value}, use a value from 5..55 inclusive"
1175+
f"Invalid quality value {value}, use a value from 2..55 inclusive"
11761176
)
11771177
self._write_register(_COMPRESSION_CTRL07, value & 0x3F)
11781178

examples/ov5640_directio_kaluga1_3_ili9341.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""
1818

1919
import struct
20+
2021
import board
2122
import busio
2223
import digitalio

examples/ov5640_jpeg_kaluga1_3.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,45 @@
1010
The audio board must be mounted between the Kaluga and the LCD, it provides the
1111
I2C pull-ups(!)
1212
13-
You also need to place ov5640_jpeg_kaluga1_3_boot.py at CIRCUITPY/boot.py
14-
and reset the board to make the internal flash readable by CircuitPython.
15-
You can make CIRCUITPY readable from your PC by booting CircuitPython in
16-
safe mode or holding the "MODE" button on the audio daughterboard while
17-
powering on or resetting the board.
13+
You also need to place ov5640_jpeg_kaluga1_3_boot.py at CIRCUITPY/boot.py.
14+
Then, hold the Mode button (button K2 on the audio board) while resetting the
15+
board to make the internal flash readable by CircuitPython.
1816
"""
1917

18+
import time
19+
2020
import board
2121
import busio
22+
import displayio
23+
import microcontroller
24+
25+
import adafruit_ili9341
2226
import adafruit_ov5640
2327

28+
# Release any resources currently in use for the displays
29+
displayio.release_displays()
30+
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
31+
display_bus = displayio.FourWire(
32+
spi,
33+
command=board.LCD_D_C,
34+
chip_select=board.LCD_CS,
35+
reset=board.LCD_RST,
36+
baudrate=80_000_000,
37+
)
38+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, rotation=90)
39+
40+
try:
41+
with open("/boot_out.txt", "ab") as f:
42+
pass
43+
except OSError as e:
44+
print(e)
45+
print(
46+
"A 'read-only filesystem' error occurs if you did not correctly install"
47+
"\nov5640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the"
48+
'\nboard while holding the "mode" button'
49+
"\n\nThis message is also shown after the board takes a picture and auto-restarts"
50+
)
51+
raise SystemExit from e
2452

2553
bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
2654
cam = adafruit_ov5640.OV5640(
@@ -30,22 +58,31 @@
3058
vsync=board.CAMERA_VSYNC,
3159
href=board.CAMERA_HREF,
3260
mclk=board.CAMERA_XCLK,
33-
mclk_frequency=20_000_000,
34-
size=adafruit_ov5640.OV5640_SIZE_QVGA,
61+
size=adafruit_ov5640.OV5640_SIZE_QSXGA,
3562
)
3663

3764
cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG
65+
cam.quality = 5
3866
b = bytearray(cam.capture_buffer_size)
67+
print(f"Capturing jpeg image of up to {len(b)} bytes")
3968
jpeg = cam.capture(b)
4069

4170
print(f"Captured {len(jpeg)} bytes of jpeg data")
4271
try:
43-
with open("/jpeg.jpg", "wb") as f:
44-
f.write(jpeg)
72+
print(end="Writing to internal storage (this is SLOW)")
73+
with open("/cam.jpg", "wb") as f:
74+
for i in range(0, len(jpeg), 4096):
75+
print(end=".")
76+
f.write(jpeg[i : i + 4096])
77+
print()
78+
print("Wrote to CIRCUITPY/cam.jpg")
79+
print("Resetting so computer sees new content of CIRCUITPY")
80+
time.sleep(0.5)
81+
microcontroller.reset() # pylint: disable=no-member
82+
4583
except OSError as e:
4684
print(e)
4785
print(
4886
"A 'read-only filesystem' error occurs if you did not correctly install"
4987
"\nov5640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the board"
5088
)
51-
print("Wrote to CIRCUITPY/jpeg.jpg")

examples/ov5640_jpeg_kaluga1_3_boot.py

Lines changed: 3 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,7 @@
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+
print("measured voltage", a_voltage)
22+
if abs(a_voltage - V_MODE) < 0.05: # If mode IS pressed...
2223
print("storage writable by CircuitPython")
2324
storage.remount("/", readonly=False)

examples/ov5640_sdcard_kaluga_1_3.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,30 @@
2121
"""
2222

2323
import os
24-
2524
import time
25+
2626
import analogio
2727
import board
2828
import busio
29-
import adafruit_ov5640
29+
import displayio
3030
import neopixel
31-
import storage
3231
import sdcardio
32+
import storage
33+
34+
import adafruit_ili9341
35+
import adafruit_ov5640
36+
37+
# Release any resources currently in use for the displays
38+
displayio.release_displays()
39+
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
40+
display_bus = displayio.FourWire(
41+
spi,
42+
command=board.LCD_D_C,
43+
chip_select=board.LCD_CS,
44+
reset=board.LCD_RST,
45+
baudrate=80_000_000,
46+
)
47+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, rotation=90)
3348

3449
V_MODE = 1.98
3550
V_RECORD = 2.41
@@ -60,15 +75,15 @@ def exists(filename):
6075
try:
6176
os.stat(filename)
6277
return True
63-
except OSError as e:
78+
except OSError as _:
6479
return False
6580

6681

6782
_image_counter = 0
6883

6984

7085
def open_next_image():
71-
global _image_counter
86+
global _image_counter # pylint: disable=global-statement
7287
while True:
7388
filename = f"/sd/img{_image_counter:04d}.jpg"
7489
_image_counter += 1
@@ -86,15 +101,16 @@ def open_next_image():
86101
while True:
87102
pixel[0] = 0x0000FF
88103
pixel.write()
89-
a_voltage = a.value * a.reference_voltage / 65535
104+
a_voltage = a.value * a.reference_voltage / 65535 # pylint: disable=no-member
90105
record_pressed = abs(a_voltage - V_RECORD) < 0.05
91106
if record_pressed:
92107
pixel[0] = 0xFF0000
93108
pixel.write()
94109
time.sleep(0.01)
95110
jpeg = cam.capture(b)
96111
print(
97-
f"Captured {len(jpeg)} bytes of jpeg data (had allocated {cam.capture_buffer_size} bytes"
112+
f"Captured {len(jpeg)} bytes of jpeg data"
113+
f" (had allocated {cam.capture_buffer_size} bytes"
98114
)
99115
print(f"Resolution {cam.width}x{cam.height}")
100116
try:
@@ -108,5 +124,7 @@ def open_next_image():
108124
except OSError as e:
109125
print(e)
110126
while record_pressed:
111-
a_voltage = a.value * a.reference_voltage / 65535
127+
a_voltage = (
128+
a.value * a.reference_voltage / 65535
129+
) # pylint: disable=no-member
112130
record_pressed = abs(a_voltage - V_RECORD) < 0.05

0 commit comments

Comments
 (0)