/ examples / ov7670_simpletest.py
ov7670_simpletest.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  """Capture an image from the camera and display it as ASCII art.
 7  
 8  The camera is placed in YUV mode, so the top 8 bits of each color
 9  value can be treated as "greyscale"."""
10  
11  import time
12  
13  import digitalio
14  import busio
15  import board
16  
17  from adafruit_ov7670 import OV7670, OV7670_SIZE_DIV16, OV7670_COLOR_YUV
18  
19  # Ensure the camera is shut down, so that it releases the SDA/SCL lines,
20  # then create the configuration I2C bus
21  
22  with digitalio.DigitalInOut(board.D39) as shutdown:
23      shutdown.switch_to_output(True)
24      time.sleep(0.001)
25      bus = busio.I2C(board.D24, board.D25)
26  
27  cam = OV7670(
28      bus,
29      data0=board.PCC_D0,
30      clock=board.PCC_CLK,
31      vsync=board.PCC_DEN1,
32      href=board.PCC_DEN2,
33      mclk=board.D29,
34      shutdown=board.D39,
35      reset=board.D38,
36  )
37  cam.size = OV7670_SIZE_DIV16
38  cam.colorspace = OV7670_COLOR_YUV
39  
40  buf = bytearray(2 * cam.width * cam.height)
41  chars = " .:-=+*#%@"
42  
43  cam.capture(buf)
44  width = cam.width
45  for j in range(cam.height):
46      for i in range(cam.width):
47          b = buf[2 * (width * j + i)] * (len(chars) - 1) // 255
48          print(end=chars[b] * 2)
49      print()