It's easy to use the PiCowbell Camera Breakout with CircuitPython and the Adafruit_CircuitPython_OV5640 library. This library allows you to easily write Python code that lets you interface with the OV5640 camera modules.
The first example will use a 240x240 TFT display to show a preview from the camera.




Wiring
The Raspberry Pi Pico and the PiCowbell Camera will be plugged into a PiCowbell Doubler. You can use an EYESPI breakout to easily connect to the EYESPI TFT display.
- EYESPI Vin to Pico 3.3V (red wire)
- EYESPI Gnd to Pico GND (black wire)
- EYESPI SCK to Pico GP18 (green wire)
- EYESPI MOSI to Pico GP19 (blue wire)
- EYESPI DC to Pico GP21 (yellow wire)
- EYESPI TCS to Pico GP17 (white wire)
CircuitPython Usage
To use with CircuitPython, you need to first install the OV5640 library, and its dependencies, into the lib folder onto your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file.
Connect your board to your computer via a known good data+power USB cable. The board should show up in your File Explorer/Finder (depending on your operating system) as a flash drive named CIRCUITPY.
Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and files:
- adafruit_bus_device/
- adafruit_ov5640.mpy
- adafruit_st7789.mpy

Example Code
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: Unlicense """ This demo is designed for the Raspberry Pi Pico, Camera PiCowbell, and ST7789 240x240 SPI TFT display It shows the camera image on the LCD """ import time import busio import board import digitalio import adafruit_ov5640 import adafruit_st7789 import displayio import fourwire displayio.release_displays() spi = busio.SPI(clock=board.GP18, MOSI=board.GP19) display_bus = fourwire.FourWire(spi, command=board.GP21, chip_select=board.GP17, reset=None) display = adafruit_st7789.ST7789(display_bus, width=240, height=240, rowstart=80, rotation=0) print("construct bus") i2c = busio.I2C(board.GP5, board.GP4) print("construct camera") reset = digitalio.DigitalInOut(board.GP14) cam = adafruit_ov5640.OV5640( i2c, data_pins=( board.GP6, board.GP7, board.GP8, board.GP9, board.GP10, board.GP11, board.GP12, board.GP13, ), clock=board.GP3, vsync=board.GP0, href=board.GP2, mclk=None, shutdown=None, reset=reset, size=adafruit_ov5640.OV5640_SIZE_240X240, ) print("print chip id") print(cam.chip_id) cam.colorspace = adafruit_ov5640.OV5640_COLOR_RGB cam.flip_y = False cam.flip_x = False cam.test_pattern = False width = display.width height = display.height #cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE try: bitmap = displayio.Bitmap(cam.width, cam.height, 65535) except MemoryError: print("Oops, 240x240 is a little too big, trying 240x176..") cam.size = adafruit_ov5640.OV5640_SIZE_QCIF bitmap = displayio.Bitmap(cam.width, cam.height, 65535) print(width, height, cam.width, cam.height) if bitmap is None: raise SystemExit("Could not allocate a bitmap") g = displayio.Group(scale=1, x=(width-cam.width)//2, y=(height-cam.height)//2) tg = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565_SWAPPED) ) g.append(tg) display.root_group = g t0 = time.monotonic_ns() display.auto_refresh = False while True: cam.capture(bitmap) bitmap.dirty() display.refresh(minimum_frames_per_second=0) t1 = time.monotonic_ns() print("fps", 1e9 / (t1 - t0)) t0 = t1
In the code, the TFT display is instantiated over SPI. Then, the camera object is constructed. The camera frame is shown as a bitmap on the TFT display. In the serial monitor, you'll see the framerate of the camera printed.
Page last edited January 22, 2025
Text editor powered by tinymce.