# Adafruit OV5640 Camera Breakouts

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/118/224/medium800/adafruit_products_5673-02.jpg?1675783179)

Hobby-level microcontrollers are finally getting powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output, DMA to quickly grab a frame, and the necessary RAM to buffer a raw snapshot. Now all that is needed is a nice camera module to make interfacing easy!

![](https://cdn-learn.adafruit.com/assets/assets/000/118/225/medium800/adafruit_products_5673-05.jpg?1675783240)

This Adafruit OV5640 Camera Breakout with 120 Degree Lens has a nice quality OV5640 camera with a 5 Megapixel sensor element, 120-degree wide angle lens, and all the support circuitry you need. Adafruit looked at existing camera modules and while this breakout board is backwards compatible, they made some improvements:

- Standard&nbsp;2x9 header if you want it, but also a duplicated header strip 0.3" apart so you can plug it into a breadboard or perfboard&nbsp;
- Selectable external or internal 24MHz "XCLK" clock generation - save one GPIO pin, or just have a nice stable 24 MHz signal even if your microcontroller can't generate it for you.
- Heat-sinking camera area with exposed ground pad, with lots of vias for good thermal transfer. Helpful for when doing continuous encoding and reducing thermal image drift.
- Optional VMotor 3.3V power jumper on DATA1, for auto-focusing camera modules
- 3.3V power-good LED on back that can be disabled

![](https://cdn-learn.adafruit.com/assets/assets/000/118/226/medium800/adafruit_products_5673-06.jpg?1675783294)

The module comes with header pins so you can solder it for use on a breadboard or on the standard 2x9 header—It's up to you.

# Adafruit OV5640 Camera Breakouts

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/118/457/medium800/adafruit_products_5673-fb.jpg?1676325954)

## A note on silkscreen labels
In each column, the top label (e.g., G, SDA, etc) applies to both the _top_ and _center_ rows of pins. The bottom label (e.g., 3V, SCL, etc) is for the bottom row of pins. As noted on the Assembly page, depending how you will install the module you will either be using the two outermost rows of pins, or the two bottom rows of pins.

![adafruit_products_Camera-Pin-Diagram.jpg](https://cdn-learn.adafruit.com/assets/assets/000/118/602/medium640/adafruit_products_Camera-Pin-Diagram.jpg?1676578605)

![](https://cdn-learn.adafruit.com/assets/assets/000/118/458/medium800/adafruit_products_5640-pins-camera.jpg?1676326034)

## Camera Lens

This OV5640 camera has a 120° wide-angle lens. Its focusing distance can't be adjusted. When shipped, it has an opaque lens cap on it. Remove the cap to capture images, unless you **really** like the color black.

## Power Supply
![](https://cdn-learn.adafruit.com/assets/assets/000/118/232/medium800/adafruit_products_5640-pins-power.jpg?1675787367)

The camera module requires a well-regulated 3.3v supply in order to operate.

- **G** (GND): Connect to microcontroller GND
- **3V** (3.3V): Connect to microcontroller +3.3V supply

## Power Down & Reset
![](https://cdn-learn.adafruit.com/assets/assets/000/118/234/medium800/adafruit_products_5640-pins-reset.jpg?1675787404)

- **PD** (powerdown): Optional connection to microcontroller GPIO. When pulled **HIGH** the camera module is put into power-down mode. When released or pulled **LOW** the camera is powered on. This pin can also be pulsed **HIGH** as a way to reset the camera.
- **RT** (reset): Optional connect to microcontroller GPIO. Pull the pin **LOW** to reset the camera module and release it or pull it **HIGH** to enter operating mode.

Both pins have built-in pull resistors, so by default the camera is powered on and allowed to exit reset mode.

## Power LED
![](https://cdn-learn.adafruit.com/assets/assets/000/118/238/medium800/adafruit_products_5673-04-powerled.jpg?1675787770)

When powered on, this LED will light. To disable the LED, cut the small trace between the two pads of the solder jumper. To re-enable it, bridge the two pads with a blob of solder.

## I2C Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/118/233/medium800/adafruit_products_5640-pins-i2c.jpg?1675787381)

The camera module must be configured using I2C.

- **SDA** : Connect to microcontroller SDA
- **SCL** : Connect to microcontroller SDL

Adafruit's OV5640 camera module has built-in pull ups, so you don't need to add external ones. But note that many modules from other vendors _do not have these pull-ups._

## Clock and Synchronization Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/118/235/medium800/adafruit_products_5640-pins-clocking.jpg?1675787425)

- **XC** (external clock): When the **XCLK** jumper is set to " **EXT**" (the default), this pin must be driven with a 24MHz square wave from the microcontroller or other source. When the jumper is changed to " **INT**", then an on-board clock generator is used instead. In this case, the **XC** pin should not be driven by the microcontroller and may be left unconnected.
- **PC** (pixel clock) tells the microcontroller when image data is available. This may need to be connected to a specific microcontroller pin.
- **VS** and&nbsp; **HS** are synchronization signals, which tell the microcontroller when a new frame ( **VS** ) or row ( **HS** ) of data begins. These may need to be connected to specific microcontroller pins.

![](https://cdn-learn.adafruit.com/assets/assets/000/118/237/medium800/adafruit_products_5673-04-clocksel.jpg?1675787651)

The OV5640 Camera Breakout includes an on-board 24MHz crystal oscillator. To use this as the OV5640 clock, cut the jumper from the center pad to **EXT** then solder between the center pad and **INT**. In this mode, any input on the **XC** pin is ignored and&nbsp; **XC** may be left unconnected.

## Data Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/118/236/medium800/adafruit_products_5640-pins-data.jpg?1675787438)

The 8 data pins (numbered from **D2** to **D9** _because reasons_) carry data out of the camera into the microcontroller.

Depending on mode, these 8 data bits can be half of a 16-bit pixel value, or one byte of JPEG data.

## Autofocus Motor Power
![](https://cdn-learn.adafruit.com/assets/assets/000/118/239/medium800/adafruit_products_5673-04-focusmotor.jpg?1675787871)

While the camera supplied with the OV5640 Camera Breakout does not have an auto-focus motor, some compatible camera modules include a "voice coil" motor for auto-focus.

If you install such a module, close the **VM** jumper with a blob of solder. Internally, this connects the 3.3V supply to the camera module on its **D1** connection.

## Test Bar Mode
In test bar mode, the camera shows color bars in the order **white** - **yellow** - **cyan** - **green** - **purple** - **red** - **blue** - **black**. A small vertical bar of inverted colors moves from top to bottom. Here's a typical test bar, captured in JPEG mode at VGA resolution.

![adafruit_products_img0006.jpg](https://cdn-learn.adafruit.com/assets/assets/000/118/553/medium640/adafruit_products_img0006.jpg?1676489257)

# Adafruit OV5640 Camera Breakouts

## Assembly

First, decide how you are going to use your camera module: on a board which has a standard 2x9 header or on a standard breadboard.

If your microcontroller has a 2x9 header available, that method is strongly preferred! The high speed signals of the camera module can be scrambled even with short lengths of jumper wire on a solderless breadboard.

Using side cutters, snap off two 9-pin sections of headers.

**If you are soldering for the 2x9 header** then place the pins in the two rows at the edge of the board

**If you are soldering for breadboard use** then place the pins in the outermost rows, leaving the middle row empty.

![](https://cdn-learn.adafruit.com/assets/assets/000/118/230/medium800/adafruit_products_whichrows.png?1675784881)

Carefully align the headers. You can use tacky clay to hold them in place. Solder just one pin in each row, then check again for alignment. If the pins are poorly aligned, re-heat the solder joint while adjusting it until it is straight. Add flux if needed so that you don't end up with a cold solder joint.

Then, solder the rest of the pins.

_(For tips on soldering, be sure to check out our&nbsp;_[_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._

# Adafruit OV5640 Camera Breakouts

## CircuitPython Camera Libraries

There are multiple libraries for camera support on CircuitPython.

For Espressif boards, the built in [**espcamera**](https://docs.circuitpython.org/en/latest/shared-bindings/espcamera/index.html) module (added in CircuitPython 8) interfaces with multiple types of cameras including the OV5640.

For other boards, such as the Raspberry Pi Pico with RP2040 microcontrollers, an installable library called [**adafruit\_ov5640**](https://docs.circuitpython.org/projects/ov5640/en/latest/) is used instead. Internally, this uses a module called [**imagecapture**](https://docs.circuitpython.org/en/latest/shared-bindings/imagecapture/index.html) for low-level camera interfacing.

Remember to use the right library for your board!

Warning: Adafruit does not provide support for this board with MicroPython.

## Camera Pin Naming

By convention, if a board has an integrated camera or a dedicated camera connector, the following will exist in the **board** module:

- **CAMERA\_SIOC** - the **SCL** pin of the camera
- **CAMERA\_SIOD** - the **SDA** pin of the camera
- **CAMERA\_PCLK** - the pixel clock of the camera
- **CAMERA\_VSYNC** - the vertical sync of the camera
- **CAMERA\_HREF** - the horizontal sync of the camera
- **CAMERA\_XCLK** - the input clock pin of the camera
- **CAMERA\_DATA** - the 8 data pins of the camera

# Adafruit OV5640 Camera Breakouts

## Espressif ESP32-family Overview

CircuitPython's **espcamera** module is available on most supported ESP32-S2 and ESP32-S3 boards with PSRAM. It incorporates both the camera configuration code and the image capturing code in a single library that works across multiple types of camera modules, instead of being available for regular CircuitPython objects.

Info: CircuitPython 9 does not require reserving PSRAM: the CIRCUITPY_RESERVED_PSRAM= directive is ignored. Read the below only if you are using CircuitPython 8.

## Setting 'reserved PSRAM'

Because of how CircuitPython and ESP-IDF (_Espressif IoT Development Framework_) manage memory together, a portion of memory has to be set aside for the camera framebuffers.

Usually, 1MB (1048576 bytes) is a reasonable amount of memory to reserve. This is plenty of space for two 320×240 bitmap images or a 5-megapixel JPEG image, along with other memory that the esp-idf allocates internally.

Boards with built-in cameras include a default reserved PSRAM setting. Boards with only a dedicated camera header do not.

To set the reserved memory amount, edit the **settings.toml** file within the **CIRCUITPY** drive. Add a line that says `CIRCUITPY_RESERVED_PSRAM=1048576`

The setting will become effective when the board is reset with the reset button. You can check it by opening the repl and running the following lines:

```auto
Adafruit CircuitPython 8.0.0-rc.1 on 2023-01-30; Kaluga 1 with ESP32S2
>>> import espidf
>>> espidf.get_reserved_psram()
1048576
```

## Pin Choices

By selecting appropriate pins, you can use the espcamera CircuitPython module on other boards with supported ESP32, ESP32-S2 and ESP32-S3 microcontrollers:

- **xclk** , **pclk** , **vsync** , **href** : Free choice of any pin
- **reset** , **shutdown** : Free choice of any pin. Can omit one or both, but the initialization sequence is less reliable.
- **data\_pins** : Free choice of any 8 pins

By convention, if a board has an integrated camera or a dedicated camera connector, the following will exist in the **board** module:

- **CAMERA\_SIOC** - the **SCL** pin of the camera
- **CAMERA\_SIOD** - the **SDA** pin of the camera
- **CAMERA\_PCLK** - the pixel clock of the camera
- **CAMERA\_VSYNC** - the vertical sync of the camera
- **CAMERA\_HREF** - the horizontal sync of the camera
- **CAMERA\_XCLK** - the input clock pin of the camera
- **CAMERA\_DATA** - the 8 data pins of the camera

Continue to the next page to see how to use the camera module with the Espressif Kaluga, which has a compatible 18-pin camera connector built in.

# Adafruit OV5640 Camera Breakouts

## Install TinyUF2 on Espressif Kaluga

Info: 

Now, use the breakout USB connection in lieu of either of the built-in USB Micro B ports to install and use CircuitPython.

Start by connecting the USB Breakout Cable to the Kaluga board.

- **Black** : Use a Male/Female Extension Jumper Wire to connect to **GND**
- **White** : Connect to **IO19**
- **Green** : Connect to **IO20**
- **Red** : Use a Male/Female Extension Jumper Wire to connect to **5V**

![sensors_PXL_20210629_171325610.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/223/medium640/sensors_PXL_20210629_171325610.jpg?1624987366)

Danger: 

If you're familiar with our other products and chipsets you may be famliar with our drag-n-drop bootloader, a.k.a UF2. We have a UF2 bootloader for the ESP32-S2, that will let you drag firmware on/off a USB disk drive.

Warning: 

However, thanks to the ROM bootloader, you don't have to worry about it if the UF2 bootloader is damaged. The ROM bootloader can never be disabled or erased, so its always there if you need it! You can simply re-load the UF2 bootloader (USB-disk-style) with the ROM bootloader (non-USB-drive)

You can use the TinyUF2 bootloader to load code directly, say CircuitPython or the binary output of an Arduino compilation or you can use it to load a&nbsp;_second_&nbsp;bootloader on, like UF2 which has a drag-n-drop interface.

Danger: 

# Method 1: WebSerial ESPTool / `esptool`

This section outlines using WebSerial ESPTool or `esptool` to flash the UF2 bootloader onto your ESP32-S2 board.

## Step 1. Download the tinyuf2 combined.bin file here

Note that this file is 3MB but that's because the bootloader is near the end of the available flash. It's not actually 3MB large, most of the file is empty but its easier to program if we give you one combined 'swiss cheese' file. Save this file to your desktop or wherever you plan to run esptool from

[combined.bin](https://cdn-learn.adafruit.com/assets/assets/000/103/224/original/combined.bin?1624988368)
## Step 2. Place your board in bootloader mode

Entering the bootloader is easy. Complete the following steps.

1. **Make sure your ESP32-S2 is plugged into USB port to your computer using a data/sync cable.** &nbsp;Charge-only cables will not work!
2. **Turn on the On/Off switch** &nbsp;- If your board has a power switch, check that you see the OK light on so you know the board is powered, a prerequisite!
3. **Press and hold the DFU / Boot0 button down.** &nbsp;Don't let go of it yet!
4. **Press and release the Reset button.** &nbsp;You should have the DFU/Boot0 button pressed while you do this.
5. **Now you can release the DFU / Boot0 button**

![](https://cdn-learn.adafruit.com/assets/assets/000/103/225/medium800/sensors_PXL_20210629_174607633.jpg?1624988907)

Because there are several incompatible versions of the Kaluga TFT display, the bootloader's screen may appear incorrectly or not at all. This does not affect its operation.

### Check for a new serial / COM port
 **On Windows check the Device manager&nbsp;** - you will see a COM port, for example here its COM88. You may also see another "Other device" called ESP32-S2

It's best to do this with no other dev boards plugged in so you don't get confused about which COM port is the ESP32-S2

![install_uf2_bootloader_Windows_Device_Manager.png](https://cdn-learn.adafruit.com/assets/assets/000/101/577/medium640/install_uf2_bootloader_Windows_Device_Manager.png?1618614418)

On Mac/Linux you will need to find the tty name which lives under /dev

On Linux, try&nbsp; **ls** &nbsp; **/dev/ttyS\*** &nbsp;for example, to find the matching serial port name. In this case it shows up as&nbsp; **/dev/ttyS87**. If you don't see it listed try&nbsp; **ls /dev/ttyA\*&nbsp;** on some Linux systems it might show up like&nbsp; **/dev/ttyACM0**

On Mac, try&nbsp; **ls /dev/cu.usbmodem\*** &nbsp;for example, to find the matching serial port name. In this case, it shows up as&nbsp; **/dev/cu.usbmodem01**

It's best to do this with no other dev boards plugged in so you don't get confused about which serial port is the ESP32-S2

![install_uf2_bootloader_adafruit_products_image_(4).png](https://cdn-learn.adafruit.com/assets/assets/000/101/578/medium640/install_uf2_bootloader_adafruit_products_image_%284%29.png?1618614511)

![install_uf2_bootloader_adafruit_products_Metro_ESP_32_bootloader_serial_name.png](https://cdn-learn.adafruit.com/assets/assets/000/101/579/medium640/install_uf2_bootloader_adafruit_products_Metro_ESP_32_bootloader_serial_name.png?1618614539)

## Step 3 Option A. Use the Web Serial ESPTool to upload

The WebSerial ESPTool was designed to be a web-capable option for programming ESP32-S2 boards. It allows you to erase the contents of the microcontroller and program up to 4 files at different offsets.

Yellow: Web Serial support requires Firefox 151 or a Chrome-89-based browser (or higher).

### Enable Web Serial on Older Versions of Chrome
Primary: As of Chrome 89, Web Serial is already enabled, so this step is only necessary on older browsers. Firefox 151 and higher are ok, you can skip this.

Visit **chrome://flags** &nbsp;from within Chrome. Find and enable the&nbsp; **Experimental Web Platform features**

**Restart Chrome**

![install_uf2_bootloader_adafruit_products_Enable_Features.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/562/medium640/install_uf2_bootloader_adafruit_products_Enable_Features.jpg?1618608210)

### Connecting
In the **Chrome browser** visit [https://adafruit.github.io/Adafruit\_WebSerial\_ESPTool/](https://adafruit.github.io/Adafruit_WebSerial_ESPTool/). It should look like the image to the left.

![camera_Screen_Shot_2022-04-04_at_3.07.03_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/625/medium640/camera_Screen_Shot_2022-04-04_at_3.07.03_PM.png?1649366866)

Press the&nbsp; **Connect** &nbsp;button in the top right of the web browser. You will get a pop up asking you to select the COM or Serial port.

**Remember, you should remove all other USB devices so&nbsp;**** _only_&nbsp;the ESP32-S2 board is attached, that way there's no confusion over multiple ports!**

On some systems, such as MacOS, there may be additional system ports that appear in the list.

![camera_Screen_Shot_2022-04-04_at_3.12.49_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/626/medium640/camera_Screen_Shot_2022-04-04_at_3.12.49_PM.png?1649366909)

The Javascript code will now try to connect to the ROM bootloader. It may timeout for a bit until it succeeds. On success, you will see that it is&nbsp; **Connected** &nbsp;and will print out a unique&nbsp; **MAC address** &nbsp;identifying the board.

![camera_Screen_Shot_2022-04-04_at_3.16.00_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/627/medium640/camera_Screen_Shot_2022-04-04_at_3.16.00_PM.png?1649367045)

Once you have successfully connected, the command toolbar will appear.

![camera_Screen_Shot_2022-04-04_at_3.18.26_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/628/medium640/camera_Screen_Shot_2022-04-04_at_3.18.26_PM.png?1649367078)

### Erasing the Contents

If you would like to erase the entire flash area so that you can start with a clean slate, you can use the erase feature. We recommend doing this if you are having issues.

To erase the contents, click the Erase button. You will be prompted whether you want to continue. Click OK to continue or if you changed your mind, just click cancel.

![camera_Screen_Shot_2022-04-04_at_3.19.58_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/629/medium640/camera_Screen_Shot_2022-04-04_at_3.19.58_PM.png?1649367120)

### Programming the Microcontroller

Programming the microcontroller can be done with up to 4 files at different locations, but with the&nbsp; **tinyuf2combo** &nbsp; **BIN** &nbsp;file, which you should have downloaded under **Step 1** on this&nbsp;page, you only need to use 1 file.

You can click on&nbsp; **Choose a file...** &nbsp;from any of the available buttons. It will only attempt to program buttons with a file and a unique location. Then select the Adafruit CircuitPython&nbsp; **BIN** &nbsp;files (not the UF2 file!)

Verify that the&nbsp; **Offset** &nbsp;box next to the file location you used is 0x0.

![install_uf2_bootloader_adafruit_products_image_(3).png](https://cdn-learn.adafruit.com/assets/assets/000/101/574/medium640/install_uf2_bootloader_adafruit_products_image_%283%29.png?1618608677)

Once you choose a file, the button text will change to match your filename. You can then select the Program button to start flashing.

![camera_Screen_Shot_2022-04-04_at_3.22.13_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/630/medium640/camera_Screen_Shot_2022-04-04_at_3.22.13_PM.png?1649367171)

A progress bar will appear and after a minute or two, you will have written the firmware.

![camera_Screen_Shot_2022-04-04_at_3.23.42_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/110/631/medium640/camera_Screen_Shot_2022-04-04_at_3.23.42_PM.png?1649367200)

Info: 

## Step 3. Option B. Use esptool.py to upload (for advanced users)

Once you have entered ROM bootloader mode, you can then&nbsp;[use Espressif's esptool program](https://github.com/espressif/esptool)&nbsp;to communicate with the chip!&nbsp;`esptool`&nbsp;is the 'official' programming tool and is the most common/complete way to program an ESP chip.

### Install ESPTool.py

You will need to use the command line / Terminal to install and run&nbsp;`esptool`.

You will also need to have pip and Python installed (any version!)

Install the latest version using pip (you may be able to run&nbsp;`pip`&nbsp;without the&nbsp;`3`&nbsp;depending on your setup):

`pip3 install --upgrade esptool`

Then, you can run:

`esptool.py`

### Test the Installation

Run&nbsp;`esptool.py`&nbsp;in a new terminal/command line and verify you get something like the below:

![](https://cdn-learn.adafruit.com/assets/assets/000/101/580/medium800/install_uf2_bootloader_adafruit_products_image_%282%29.png?1618614758)

Info: 

Run the following command, replacing the identifier after&nbsp;`--port`&nbsp;with the&nbsp;`COMxx`,&nbsp;`/dev/cu.usbmodemxx`&nbsp;or&nbsp;`/dev/ttySxx`&nbsp;you found above.

`esptool.py --port COM88 chip_id`

You should get a notice that it connected over that port and found an ESP32-S2

![](https://cdn-learn.adafruit.com/assets/assets/000/101/581/medium800/install_uf2_bootloader_adafruit_products_image_%283%29.png?1618615988)

### Installing the Bootloader

Run this command and replace the serial port name with your matching port and the file you just downloaded

`esptool.py --port COM88 write_flash 0x0 tinyuf2_combo.bin`

Don't forget to change the `--port` name to match.

There might be a bit of a 'wait' when programming, where it doesn't seem like it's working. Give it a minute, it has to erase the old flash code which can cause it to seem like it's not running.

You'll finally get an output like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/101/548/medium800/install_uf2_bootloader_adafruit_products_image.png?1618598592)

## Step 4. Reset the board
Click the RESET button to launch the bootloader. You'll see a new disk drive on your computer with the name **KALUGA1BOOT**.

You're now ready to copy the CircuitPython UF2 on to the drive which will set up CircuitPython!

# Method 2: Flash an Arduino Sketch

This section outlines flashing an Arduino sketch onto your ESP32-S2 board, which automatically installs the UF2 bootloader as well.

## Arduino IDE Setup

If you don't already have the Arduino IDE installed, the first thing you will need to do is to download the latest release of the Arduino IDE. ESP32-S2 requires **version 1.8** &nbsp;or higher. Click the link to download the latest.

[Arduino IDE Download](https://www.arduino.cc/en/software)
After you have downloaded and installed **&nbsp;** the latest version of Arduino IDE, you will need to start the IDE&nbsp;and navigate to&nbsp;the&nbsp; **Preferences** &nbsp;menu. You can access it from the&nbsp; **File \> Preferences** menu in&nbsp;Windows&nbsp;or&nbsp;Linux, or the&nbsp; **Arduino \> Preferences** menu on&nbsp;OS X.

The **Preferences** window will open.

In the **Additional Boards Manager URLs** field, you'll want to add a new URL. The list of URLs is comma separated, and&nbsp;_you will only have to add each&nbsp;URL once._ The URLs point to index files that the Board Manager uses to build the list of available & installed boards.

Copy the following URL.

`https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json`

Add the URL to the the **Additional Boards Manager URLs** field (highlighted in red below).

![](https://cdn-learn.adafruit.com/assets/assets/000/107/290/medium800/install_uf2_bootloader_esp32_s2_Arduino_Template_RP2040_preferences_window.png?1639413677)

Click **OK** to save and close **Preferences**.

In the **Tools \> Boards** menu you should see the **ESP32 Arduino** menu. In the expanded menu, it should contain the ESP32 boards along with all the latest ESP32-S2 boards.

Now that your IDE is setup, you can continue on to loading the sketch.

## Load the Blink Sketch
In the **Tools \> Boards** menu you should see the **ESP32 Arduino** menu. In the expanded menu, look for the menu option for the **ESP32S2 Dev Module** , and click on it to choose it.

Open the Blink sketch by clicking through **File \> Examples \> 01.Basics \> Blink**.

![](https://cdn-learn.adafruit.com/assets/assets/000/107/291/medium800/install_uf2_bootloader_esp32_s2_Arduino_Template_RP2040_open_Blink.png?1639413760)

Once open, click Upload from the sketch window.

![](https://cdn-learn.adafruit.com/assets/assets/000/107/292/medium800/install_uf2_bootloader_esp32_s2_CP_Template_ESP32-S2_factory_reset_blink_upload.png?1639413852)

Once successfully uploaded, the little red LED will begin blinking once every second. At that point, you can now enter the bootloader.

# Adafruit OV5640 Camera Breakouts

## Install CircuitPython on Espressif Kaluga with TinyUF2

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your a Kaluga 1.3 board (a Kaluga 1.2 will NOT WORK).

[ Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/espressif_kaluga_1.3/)
![](https://cdn-learn.adafruit.com/assets/assets/000/118/508/medium800/adafruit_products_kaluga-booting.jpg?1676406858)

## Kaluga USB Connection

Neither of the two Micro USB connectors on the Kaluga provide access to the native USB connection used by CircuitPython. Instead, a USB breakout cable must be connected as follows:

- USB **+5V** (red) to Kaluga **+5V**
- USB **GND** (black) to Kaluga **GND**
- USB **D+** (green) to Kaluga **GPIO20**
- USB **D-** (white) to Kaluga **GPIO19**

### Advanced USB connection

Non-populated resistor positions R151 & R152 connect the "J10" micro-USB connector to native USB. By soldering in a 0-ohm link at these positions, you can use the J10 connector for native USB. Some photos in this guide show a board which has been modified in this way.

Click the **reset** button once, and then the **boot** button once when you see the **RGB status LED** turn purple (approximately half a second later). The second tap needs to happen while the LED is still purple.

Once successful, you will see the **RGB status LED(s)** turn green (highlighted in green above). If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

**Remember that unless you've modified your Kaluga, you have to use a USB breakout cable, not the built-in USB Micro-B ports!**

Info: 

You will see a new disk drive appear called **KALUGA1BOOT**.

![adafruit_products_Screenshot_2023-02-14_14-39-09.png](https://cdn-learn.adafruit.com/assets/assets/000/118/510/medium640/adafruit_products_Screenshot_2023-02-14_14-39-09.png?1676407341)

Drag the **adafruit-circuitpython-espressif\_kaluga\_1.3.uf2** file to **KALUGA1BOOT**

![adafruit_products_Screenshot_2023-02-14_14-41-05.png](https://cdn-learn.adafruit.com/assets/assets/000/118/511/medium640/adafruit_products_Screenshot_2023-02-14_14-41-05.png?1676407370)

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![adafruit_products_Screenshot_2023-02-14_14-44-19.png](https://cdn-learn.adafruit.com/assets/assets/000/118/512/medium640/adafruit_products_Screenshot_2023-02-14_14-44-19.png?1676407476)

# Adafruit OV5640 Camera Breakouts

## Espressif Kaluga Pinout

Danger: 

Warning: 

## Setting 'reserved PSRAM'

The 'reserved PSRAM' setting was discussed earlier, but here's a reminder now that you've got CircuitPython installed:

Edit the **settings.toml** file within the **CIRCUITPY** drive, creating it as an empty file if necessary. Add a line that says `CIRCUITPY_RESERVED_PSRAM=1048576`

The setting will become effective when the board is reset with the reset button. You can check it by opening the REPL and running the following lines:

```auto
Adafruit CircuitPython 8.0.0-rc.1 on 2023-01-30; Kaluga 1 with ESP32S2
>>> import espidf
>>> espidf.get_reserved_psram()
1048576
```

## Camera Module Connections

Take the assembled Kaluga board stack (all three boards) and attach the camera at the dedicated header, making sure the pins are inserted properly.

The camera pins are as follows (though in CircuitPython they also have meaningful names that should be used when available):

- **GPIO8** is **CAMERA\_SIOC** - the **SCL** pin of the camera
- **GPIO9** is **CAMERA\_SIOD** - the **SDA** pin of the camera
- **GPIO33** is **CAMERA\_PCLK** - the pixel clock of the camera
- **GPIO2** is **CAMERA\_VSYNC** - the vertical sync of the camera
- **GPIO3** is **CAMERA\_HREF** - the horizontal sync of the camera
- **GPIO1** is **CAMERA\_XCLK** - the input clock pin of the camera
- **GPIO36, 37, 41, 42, 39, 40, 21, 38** are **CAMERA\_DATA** - the 8 data pins of the camera

## LCD variants

There are at least 3 variants of the LCD board that ship with the Kaluga:

- st7789
- ili9341
- ili9341 with rotation=90

There are no markings to distinguish the three, so for demos that use the LCD you will need to try each variant until you find the one that works.

# Adafruit OV5640 Camera Breakouts

## LCD Mirror Demo

![](https://cdn-learn.adafruit.com/assets/assets/000/118/601/medium800thumb/adafruit_products_PXL_20230216_171315347.TS.mp4_2-opt.jpg?1676568244)

## Install & Use the Demo

First, make sure you can see the Kaluga **CIRCUITPY** drive and connect to the REPL. Open the REPL and double check that `import espcamera` works without showing an error. Then, copy one of the Adafruit software bundles to your device (the first appears below, more on subsequent pages). It will automatically reload and start displaying the image from the camera on the built-in LCD.

By clicking the BOOT button you can swap the camera between live mode & test pattern mode.

If the live mode image is black, remove the lens cap from the camera.

Click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the entire **lib folder** and the **code.py** file to your **CIRCUITPY** drive.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/OV5640_Breakout/CircuitPython_Kaluga-lcd-mirror/code.py

![Folder](https://adafruit.github.io/Adafruit_Learning_System_Guides/OV5640_Breakout_CircuitPython_Kaluga-lcd-mirror.png )

## Code Walkthrough

First, the code performs necessary imports and sets up the display. It will stop if it detects the necessary reserved PSRAM setting is not active:

```auto
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

"""
This demo is designed for the Kaluga development kit version 1.3 with the
ILI9341 display. It requires CircuitPython 8.

To fix the MemoryError when creating a Camera object, Place the line
```toml
CIRCUITPY_RESERVED_PSRAM=1048576
```
in the file **CIRCUITPY/settings.toml** and restart.
"""

import struct

import board
import busio
import keypad
import displayio
import fourwire
import espcamera
import espidf

print("Initializing display")
displayio.release_displays()
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
display_bus = fourwire.FourWire(
    spi,
    command=board.LCD_D_C,
    chip_select=board.LCD_CS,
    reset=board.LCD_RST,
    baudrate=80_000_000,
)
_INIT_SEQUENCE = (
    b"\x01\x80\x80"  # Software reset then delay 0x80 (128ms)
    b"\xEF\x03\x03\x80\x02"
    b"\xCF\x03\x00\xC1\x30"
    b"\xED\x04\x64\x03\x12\x81"
    b"\xE8\x03\x85\x00\x78"
    b"\xCB\x05\x39\x2C\x00\x34\x02"
    b"\xF7\x01\x20"
    b"\xEA\x02\x00\x00"
    b"\xc0\x01\x23"  # Power control VRH[5:0]
    b"\xc1\x01\x10"  # Power control SAP[2:0];BT[3:0]
    b"\xc5\x02\x3e\x28"  # VCM control
    b"\xc7\x01\x86"  # VCM control2
    b"\x36\x01\x40"  # Memory Access Control
    b"\x37\x01\x00"  # Vertical scroll zero
    b"\x3a\x01\x55"  # COLMOD: Pixel Format Set
    b"\xb1\x02\x00\x18"  # Frame Rate Control (In Normal Mode/Full Colors)
    b"\xb6\x03\x08\x82\x27"  # Display Function Control
    b"\xF2\x01\x00"  # 3Gamma Function Disable
    b"\x26\x01\x01"  # Gamma curve selected
    b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00"  # Set Gamma
    b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F"  # Set Gamma
    b"\x11\x80\x78"  # Exit Sleep then delay 0x78 (120ms)
    b"\x29\x80\x78"  # Display on then delay 0x78 (120ms)
)

display = displayio.Display(display_bus, _INIT_SEQUENCE, width=320, height=240)

if espidf.get_reserved_psram() < 1047586:
    print("""Place the following line in CIRCUITPY/settings.toml, then hard-reset the board:

CIRCUITPY_RESERVED_PSRAM=1048576
""")
    raise SystemExit
```

Next, the camera object is created. Since this board has a dedicated camera header, there are shorthand names in the **board** module to name the pins; see the Espressif Overview page for how to adapt the example to other boards.

```auto
print("Initializing camera")
cam = espcamera.Camera(
    data_pins=board.CAMERA_DATA,
    external_clock_pin=board.CAMERA_XCLK,
    pixel_clock_pin=board.CAMERA_PCLK,
    vsync_pin=board.CAMERA_VSYNC,
    href_pin=board.CAMERA_HREF,
    pixel_format=espcamera.PixelFormat.RGB565,
    frame_size=espcamera.FrameSize.QVGA,
    i2c=board.I2C(),
    external_clock_frequency=20_000_000,
    framebuffer_count=2)
```

The **BOOT** button (also known as IO0) can be used when the demo is running to turn the test pattern on and off:

```auto
k = keypad.Keys([board.IO0], value_when_pressed=False)
```

To improve the refresh rate of the display, the demo directly sends data to the LCD rather than going through displayio. The program's forever-loop repeatedly fetches a frame and then sends its data to the LCD over the fourwire bus:

```auto
ow = (display.width - cam.width) // 2
oh = (display.height - cam.height) // 2
display_bus.send(42, struct.pack(">hh", ow, cam.width + ow - 1))
display_bus.send(43, struct.pack(">hh", oh, cam.height + ow - 1))

while True:
    if (e := k.events.get()) is not None and e.pressed:
        cam.colorbar = not cam.colorbar

    frame = cam.take(1)
    display_bus.send(44, frame)
```

### USB Type A Plug Breakout Cable with Premium Female Jumpers

[USB Type A Plug Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4448)
If you'd like to connect a USB-capable chip to your USB host, this cable will make the task very simple. **There is no converter chip in this cable!** Its basically a plain USB cable that's cut in half and with jumper sockets on the power and data lines. Simple to use,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4448)
[Related Guides to the Product](https://learn.adafruit.com/products/4448/guides)
![Angled shot of Black, USB-A plug cable with four socket jumpers.](https://cdn-shop.adafruit.com/640x480/4448-01.jpg)

### USB Extension Cable - 3 meters / 10 ft long

[USB Extension Cable - 3 meters / 10 ft long](https://www.adafruit.com/product/993)
This handy USB extension cable will make it easy for you to extend your USB cable when it won't reach. The connectors are gold plated for years of reliability. We use these handy cables all over our factory and homes. Cable is standard "Adafruit black".  
  
Cable length:...

In Stock
[Buy Now](https://www.adafruit.com/product/993)
[Related Guides to the Product](https://learn.adafruit.com/products/993/guides)
![USB Type A Extension Cable](https://cdn-shop.adafruit.com/640x480/993-03.jpg)

# Adafruit OV5640 Camera Breakouts

## ASCII Mirror Demo

![](https://cdn-learn.adafruit.com/assets/assets/000/118/573/medium800thumb/adafruit_products_vokoscreenNG-2023-02-15_14-05-51-opt.jpg?1676491702)

## Install & Use the Demo

First, make sure you can see the Kaluga **CIRCUITPY** drive and connect to the REPL. Open the REPL and double check that `import espcamera` works without showing an error. Then, copy the correct bundle to your device. It will automatically reload and start displaying the image from the camera on the serial REPL as lo-fi ASCII art.

By clicking the BOOT button you can swap the camera between live mode & test pattern mode.

You will need to use a terminal program that understands ANSI escape codes such as **screen** or **tio**.

If the live mode image is black, remove the lens cap from the camera.

Click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the entire **lib folder** and the **code.py** file to your **CIRCUITPY** drive.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/OV5640_Breakout/CircuitPython_Kaluga-ascii-mirror/code.py

![Folder](https://adafruit.github.io/Adafruit_Learning_System_Guides/OV5640_Breakout_CircuitPython_Kaluga-lcd-mirror.png )

After code that is familiar from the LCD demo is the start of the code specific to the ASCII art part of the program:

- "chars" holds the ASCII characters to use, arranged from darkest to lightest (the demo is intended to be run on a terminal with a dark background color).
- "remap" is a 256-element look-up table from the raw brightness value to a character
- "width" is just a shorthand way to refer to the camera's width property
- "row" contains one byte for every 2 characters across the image, which gives a width of 80 characters, a standard terminal width.

Finally, the whole screen is cleared.

```auto
chars = b" .:-=+*#%@"
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
width = cam.width
row = bytearray(width//2)

sys.stdout.write("\033[2J")
```

The forever loop grabs a fresh frame and then converts it to ASCII.

Every 5th row of the input image is used, giving 24 lines of height; every 2nd column is taken, given 80 characters of width.

First, an escape code is printed to move the cursor to the start of the correct line.

Then, the ASCII characters for the row are calculated by using the **remap** array

Finally, the row is written, followed by an escape code indicating "clear to end of line".

When the whole thing is written, the remainder of the screen (if any) is cleared.

```auto
while True:
    if (e := k.events.get()) is not None and e.pressed:
        cam.colorbar = not cam.colorbar

    frame = cam.take(1)

    for j in range(0, cam.height, 5):
        sys.stdout.write(f"\033[{j//5}H")
        for i in range(cam.width // 2):
            row[i] =  remap[frame[width * j + 2 * i]]
        sys.stdout.write(row)
        sys.stdout.write("\033[K")
    sys.stdout.write("\033[J")
```

### USB Type A Plug Breakout Cable with Premium Female Jumpers

[USB Type A Plug Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4448)
If you'd like to connect a USB-capable chip to your USB host, this cable will make the task very simple. **There is no converter chip in this cable!** Its basically a plain USB cable that's cut in half and with jumper sockets on the power and data lines. Simple to use,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4448)
[Related Guides to the Product](https://learn.adafruit.com/products/4448/guides)
![Angled shot of Black, USB-A plug cable with four socket jumpers.](https://cdn-shop.adafruit.com/640x480/4448-01.jpg)

### USB Extension Cable - 3 meters / 10 ft long

[USB Extension Cable - 3 meters / 10 ft long](https://www.adafruit.com/product/993)
This handy USB extension cable will make it easy for you to extend your USB cable when it won't reach. The connectors are gold plated for years of reliability. We use these handy cables all over our factory and homes. Cable is standard "Adafruit black".  
  
Cable length:...

In Stock
[Buy Now](https://www.adafruit.com/product/993)
[Related Guides to the Product](https://learn.adafruit.com/products/993/guides)
![USB Type A Extension Cable](https://cdn-shop.adafruit.com/640x480/993-03.jpg)

# Adafruit OV5640 Camera Breakouts

## JPEG Capture Demo

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/118/600/medium800/adafruit_products_img0023.jpg?1676568223)

## Install & Use the Demo

For this demo, you'll need to attach an SD card breakout to your Kaluga using the following connections:

- **5V** to **5V** , or **3V** to **3V3** (depends on breakout)
- **GND** to **GND**
- **CLK** to **GPIO18**
- **MOSI** to **GPIO14**
- **MISO** to **GPIO10**
- **CS** to **GPIO12**

Now, insert a CircuitPython-supported, formatted SD card. Supported formats include FAT16 and FAT32, but not exFAT.

Next, copy the correct bundle to your device. It will automatically reload and start displaying the image from the camera on the LCD.

Click the boot button to capture an image in JPEG format to the SD card.

Click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the entire **lib** folder and the **code.py** file to your **CIRCUITPY** drive.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/OV5640_Breakout/CircuitPython_Kaluga-jpeg/code.py

![Folder](https://adafruit.github.io/Adafruit_Learning_System_Guides/OV5640_Breakout_CircuitPython_Kaluga-lcd-mirror.png )

## Code walkthrough

These functions help with opening the next numbered image in a sequence, so that files are named **img0000**  **img0001** etc.

```auto
def exists(filename):
    try:
        os.stat(filename)
        return True
    except OSError:
        return False


_image_counter = 0


def open_next_image(extension="jpg"):
    global _image_counter  # pylint: disable=global-statement
    while True:
        filename = f"/sd/img{_image_counter:04d}.{extension}"
        _image_counter += 1
        if exists(filename):
            continue
        print("#", filename)
        return open(filename, "wb")
```

Inside the forever loop, when the shutter button is pressed, these lines change the camera to JPEG mode, capture an image to the SD card, and then set the camera back to RGB mode:

```auto
if (e := k.events.get()) is not None and e.pressed:
        cam.reconfigure(
            pixel_format=espcamera.PixelFormat.JPEG,
            frame_size=espcamera.FrameSize.SVGA,
        )
        frame = cam.take(1)
        if isinstance(frame, memoryview):
            jpeg = frame
            print(f"Captured {len(jpeg)} bytes of jpeg data")

            with open_next_image() as f:
                f.write(jpeg)
        cam.reconfigure(
            pixel_format=espcamera.PixelFormat.RGB565,
            frame_size=espcamera.FrameSize.QVGA,
        )
```

### USB Type A Plug Breakout Cable with Premium Female Jumpers

[USB Type A Plug Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4448)
If you'd like to connect a USB-capable chip to your USB host, this cable will make the task very simple. **There is no converter chip in this cable!** Its basically a plain USB cable that's cut in half and with jumper sockets on the power and data lines. Simple to use,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4448)
[Related Guides to the Product](https://learn.adafruit.com/products/4448/guides)
![Angled shot of Black, USB-A plug cable with four socket jumpers.](https://cdn-shop.adafruit.com/640x480/4448-01.jpg)

### USB Extension Cable - 3 meters / 10 ft long

[USB Extension Cable - 3 meters / 10 ft long](https://www.adafruit.com/product/993)
This handy USB extension cable will make it easy for you to extend your USB cable when it won't reach. The connectors are gold plated for years of reliability. We use these handy cables all over our factory and homes. Cable is standard "Adafruit black".  
  
Cable length:...

In Stock
[Buy Now](https://www.adafruit.com/product/993)
[Related Guides to the Product](https://learn.adafruit.com/products/993/guides)
![USB Type A Extension Cable](https://cdn-shop.adafruit.com/640x480/993-03.jpg)

# Adafruit OV5640 Camera Breakouts

## espcamera documentation

# Adafruit OV5640 Camera Breakouts

## Raspberry Pi RP2040 Overview

The CircuitPython **imagecapture** module is available on most supported RP2040 boards including the Raspberry Pi Pico.

This low-level module works together with a camera-specific high-level module such as **adafruit\_ov5640** , to set up the camera.

## Image storage

A 320×240 image at 16bpp takes about 150kB of RAM to store. The RP2040 has this much storage, but as memory can become fragmented, it's generally a good idea to allocate storage for the image just once at the beginning of your program. As shown in the example, a `displayio.Bitmap` object can be used for this.

## Pin choices

By selecting appropriate pins, you can use the **adafruit\_ov5640** library on other boards with the RP2040 microcontroller:

- **xclk** , **pclk** , **vsync** , **href** : Free choice of any pin
- **reset** , **shutdown** : Free choice of any pin. Can omit one or both, but the initialization sequence is less reliable.
- **data\_pins** : Any 8 sequential pins in GPIO ordering (e.g., GPIO2..GPIO9).

By convention, if a board has an integrated camera or a dedicated camera connector, the following will exist in the **board** module:

- **CAMERA\_SIOC** - the **SCL** pin of the camera
- **CAMERA\_SIOD** - the **SDA** pin of the camera
- **CAMERA\_PCLK** - the pixel clock of the camera
- **CAMERA\_VSYNC** - the vertical sync of the camera
- **CAMERA\_HREF** - the horizontal sync of the camera
- **CAMERA\_XCLK** - the input clock pin of the camera
- **CAMERA\_DATA** - the 8 data pins of the camera

Continue to the next page to see how to use the camera module with the Raspberry Pi Pico module on a permaproto board. Be prepared to do quite a bit of wiring & soldering for the required connections.

# Adafruit OV5640 Camera Breakouts

## Raspberry Pi Pico Usage

## Camera connections

For the Raspberry Pi Pico setup shown in these examples, wire the following connections:

- OV5640 **GND** to Pi Pico **GND**
- OV5640 **3V** to Pi Pico **3V3**
- OV5640 **SDA** to Pi Pico **GP8**
- OV5640 **SCL** to Pi Pico **GP9**
- OV5640 **HS** to Pi Pico **GP21**
- OV5640 **VS** to Pi Pico **GP7**
- OV5640 **XC** to Pi Pico **GP20**
- OV5640 **PC** to Pi Pico **GP11**
- OV5640 **D2..D9** to Pi Pico **GP12..GP19**
- OV5640 **RT** to Pi Pico **GP10**

The pull-up resistors shown on GP8 and GP9 are not required for Adafruit's OV5640 camera break-out board but may be required for other camera breakout boards.

Primary: 

## LCD connections

For the LCD display, make the following connections:

- Display **V+** to Pi Pico **VBUS**
- Display **GND** to Pi Pico **GND**
- Display **CK&nbsp;** to **Pi Pico GP2** 
- Display **SI&nbsp;** to **Pi Pico GP3** 
- Display **DC&nbsp;** to **Pi Pico GP0** 
- Display **TC** to Pi Pico **GP1**

![](https://cdn-learn.adafruit.com/assets/assets/000/118/557/medium800/adafruit_products_IMG_0694r.jpg?1676490462)

Here's a diagram of the many connections required; rather than trying to trace out the connections from this image, though, it's better to use the bullet list of connections above.

![](https://cdn-learn.adafruit.com/assets/assets/000/120/123/medium800/adafruit_products_pico-camera-lcd_bb.png?1680808047)

Depending whether you are using the optional LCD display, continue on to the LCD or ASCII mirror demo on the following pages.

# Adafruit OV5640 Camera Breakouts

## ASCII Mirror Demo

![](https://cdn-learn.adafruit.com/assets/assets/000/118/572/medium800thumb/adafruit_products_vokoscreenNG-2023-02-15_14-05-51-opt.jpg?1676491685)

## Install & Use the Demo

Click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the entire **lib folder** and the **code.py** file to your **CIRCUITPY** drive.

You will need to use a terminal program that understands ANSI escape codes such as `screen` or `tio`. Connect to your device using a compatible terminal program and you will see the image captured as lo-fi ASCII art.

If the live mode image is black, remove the lens cap from the camera.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/OV5640_Breakout/CircuitPython_Pico-ascii-mirror/code.py

![Folder](https://adafruit.github.io/Adafruit_Learning_System_Guides/OV5640_Breakout_CircuitPython_Pico-ascii-mirror.png )

After code that is familiar from the LCD demo is the start of the code specific to the ASCIi art part of the program:

- "chars" holds the ASCII characters to use, arranged from darkest to lightest (the demo is intended to be run on a terminal with a dark background color).
- "remap" is a 256-element look-up table from the raw brightness value to a character
- "width" is just a short-hand way to refer to the camera's width property
- "row" contains one byte for every 2 characters across the image, which gives a width of 80 characters, a standard terminal width.

Finally, the whole screen is cleared.

```auto
chars = b" .:-=+*#%@"
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
width = cam.width
row = bytearray(width//2)

sys.stdout.write("\033[2J")
```

The forever loop grabs a fresh frame and then converts it to ASCII.

Every 5th row of the input image is used, giving 24 lines of height; every 2nd column is taken, given 80 characters of width.

First, an escape code is printed to move the cursor to the start of the correct line.

Then, the ASCII characters for the row are calculated by using the `remap` array

Finally, the row is written, followed by an escape code indicating "clear to end of line".

When the whole thing is written, the remainder of the screen (if any) is cleared.

```auto
sys.stdout.write("\033[2J")
while True:
    cam.capture(buf)
    for j in range(0, cam.height, 2):
        sys.stdout.write(f"\033[{j//2}H")
        for i in range(cam.width):
            row[i] = remap[buf[2 * (width * j + i)]]
        sys.stdout.write(row)
        sys.stdout.write("\033[K")
    sys.stdout.write("\033[J")
    time.sleep(0.1)
```

### USB Type A Plug Breakout Cable with Premium Female Jumpers

[USB Type A Plug Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4448)
If you'd like to connect a USB-capable chip to your USB host, this cable will make the task very simple. **There is no converter chip in this cable!** Its basically a plain USB cable that's cut in half and with jumper sockets on the power and data lines. Simple to use,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4448)
[Related Guides to the Product](https://learn.adafruit.com/products/4448/guides)
![Angled shot of Black, USB-A plug cable with four socket jumpers.](https://cdn-shop.adafruit.com/640x480/4448-01.jpg)

### USB Extension Cable - 3 meters / 10 ft long

[USB Extension Cable - 3 meters / 10 ft long](https://www.adafruit.com/product/993)
This handy USB extension cable will make it easy for you to extend your USB cable when it won't reach. The connectors are gold plated for years of reliability. We use these handy cables all over our factory and homes. Cable is standard "Adafruit black".  
  
Cable length:...

In Stock
[Buy Now](https://www.adafruit.com/product/993)
[Related Guides to the Product](https://learn.adafruit.com/products/993/guides)
![USB Type A Extension Cable](https://cdn-shop.adafruit.com/640x480/993-03.jpg)

# Adafruit OV5640 Camera Breakouts

## LCD Mirror Demo

![](https://cdn-learn.adafruit.com/assets/assets/000/118/575/medium800/adafruit_products_IMG_0693r.jpg?1676492617)

## Install & Use the Demo

Click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the entire **lib folder** and the **code.py** file to your **CIRCUITPY** drive.

If the live mode image is black, remove the lens cap from the camera.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/OV5640_Breakout/CircuitPython_Pico-lcd-mirror/code.py

![Folder](https://adafruit.github.io/Adafruit_Learning_System_Guides/OV5640_Breakout_CircuitPython_Pico-lcd-mirror.png )

## Code Walkthrough

First, the code performs necessary imports and sets up the display.

```auto
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
This demo is designed for the Raspberry Pi Pico. with 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

# Set up the display (You must customize this block for your display!)
displayio.release_displays()
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3)
display_bus = fourwire.FourWire(spi, command=board.GP0, chip_select=board.GP1, reset=None)
display = adafruit_st7789.ST7789(display_bus, width=240, height=240, rowstart=80, rotation=0)
```

Next, the camera object is created and configured.

```auto
print("construct bus")
bus = busio.I2C(board.GP9, board.GP8)
print("construct camera")
reset = digitalio.DigitalInOut(board.GP10)
cam = adafruit_ov5640.OV5640(
    bus,
    data_pins=(
        board.GP12,
        board.GP13,
        board.GP14,
        board.GP15,
        board.GP16,
        board.GP17,
        board.GP18,
        board.GP19,
    ),
    clock=board.GP11,
    vsync=board.GP7,
    href=board.GP21,
    mclk=board.GP20,
    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
```

This demo integrates with displayio for display, so a bitmap object is needed:

```auto
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
```

The forever loop grabs a frame to the bitmap and then refreshes the display. It tracks the approximate refresh rate (FPS) of the demo; this demo achieves about 2fps due mostly to the overhead of displayio & communication with the display.

```auto
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
```

# Adafruit OV5640 Camera Breakouts

## adafruit_ov5640 documentation

# Adafruit OV5640 Camera Breakouts

## Downloads

## Files

- [OV5640 Datasheet](https://cdn-learn.adafruit.com/assets/assets/000/118/306/original/ov5640_datasheet.pdf?1675869959)
- [OV5640 Register Datasheet](https://cdn-learn.adafruit.com/assets/assets/000/118/994/original/OV5640_datasheet.pdf?1677598686)
- [OV5640 Firmware User Guide](https://cdn-learn.adafruit.com/assets/assets/000/126/084/original/ov5640-firmware-user-guide.pdf?1700151367)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-OV5640-Camera-Breakout-PCB)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20OV5640%20Camera%20Breakout.fzpz)

## Schematic and Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/118/304/medium800/adafruit_products_cam_schem.png?1675865865)

![](https://cdn-learn.adafruit.com/assets/assets/000/118/305/medium800/adafruit_products_cam_fab.png?1675865872)


## Primary Products

### Adafruit OV5640 Camera Breakout - 120 Degree Lens

[Adafruit OV5640 Camera Breakout - 120 Degree Lens](https://www.adafruit.com/product/5673)
Hobby-level microcontrollers are finally getting big and powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output,...

In Stock
[Buy Now](https://www.adafruit.com/product/5673)
[Related Guides to the Product](https://learn.adafruit.com/products/5673/guides)
### Adafruit OV5640 Camera Breakout - 120 Degree Lens with Autofocus

[Adafruit OV5640 Camera Breakout - 120 Degree Lens with Autofocus](https://www.adafruit.com/product/5838)
Hobby-level microcontrollers are finally getting big and powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output,...

In Stock
[Buy Now](https://www.adafruit.com/product/5838)
[Related Guides to the Product](https://learn.adafruit.com/products/5838/guides)
### Adafruit OV5640 Camera Breakout - 120 Degree Low Distortion

[Adafruit OV5640 Camera Breakout - 120 Degree Low Distortion](https://www.adafruit.com/product/5839)
Hobby-level microcontrollers are finally getting big and powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output,...

In Stock
[Buy Now](https://www.adafruit.com/product/5839)
[Related Guides to the Product](https://learn.adafruit.com/products/5839/guides)
### Adafruit OV5640 Camera Breakout - 72 Degree Lens with Autofocus

[Adafruit OV5640 Camera Breakout - 72 Degree Lens with Autofocus](https://www.adafruit.com/product/5840)
Hobby-level microcontrollers are finally getting big and powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5840)
[Related Guides to the Product](https://learn.adafruit.com/products/5840/guides)
### Adafruit OV5640 Camera Breakout - 160 Degree Wide Angle

[Adafruit OV5640 Camera Breakout - 160 Degree Wide Angle](https://www.adafruit.com/product/5841)
Hobby-level microcontrollers are finally getting big and powerful enough to start handling camera modules that historically would have required a full computer or FPGA to handle. The RP2040 and ESP32-Sx series of chips, for example, have enough pins to communicate with the 8-bit data output,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5841)
[Related Guides to the Product](https://learn.adafruit.com/products/5841/guides)

## Featured Products

### ESP32-S2 Kaluga Dev Kit featuring ESP32-S2 WROVER

[ESP32-S2 Kaluga Dev Kit featuring ESP32-S2 WROVER](https://www.adafruit.com/product/4729)
The **ESP32-S2-Kaluga-1** kit is a full featured development kit by Espressif for the ESP32-S2 that comes with everything but the kitchen sink! From TFTs to touch panels, this dev board has it all. Espressif designed this kit to demonstrate the ESP32-S2’s human-computer...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4729)
[Related Guides to the Product](https://learn.adafruit.com/products/4729/guides)
### Raspberry Pi Pico RP2040

[Raspberry Pi Pico RP2040](https://www.adafruit.com/product/4864)
The Raspberry Pi foundation changed single-board computing [when they released the Raspberry Pi computer](https://www.raspberrypi.org/archives/723), now they're ready to do the same for microcontrollers with the release of the brand new **Raspberry Pi Pico**. This...

In Stock
[Buy Now](https://www.adafruit.com/product/4864)
[Related Guides to the Product](https://learn.adafruit.com/products/4864/guides)
### USB Type A Plug Breakout Cable with Premium Female Jumpers

[USB Type A Plug Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4448)
If you'd like to connect a USB-capable chip to your USB host, this cable will make the task very simple. **There is no converter chip in this cable!** Its basically a plain USB cable that's cut in half and with jumper sockets on the power and data lines. Simple to use,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4448)
[Related Guides to the Product](https://learn.adafruit.com/products/4448/guides)
### USB Extension Cable - 3 meters / 10 ft long

[USB Extension Cable - 3 meters / 10 ft long](https://www.adafruit.com/product/993)
This handy USB extension cable will make it easy for you to extend your USB cable when it won't reach. The connectors are gold plated for years of reliability. We use these handy cables all over our factory and homes. Cable is standard "Adafruit black".  
  
Cable length:...

In Stock
[Buy Now](https://www.adafruit.com/product/993)
[Related Guides to the Product](https://learn.adafruit.com/products/993/guides)
### Adafruit Perma-Proto Full-sized Breadboard PCB - 3 Pack!

[Adafruit Perma-Proto Full-sized Breadboard PCB - 3 Pack!](https://www.adafruit.com/product/590)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: it's always crummy quality, with pads that flake off and no labeling. Then we thought about how people **actually** prototype - usually starting with a solderless breadboard and then...

In Stock
[Buy Now](https://www.adafruit.com/product/590)
[Related Guides to the Product](https://learn.adafruit.com/products/590/guides)
### 4GB Blank SD/MicroSD Memory Card

[4GB Blank SD/MicroSD Memory Card](https://www.adafruit.com/product/102)
Add mega-storage in a jiffy using this 4&nbsp;GB micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters! Preformatted to FAT so it works out of the box with our projects. Tested and works great with our [Wave...](http://www.adafruit.com/products/94)

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/102)
[Related Guides to the Product](https://learn.adafruit.com/products/102/guides)
### MicroSD card breakout board+

[MicroSD card breakout board+](https://www.adafruit.com/product/254)
Not just a simple breakout board, this microSD adapter goes the extra mile - designed for ease of use.

- Onboard 5v-\>3v regulator provides 150mA for power-hungry cards
- 3v level shifting means you can use this with ease on either 3v or 5v systems
- Uses a proper level...

In Stock
[Buy Now](https://www.adafruit.com/product/254)
[Related Guides to the Product](https://learn.adafruit.com/products/254/guides)

## Related Guides

- [Breadboards for Beginners](https://learn.adafruit.com/breadboards-for-beginners.md)
- [Grand Central USB MIDI Controller in CircuitPython](https://learn.adafruit.com/grand-central-usb-midi-controller-in-circuitpython.md)
- [Native MP3 decoding on Arduino](https://learn.adafruit.com/native-mp3-decoding-on-arduino.md)
- [Micro SD Card Breakout Board Tutorial](https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial.md)
- [CircuitPython Hardware: SD Cards](https://learn.adafruit.com/micropython-hardware-sd-cards.md)
- [2.8" TFT Touchscreen](https://learn.adafruit.com/2-8-tft-touchscreen.md)
- [TTL Serial Camera](https://learn.adafruit.com/ttl-serial-camera.md)
- [Digital Circuits 6: An EPROM Emulator](https://learn.adafruit.com/digital-circuits-6-eprom-emulator.md)
- [Raspberry Pi Halloween Costume Detector](https://learn.adafruit.com/raspberry-pi-halloween-costume-detector.md)
- [Adafruit Metro M7 with microSD](https://learn.adafruit.com/adafruit-metro-m7-microsd.md)
- [Creating Custom LED Animations](https://learn.adafruit.com/creating-custom-led-animations.md)
- [Adafruit APDS9960 breakout](https://learn.adafruit.com/adafruit-apds9960-breakout.md)
- [Adafruit PCA9546 4-Channel I2C Multiplexer](https://learn.adafruit.com/adafruit-pca9546-4-channel-i2c-multiplexer.md)
- [LED Glasses Custom Animated Graphics with Sprites](https://learn.adafruit.com/led-glasses-custom-animated-graphics-with-sprites.md)
- [Getting Started with the nRF8001 Bluefruit LE Breakout](https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout.md)
