Wednesday, August 15, 2012


Using  the Serial Camera to Read the Smart-Meter                              



I had a couple of technical problems with the serial camera to solve before I could have my computer turn an image of the meter face into a numeric electric usage rate. During the day, there are reflections off the meter face. The very bright reflections from the white LEDs I had installed on the camera caused the image to go to saturation in places. The difference between day and night lighting made it difficult to detect the widely changing pixel values over a 24 hour cycle.  I solved these problems by using an electroluminesent (EL) flat panel light source and by putting a black plastic bag over the camera and meter.   I bought a blue-green EL panel and 5vdc driver on eBay ($15.49 delivered!). With a pair of scissors, I trimmed the EL panel down to the size of the camera box and glued it on to the box face such that the lens would stick though a hole in the center of the panel. The resulting camera images were in shades of blue-green with RGB pixel values of approximately, G = B and R = 0. There are still some reflections of the camera lens itself and the images are reminiscent of the HAL camera/eye in 2001Space Odyssey, except  this image is blue-green, instead of red.

The Smart Meter display, cycles through five different readouts of 5 seconds each, which repeat every 25 seconds. The cycle times are not exact; I suspect that the meter’s microcontroller occasionally becomes busy with networking functions and so the timing becomes inconsistent. The first order of business is to correctly identify each of these images:
1.       A Blank image, where the meter is blank (except for the letters CLS off-screen to the left.)
2.       A Meter reading of total Kwatts used so far.
3.       A meter Identifier, which for my meter is always “151”.
4.       The Rate of electric usage in Kwatts per hour.
5.       A Test screen where all the meter's LCD elements are active.

The screen identification algorithm I  went with, is as follows: I start out by reading images from the camera, as fast as it will go, for the first 35 seconds. An image brightness is calculated by adding up each of the 160 green-blue bytes along a single centered horizontal line for each image. Transitions between successive images are scored by comparing brightness to the prior image. The biggest difference between brightnesses is when the Test screen transitions to the Blank screen. This maximum score is saved and used to calculate a cutoff value to detect successive blank screens. Now when a Blank screen is detected, a timer is started to read the next four images at five second intervals, but after the reading the fifth (Test) image, the timer reverts to quick reading images until a Blank image is found again. This algorithm seems to work well and I have not seen any misreading of image types.


Any image of interest can be turned in to a monochromatic image by subtracting from each pixel, the corresponding pixel from the Blank image. Subtracting the Blank’s background color and testing against a cutoff value generates a two toned image. I use the Test monochromatic image to find the locations of pixels in each segment of five LCD numerals. This process is CPU intense but when found, these segment pixel locations can be used for all images until the camera is moved. These segment pixel locations are scored against pixels on the Meter reading images and on the Rate images to generate a seven segment score that is translated to a numeric digit with the help of a look-up table (“1111111” is the digit 8 and “0101100” is the digit 7.) Common misreads are incorporated into the lookup table as well. There is a fair amount of parallax that distorts the furthest left and right digits. The decoded meter reading, rate and system time are saved in an array and backed to a Daily named file on an hourly basis. I included a little real-time electrical usage graph in a picture control, but I usually use another Graphing utility program to view the data  from the saved files . All files are read/written  to a 1G flash drive to allow my hard drive to get some rest at night.