OpenMV Development Guide

Develop wireless sensing applications with OpenMV cameras using Bluetooth Low Energy and Pareto Anywhere.

OpenMV development for wireless sensing

The TL;DR (Too Long; Didn't Read)

Learn how to wirelessly communicate machine vision and sensor data from OpenMV cameras.


What's OpenMV?
The OpenMV project aims to make building machine vision applications on high-performance, low-power microcontrollers easy.
Why wireless?
OpenMV cameras support Bluetooth Low Energy and WiFi, enabling untethered, battery-powered applications.
What's Pareto Anywhere?
Pareto Anywhere is open source IoT middleware that makes the data from just about anything usable.

Prerequisites

An OpenMV camera & IDE and, optionally, a Pareto Anywhere instance to make sense of the data

Connecting to the OpenMV camera   Step 1 of 3

Connect with the camera in the OpenMV IDE.


How to connect?
A USB connection from your PC powers the camera and enables serial communication with the IDE.
What's an IDE?
An Integrated Development Environment facilitates the development and testing of code, in this case directly on the OpenMV camera itself.
Connect to the OpenMV camera

Prepare the OpenMV camera Part 1

  Your OpenMV camera will likely ship ready to connect to the OpenMV IDE.

If in doubt, consult the official documentation to ensure that any firmware updates are installed, and that the hardware (jumpers, antennas, ...) is correctly configured.

Connect via USB cable Part 2

Choose a USB cable of sufficient length to allow the camera to be pointed at subjects of interest while tethered. Connect the camera first and then connect to your PC.

  Your OS may mount the camera as a USB storage device.

USB connector by camera model
OpenMV N6 USB-C
OpenMV AE3 USB-C
OpenMV Cam RT1062 USB-C
OpenMV Cam H7 Micro-USB
Arduino Nicla Vision Micro-USB

Connect in the OpenMV IDE Part 3

Run the OpenMV IDE on your PC. The default view should resemble the following. Annotations have been added to highlight key features.

OpenMV IDE

Click the Connect icon to connect to the camera via USB. The OpenMV IDE footer will display information about the device which is currently connected, in this case the OpenMV AE3 with the PAG7936 sensor.

OpenMV IDE footer

The camera can now be programmed via the OpenMV IDE, which is the subject of the next step.

Programming the OpenMV camera   Step 2 of 3

Run a Python script on the camera.


Why Python?
OpenMV uses the MicroPython operating system to run Python 3 scripts, which make working with machine vision algorithms much easier.
Any documentation?
Yes, consult the MicroPython for OpenMV documentation to learn more.
Program the OpenMV camera

Run helloworld.py Part 1

The OpenMV IDE should open a helloworld.py file by default. Click the Start (run script) icon at the bottom left of the IDE to run this script on the camera.

OpenMV helloworld.py

Observe the sensor snapshots updating live in the Frame Buffer and the frames per second calculations printed in the Serial Terminal.

  Click the Stop (halt script) icon at the bottom left of the IDE to stop a running script.

Run OpenMV examples Part 2

OpenMV blazeface_detector.py

Explore the extensive capabilities of the OpenMV camera by running the example scripts provided in the IDE. For instance, to test out the machine learning capabilities for face detection using TensorFlow, select the following:

File ➙ Examples ➙ Machine Learning ➙ TensorFlow ➙ blazeface_detector.py

  Some examples are camera-specific and might not run on yours!

Transmitting data   Step 3 of 3

Relay machine vision and sensor data wirelessly.


Using BLE?
Yes, Bluetooth Low Energy is ideal for battery-powered applications that require periodic transmission of a few bytes of data (ex: sensor readings).
Using WiFi?
Yes, WiFi facilitates the transmission of larger data (ex: images), with the tradeoff of higher energy consumption.
Transmit wireless data from an OpenMV camera

Transmit BLE advertising packets Part 1

The MicroPython bluetooth module includes a BLE class which provides a gap_advertise function to specify and transmit Bluetooth Low Energy advertising packets. The two key parameters of the gap_advertise function are:

  • interval_us   Interval, in microseconds, between advertising packet transmissions.
  • adv_data   The GAP* data, to include in the advertising packet.

* The Bluetooth Generic Access Profile (GAP) defines the advertising packet data structure.

The following Python script will advertise, every 0.5 seconds, OpenMV as the local name of the device.

import bluetooth, time

_ADV_PAYLOAD = [ 0x07, 0x09, ord('O'), ord('p'), ord('e'), ord('n'), ord('M'), ord('V') ]

ble = bluetooth.BLE()
ble.active(True)
ble.gap_advertise(500000, adv_data=bytearray(_ADV_PAYLOAD))

while(True):
    time.clock().tick()

Copy Ctrl-C and paste Ctrl-V the code into a new file in the OpenMV IDE and then click the Start (run script) icon.

Observe in Pareto Anywhere, or from any Bluetooth Low Energy scanning mobile app, a device named OpenMV. This is the camera advertising its name to any devices in range.

Replace the _ADV_PAYLOAD from the script above with any of the examples below, in order to transmit different types of data.

# Battery Level
# Advertising payload bytes:
# 0:   0x04 = Length (not including the length byte itself)
# 1:   0x16 = 16-bit service data (from GAP)
# 2-3: 0x2a19 = Battery Level service UUID (from GATT)*
# 4:   0x64 = Battery level as percentage (0x64 = 100%)
batteryPercentage = 100
_ADV_PAYLOAD = [ 0x04, 0x16, 0x19, 0x2a, batteryPercentage ]

* Payload uses little endian byte ordering: least-significant byte (LSB) first.

# Generic Level (ex: gauge reader)
# Advertising payload bytes:
# 0:   0x05 = Length (not including the length byte itself)
# 1:   0x16 = 16-bit service data (from GAP)
# 2-3: 0x2af9 = Generic Level service UUID (from GATT)*
# 4-5: 0x1234 = Generic level as unitless 16-bit value*
levelMsb = 0x12
levelLsb = 0x34
_ADV_PAYLOAD = [ 0x05, 0x16, 0xf9, 0x2a, levelLsb, levelMsb ]

* Payload uses little endian byte ordering: least-significant byte (LSB) first.

# Distance (ex: ToF sensor)
# Advertising payload bytes:
# 0:   0x07 = Length (not including the length byte itself)
# 1:   0x16 = 16-bit service data (from GAP)
# 2-3: 0xfcd2 = BTHome service UUID*
# 4:   0x40 = BTHome device information
# 5:   0x40 = Distance (mm) Object ID
# 6-7: 0x04d2 = Distance measurement (1234mm)*
distanceMsb = 0x04
distanceLsb = 0xd2
_ADV_PAYLOAD = [ 0x07, 0x16, 0xd2, 0xfc, 0x40, 0x40, distanceLsb, distanceMsb ]

* Payload uses little endian byte ordering: least-significant byte (LSB) first.

# Motion + Occupancy
# Advertising payload bytes:
# 0:   0x08 = Length (not including the length byte itself)
# 1:   0x16 = 16-bit service data (from GAP)
# 2-3: 0xfcd2 = BTHome service UUID*
# 4:   0x40 = BTHome device information
# 5:   0x21 = Motion Object ID
# 6:   0x01 = Motion detected (1 = true)
# 7:   0x23 = Occupancy Object ID
# 8:   0x00 = Occupancy not detected (0 = false)
isMotionDetected = 1
isOccupancyDetected = 0
_ADV_PAYLOAD = [ 0x08, 0x16, 0xd2, 0xfc, 0x40, 0x21, isMotionDetected, 0x23, isOccupancyDetected ]

* Payload uses little endian byte ordering: least-significant byte (LSB) first.

Consult our best practices guide for more details and examples:

Transmit images over WiFi Part 2

Details to come using the record-silo of Pareto Anywhere.

Tutorial prepared with by jeffyactive.

You can reelyActive's open source efforts directly by contributing code & docs, collectively by sharing across your network, and commercially through our packages. We invite you to become a sponsor to OpenMV to their work too!

Where to next?

Continue exploring our open architecture and all its applications.