My goal was to measure the electrical power consumption in the course of a day. Not regularly but for a few days with various typical home house-hold usage patterns. Hence my requirements were
The pre-requisites were
This project consists of four parts
libsml package to list or dump the read-out to a fileThe four parts are deliberately modular in nature, e.g.
Ths image shows all hardware components. The image also shows the USB-B receptacle with a four pin terminal block to complete the USB-UART and a short 3-wire cable to link the amplifier circuit and the USB-UART:
Close-up of the photo-diode head assembly. Two cylindrical magnets make the head stick at the smart meter:
Photo diode current amplifier circuit:
USB-UART with TTL input/output:
The following image is a "plot" of the schematics as an SVG file:
Please note that I have drawn the schematic to help my strip-board assembly, rather than a good schematic read.
The USB-UART uses Microchip's MCP2221A integrated circuit, which is a pre-programmed microcontroller. By default it provides two independent functional blocks:
For the smart meter read-out, I only use the USB-UART bridge.
The circuit contains four LEDs. By default, the MCP2221A's four general purpose IO-pins are programmed to drive the LEDs:
The current limit resistors of 3.3 kOhm set a LED current of about 1 mA. As D3 will be on all the time, I put 6.8 kOhm to set 0.5 mA. You might want to use modern LEDs with point type non-diffuse lenses which provide >1000 mCd light flow at their maximum electrical current (usually around 20 mA).
R4 = 2.2 MOhm makes sure the Rx pin reads idle level (= +5 V) when nothing is connected. The MCP2221A does not seem to have a pull-up resistor at that input pin.
R2 = 10 kOhm is the recommended pull-up for the MCP2221A reset line.
The MCP2221A provides TTL level Rx input and Tx output. For standard RS232 UART voltage levels, you needed an additional driver/receiver circuit, e.g. using the MAX232 integrated circuit.
Nota bene: the MCP2221A supports only core UART operation using Rx and Tx. I.e. there is no support for UART hardware handshaking functionality. Yes, other MCP2221A pins could be re-programmed as general inputs or outputs, but I am not aware of any driver software that does that for the purpose of UART handshake.
I cannot remember why I chose an infrared photo diode rather than an infrared photo transistor. Anyway, I designed an amplifier to convert the photo diode current into a logic level signal. I experimented with various circuits and settled for a MOSFET transistor that does this conversion.
Resistor R9 sets the input sensitivity, i.e. the diode current to output voltage ratio. R8 sets the operating point, i.e. the voltage at DP2 when idle, when the diode current is zero.
Two consecutive CMOS inverters do further amplification and allow to drive long cables. When testing the circuit, I successfully used a 5 m (15 ft) cable between amplifier and USB-UART.
The CMOS inverters also make sure the output swings rail to rail. This is vital as the MCP2221A Rx input has quite a large switching hysteresis.
The 4007 CMOS integrated circuit (in my case an ancient HBF4007 from the manufacturer SGS Ates) does provide the single P-MOSFET as amplifier and the 4007 also provides the two additional CMOS inverters.
The 4007 MOSFETs have relativly low gate capacitance compared to single MOSFETs like the BS107, BS170 or BSS250. This is important as a too high gate capacitance degrades the signal switching slew rate. In other words: MOSFETS like BS107, BS170 or BSS250 are no good to amplify photo diode signals.
I re-used an existing cable from an old PC that has two twisted stranded cables ending in 2-pin female connectors with 1/10 inch spacing. The connectors fit nicely the two diode pins and the 2-pin male connector on the amplifier board.
Please note that the photo diode is also available as SFH203 without the FA suffix. That device does not have an infrared filter in front. It would also work in this application but only if you make sure the head assembly is shielded from all ambient light.
The head is fixed to the smart meter by two cylindrical magnets in a plastic housing, which I had available. The plastic covers a rectangular steel plate that connects the two magnets at the back.
Obviously, three such magnets would by optimal to fit to the round steel plate inside the smart meter. A round head assembly of 32 mm diameter is the recommended shape.
I my case, the photo diode needs to gently touch the smart meter's round translucent window in front of the infrared LED inside the smart meter. Some millimetres distance would already weaken the signal too much, but this could be compensated by increasing R9 to yield higher amplifier gain.
I am using the libsml software from the Volkszaehler-Solution. The repository is https://github.com/volkszaehler/libsml/blob/master/
The current version of libsml is available in the standard repository of Debian 13 (Trixie). However, the laptop I use runs Debian 12 (Bookworm), where the libsml version in the repository is out of date. Hence I needed to compile libsml.
libsml contains the executable sml_server in the examples directory. sml_server shall be used from the command line and prints (all?) the received data in human readable form. This is very useful for testing.
The USB-UART is self-contained and can be tested without the other components. When connecting the USB-UART to a PC USB-port the USB LED shall come on. This confirms that the USB-UART has been recognised by the PC's OS. On Linux this can also be verified using
# dmesg | tail -n 20
after connecting the USB cable. The dmesg command also shows the device name that the OS assigns to the USB-UART. In my case this was /dev/ttyACM0.
Next you might want to open a program to operate the serial line. I used Emacs' serial-terminal mode. It asks the device name and the baud rate, where I chose 9600. When you type characters on the keyboard you should see the Tx LED flash. When you connect the Tx to the Rx pin using a jumper, the Rx LED should also flash and the typed characters should be echoed in the terminal program.
Initially I did not know that the smart meter would output via its infrared LED all the time. I had checked with the smartphone camera but did not see anything. Hence I assumed wrongly that you needed to transmit something to the meter to "request" data.
This is why I built an infrared transmitter circuit to be able to test without the smart meter:
The 620 Ohms resister sets the SFH4546 infrared LED on current to about 5 mA. This is my guess for the current through the LED inside the smart meter.
The transmitter circuit could be connected to the Tx output pin of the USB-UART. Thus testing could be done by sending from a serial terminal program or from a script.
The schematic shows a simple alternate circuit to drive the infrared LED from a function generator, which outputs a 10 kHz square wave. Well, 9600 bits per second corresponds to a 5 kHz square wave. But if the test works for 10 kHz, it will for sure work with 5 kHz.
I fixed the SFH4546 infrared LED and the SFH203FA infrared photo diode provisionally on a 10 mm × 10 mm L-shaped aluminium rail, 100 mm long, opposite to each other. Thus I could easily play with the distance of LED and photo diode.
Without the photo diode connected or with no IR-light illuminating it, the amplifying P-MOSFET's drain (pin 1 of U1) shows a voltage of ≈3.0 V. If you illuminate the IR-LED, the voltage drops well below 2.5 V, which is the switching threshold.
Dynamic testing needs an oscilloscope to check the waveform at pin 1. Pins 8, 10 and 13 should show the inverted waveform and pin 12 ‑ which is the output ‑ the non-inverted waveform.
I copied and adapted the sml_server source code to print the following data:
I separated these 6 values by a tab character and have each line terminated by ''. My smart meter model generates a full data set each second, hence I get one line per second. I redirect the output to a file. The log for one day yields a file of about 3 MB of data.
These tab separated values files can be easily imported into LibreOffice, to analyse using pivot tables and charts.
I have tried various designs for the electronic circuit to convert the photo diode current to a logic level signal:
The polarity convention is: the circuit output logic level shall be "high" (either +5 V ‑ in my case ‑ or +3.3 V for the RasPi), when there is no light and "low" (0 V) when there is light.