Machine vision with low-cost camera modules


If you’re interested in embedded machine learning (TinyML) on the Arduino Nano 33 BLE Sense , you’ll have found a ton of on-board sensors — digital microphone, accelerometer, gyro, magnetometer, light, proximity, temperature, humidity and color — but realized that for vision you need to attach an external camera.

In this article, we will show you how to get image data from a low-cost VGA camera module. We’ll be using the Arduino_OVD767x library to make the software side of things simpler.

Hardware setup

To get started, you will need:

Arduino Nano 33 BLE Sense with headers
OV7670 CMOS VGA Camera Module
16x female to female jumper wires
A microUSB cable to connect to your Arduino

You can of course get a board without headers and solder instead, if that’s your preference.

The one downside to this setup is that (in module form) there are a lot of jumpers to connect. It’s not hard but you need to take care to connect the right cables at either end. You can use tape to secure the wires once things are done, lest one comes loose.

You need to connect the wires as follows:

Software setup

First, install the Arduino IDE or register for Arduino Create tools. Once you install and open your environment, the camera library is available in the library manager.

Install the Arduino IDE or register for Arduino Create

Tools > Manage Libraries and search for the OV767 library
Press the Install button

Now, we will use the example sketch to test the cables are connected correctly:

Examples > Arduino_OV767X > CameraCaptureRawBytes
Uncomment (remove the //) from line 48 to display a test pattern

Camera.testPattern();

Compile and upload to your board
Your Arduino is now outputting raw image binary over serial. To view this as an image we’ve included a special application to view the image output from the camera using Processing.

Processing is a simple programming environment that was created by graduate students at MIT Media Lab to make it easier to develop visually oriented applications with an emphasis on animation and providing users with instant feedback through interaction.

Install and open Processing  
Paste the CameraVisualizerRawBytes code into a Processing sketch
Edit line 31-37 to match the machine and serial port your Arduino is connected to
Hit the play button in Processing and you should see a test pattern (image update takes a couple of seconds):

If all goes well, you should see the striped test pattern above!

Next we will go back to the Arduino IDE and edit the sketch so the Arduino sends a live image from the camera in the Processing viewer: 

Return to the Arduino IDE
Comment out line 48 of the Arduino...

Top