/ examples / ov2640_jpeg_kaluga1_3.py
ov2640_jpeg_kaluga1_3.py
 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  You also need to place ov2640_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.
18  """
19  
20  import board
21  import busio
22  import adafruit_ov2640
23  
24  
25  bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
26  cam = adafruit_ov2640.OV2640(
27      bus,
28      data_pins=board.CAMERA_DATA,
29      clock=board.CAMERA_PCLK,
30      vsync=board.CAMERA_VSYNC,
31      href=board.CAMERA_HREF,
32      mclk=board.CAMERA_XCLK,
33      mclk_frequency=20_000_000,
34      size=adafruit_ov2640.OV2640_SIZE_QVGA,
35  )
36  
37  pid = cam.product_id
38  ver = cam.product_version
39  print(f"Detected pid={pid:x} ver={ver:x}")
40  # cam.test_pattern = True
41  
42  cam.colorspace = adafruit_ov2640.OV2640_COLOR_JPEG
43  b = bytearray(cam.capture_buffer_size)
44  jpeg = cam.capture(b)
45  
46  print(f"Captured {len(jpeg)} bytes of jpeg data")
47  try:
48      with open("/jpeg.jpg", "wb") as f:
49          f.write(jpeg)
50  except OSError as e:
51      print(e)
52      print(
53          "A 'read-only filesystem' error occurs if you did not correctly install"
54          "\nov2640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the board"
55      )
56  print("Wrote to CIRCUITPY/jpeg.jpg")