ov5640_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 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. 16 """ 17 18 import time 19 20 import board 21 import busio 22 import displayio 23 import microcontroller 24 25 import adafruit_ili9341 26 import adafruit_ov5640 27 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 52 53 bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD) 54 cam = adafruit_ov5640.OV5640( 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 size=adafruit_ov5640.OV5640_SIZE_QSXGA, 62 ) 63 64 cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG 65 cam.quality = 5 66 b = bytearray(cam.capture_buffer_size) 67 print(f"Capturing jpeg image of up to {len(b)} bytes") 68 jpeg = cam.capture(b) 69 70 print(f"Captured {len(jpeg)} bytes of jpeg data") 71 try: 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 83 except OSError as e: 84 print(e) 85 print( 86 "A 'read-only filesystem' error occurs if you did not correctly install" 87 "\nov5640_jpeg_kaluga1_3_boot.py as CIRCUITPY/boot.py and reset the board" 88 )