Our step-by-step guide to create a wireless gauge reader using OpenMV on the Nicla Vision.
A Nicla Vision configured to run OpenMV
* a standard USB A to micro-B cable is required—but not included!
Right into the root folder of the Nicla attached storage device.
Beginning your adventure in gauge-reading.
aka "Fiddling with it until it works".
There are two methods the Nicla can use for determining the position of the gauge needle:
With this method, it is assumed that the center of the needle, and the min and max values of the needle will always be in the same place. These positions are set in the configuration file with the variables:
"use_color_dots" : False, # set this to FALSE to use absolute positioning
"radian_point_min": .25 * math.pi, # the point in radians of the min gauge value
"radian_point_max": 1.75 * math.pi, # the point in radians of the max gauge value
# coordinates of the center of the gauge. This will usually be half of the width and height
"center_x" : 80,
"center_y" : 60,
Place small colored dots at the min and max gauge positions, and on the center of the gauge. Then configure the color thresholds to identify those colors.
Adjusting the algorithm to match lighting conditions.
Make sure the serial terminal is on.
Make sure that the value for color_calibration_on in ra_config.py is set to True.
Start the code running when the nicla is pointed at the gauge in the intended setup. It's important to START it with the nicla in the right place, because the camera calibrates itself to its starting conditions
Point the small green circle in the center of the Frame Buffer view at the colored dot you want to match. Here it's pointed at the red dot:
Take note of the 3-value array being output in the Serial Terminal
This is the LAB value of the pixel in the center of the image
Create a RANGE array, with values about +/- 10 from the given value, so eg
(52, -1, 13) becomes (42, 62, -9,11, 3, 23 )
NOTE that the first value is LIGHTNESS, so you could try a wider range on that.
Plug this new range array into the ra_config.py, following the instructions there. Make sure you are editing the ra_config.py on the device itself, but keep an updated version backed up on your computer as well.
1. Create a new named threshold in the color_thresholds dictionary, eg
"color_thresholds" : {
"yellow" : (50, 80, -5, 10, 25, 50), # yellow_thresholds (206, 174, 90)-> Lab(72.691%, 3.691%, 37.566%)
# Yellow Dot is for the CENTER.
"room4_yellow" : (45, 75, -15, 5, 15, 45), # yellow_thresholds (206, 174, 90)-> Lab(72.691%, 3.691%, 37.566%)
# The yellow dot in room 4 looks a little different
},
2. change the value of one of the three variables in the config that indicate the threshold name for min_color, max_color, and gauge_center, eg:
"min_color": "red", # the color of the dot at the MINIMUM value of the gauge
"max_color" : "green",# the color of the dot at the MAXIMUM value of the gauge
"center_color" : "room4_yellow", # the color of the dot at the CENTER of the gauge
Run the code again and see if it works!
The Gauge values are sent from the Nicla as Hex values in the range 0-FFFF (65535), which can be divided by 65535 to get the percentage (0-100) of the gauge’s maximum value.
Observe in Pareto Anywhere, or from any Bluetooth Low Energy scanning mobile app, a device named MPY NIMBLE>. The value is advertised as UUID 2AF9
In nrfConnect it will look like this:
Time to let the little guy run on its own.
Sipping battery power like a good bourbon.
Set the following configuration variables:
"sleepmode" : True, # if true, sleep in between sending data (set to false for debugging)
"sleep_interval" : 10000, # how long to sleep, in ms, between jobs
"sends_per_wake" : 10, # how many data sends per wake session
Each time the device wakes up, it will do several reads of the gauge and send out the values via bluetooth. The number of reads it does each time it wakes up is defined in “sends_per_wake.” The amount of time it sleeps is defined in “sleep_interval”
Note: When the device goes to sleep, it also disconnects from your computer if it’s connected, meaning you can’t copy files or update the ra_config.py file.
To Turn off Low-Power Mode:
Edit ra_config.py on your computer
"sleepmode" : False,
When you re-connect the Nicla to your computer , you have a brief window where the device is available to copy files to, before sleeping again. During this window, try to copy ra_config.py to it. This might result in ra_config.py on the nicla becoming corrupted, in which case main.py won’t run, meaning it won’t go back to sleep, it will stay attached to your computer, and you can now upload your new ra_config.py files.
Tutorial prepared with ♥ by donundeen.
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 sponsor OpenMV too!Continue exploring our open architecture and all its applications.