Main Content

Capture Images with Touch Sense Using ArduCam OV2640 Camera Module and Arduino Compatible ESP32 Hardware

This example shows how to design a touch-based image capture system using an Arduino ESP32 hardware and ArduCam OV2640 camera module. The example uses the ESP32 Touch Sense block from the Simulink® Support Package for Arduino® Hardware.

A capacitive touch pin on the ESP32 board acts as a non-mechanical trigger. When the pin detects a touch, the trigger activates the camera to capture an image and transmit the JPEG data over the SPI communication interface of the hardware. On the host computer, a MATLAB script reconstructs and displays the image in real time.

This example extends the workflow described in Capture Images Using ArduCam OV2640 Camera Module and ESP32 Hardware.

Required Hardware

  • Arduino-compatible ESP32 board. This example uses a ESP32-WROOM-DevKitC.

  • ArduCamOV2640 camera module.

  • USB cable.

Hardware Connections

Make the following pin connections between ESP32 board and ArduCam OV2640 camera.

    ESP32 Board Pin  |   ArduCam Pin
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
      CS/SS          |  GPIO 5
      MOSI (SDI)     |  GPIO 23
      MISO (SDO)     |  GPIO 19
      SCK            |  GPIO 18
      SDA            |  Connect to ESP32 I2C SDA pin
      SCL            |  Connect to ESP32 I2C SCL pin
      5V             |  5V
      GND            |  GND
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Supported Camera Resolutions on ESP32

For more information on the supported JPEG image resolutions when using a ESP32 board with ArduCam OV2640, see OV2640 Camera Sensor.

Configure Simulink Model

Open the arduinoESP32TouchSenseOV2640Camera model. The model is preconfigured for ESP32-WROOM (Arduino-compatible) board.

  1. In the Simulink toolstrip, on the Hardware tab, click Hardware Settings to open the Configuration Parameters dialog box.

  2. In the Hardware Implementation pane, select your ESP32 board from the Hardware board parameters drop-down list.

  3. In the Hardware board setting section, click Target hardware resources. Under Host-board connection, specify the port number of the port to which you connected your ESP32 board in the Host COM Port parameter. You can use the default baud rate of 921600 or change it according to your requirement. Click OK.

  4. Configure the SPI properties. Click Apply.

  5. On the Hardware tab of the Simulink model, in the Deploy section, click Apply > OK.

In this example, the ESP32 Touch Sense block acts as the input source to trigger capturing the image. The State output of the block provides the logical state of the board pin.

  • 1 — Touch detected on the pin. On receiving this signal, the OV2640 Camera Sensor block initiates the image capture.

  • 0 — No touch detected on the pin.

When a valid image capture is complete, Status port of the OV2640 Camera Sensor block outputs 0. The Enabled Subsystem block in the Transmit Image over Serial area sends image over serial port 0 on the ESP32 board.

View Captured Image

To display the image captured from the OV2640 camera module in a MATLAB figure window, open the jpegimageconstruct.m file attached with this example. In this file, specify the COM port number and baud rate that you specified in the model. Then run the code. The jpegimageconstruct function reads raw image data frames from the camera sensor module and coverts them to JPEG files. You can run the function and view the JPEG image in the figure window in real time.

See Also