Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(65) ESP8266 pulse counting attractively represented on a GC9A01 circular display

by Floris Wouterlood – March 17, 2023

Summary
I upgraded a solar power pulse meter that I constructed nearly six years ago and that has been working 24/7 all those years. This pulse meter is part of a ‘bucket brigade’. The principal component of this brigade is a digital kWh meter that opens and closes a port (S0 port) when a certain amount of AC power has gone through it – power generated by the inverters of my solar panels – on its way to be injected into the AC home electric power grid. S0 port action is 1:1 with a led flashing on the kWh meter. S0 port opening and closing is recorded by an Arduino Uno logging shield.

figure 1. Completed device, up and running, displaying momentarily generated solar power (dial-wise and numerical, Watt window) and production (numerical, kWh window).

Each time that action is recorded the shield shortly sets HIGH a digital pin that is wired to an Arduino Nano that counts such secondary pulses and displays the results on a 20×4 LCD (number of pulses, kWh produced and amount of Watts currently generated). The Nano counter and the LCD are to be replaced by the current device: an ESP8266 that drives a circular 1.28 inch 240*240 TFT display. The result is a compact, attractive upgraded unit.

Introduction
Nearly six years ago I constructed an Arduino ‘bucket brigade’ device for the purpose of monitoring and logging the performance of the solar photovoltaic panels that decorate the roof of my home (schematically represented in figure 2). AC power generated by the grid-tied solar power inverters passes a kWh meter. A led on the kWh meter flashes when 1.25 Watt-hour of power has passed (800 pulses/kWh). The same moment an optocoupled switch inside the meter is activated for approximately 90 milliseconds: two contacts (together called the S0 port) are shorted.

figure 2. Organization scheme of all equipment involved in the current project. The ESP8266 D1 mini and the display are at the end of the ‘bucket brigade’ chain; they replace an Arduino Nano/LCD.

A voltage placed over the S0 port drops every time the led flashes: a pulse that can be detected by an Arduino. This particular Arduino is an Uno equipped with a logging shield with real-time clock (RTC). It detects S0 ‘pulses’ via its pin D2 (*). The Uno does more: as soon as the microcontroller records a S0 pulse from the kWh meter it sets pin D7 HIGH for a short period. This D7 ‘bucket brigade’ pin is wired to an Arduino Nano that records this secondary pulse, performs several calculations and drives a 20×4 LCD for visual display of the results. The Uno has been producing daily solar power logging files on SD card for nearly six years! I spent in 2017 two posts on my blog TheSolarUniverse describing the details of this ‘bucket brigade’ and its components (*, **). The current project was started because I felt that time had arrived to replace the Nano/LCD after its respectable operational life with a compact, appealing display. An 1.28 inch 240*240 TFT circular GC9A01 display was selected together with an ESP8266 D1 mini. Reason to use an ESP8266 in favor of a Nano is its wifi support which opens the road to my ultimate goal, that is is to conduct all S0 pulse recording and display in one device, with fully automated internet-based logging via wifi. Extra features of an ESP microcontroller board / display combination are the small footprint an an appealing look.

Construction
The board is a 6*8 cm double-sided soldering prototyping board that accommodates an ESP8266 D1 mini microcontroller board and a 1.28 inch diameter 240*240 pixel circular TFT with GC9A01 driver chip. Circular displays can be purchased mounted on an Arduino compatible breakout board (***).
Central rule in my designs is that all principal components should be easily replaceable. Thus, any ‘breakout’ must always be mounted on a corresponding pin header socket. Here we place the microcontroller board and display next to each other on the front of a landscape oriented soldering board (figs. 1, 3) while all wires run on the back.
Figure 3 shows the position of the pin header sockets and the wires that connect the microcontroller and the display. The display needs 4 wires in addition to power and GND. The wiring table is as follows.

Wiring Table

ESP8266 display
RST not connected
D8 CS
D2 DC
D7 SDA
D5 SCL
GDN GND
3V3 VCC

 

figure 3. Design drawing: 8×6 cm soldering board with the positions of the pin header sockets that support the D1 mini (left) and the GC9A01 display (right). Wiring indicated with colored lines. After soldering of the wires the microcontroller board and the display breakout were stuck onto their pin header sockets.

Electronics and supplies
1x 1.28” diameter 240*240 TFT 4-wire SPI display with GC9A01 controller
1x ESP8266 Wemos D1 mini microcontroller board
1x 8*6 cm double-sided soldering board (22*29 holes)
1x 220 Ω resistor
2x 8 pin header socket
1x 7-pin header socket
1x 5-pin header socket
2x 2-pin pin header (one red, one black)
wire
3 nylon spacers and screws
acrylic cassette tape box (stand)

Extra pin header to utilize surplus pins
Pins D2, D5, D7 and D8 of the microcontroller are necessary to drive the display. Of the unoccupied pins, D0, D1, D3, D4, D6 and A0 were selected to be connected with a horizontal 6-pin header socket in ‘bench style’. This socket was positioned in the left lower corner of the soldering board, next to double GND and 3V3 pin headers. The design drawing and wiring for this additional functionality is shown in figure 4.

figure 4. Design drawing for additional functionality of the device: an extra ‘bench style’ 6-pin socket header to make it easy to use unoccupied pins of the ESP8266 microcontroller in experiments. Pin D1 will be used as interrupt pin checking pulses coming from the Arduino Uno logging shield. Note the 220 ohm resistor to mitigate the voltage of the incoming pulse (5V from Uno SD shield).

After soldering and testing the board was fastened onto the lid of a recovered old acrylic cassette tape box. These boxes are in recycling very handy as chassis for Arduino projects. The completed, operational construction is shown in figure 1.

Display requirements
Graphical and numeric display of power generation is as follows (figure 5).

  • The circumference of the display (‘power circle’) is decorated with 33 circles that, on a scale of to 0-1.475W power, turn red related to calculated power. Each colored circle then represents approximately 45W of power.
  • Pulse indicator: the bottom of the display contains at the center a single circle whose color flips between magenta and green when a new pulse is detected.
  • kWh and Watt windows that respectively show numerically the volume of power that has passed the kWh meter and the currently recorded power.

figure 5. Design drawing for the display. The scale of the power circle in the current sketch is 1.475W. Each red dot in the power circle represents approximately 45W. The pulse indicator switches color every time a pulse is registered.

Software
The sketch running on the ESP8266 should do the following:

  • An interrupt function on pin D1 monitoring pulse activity.
  • Activity detected on pin D1 must be identified as a true single ‘pulse’ by an anti-bounce function and only then further processed.
  • A timer is necessary to record the time interval between two successive, identified pulses.
  • Power can be calculated from the recorded time interval between two successive pulses (the faster the pulse train the higher the power generation by the solar panels).
  • Production can be calculated from the number of received pulses, each pulse being the equivalent of 1.25 Wh of power generated by the solar panels.

Results
The current kWh meter registering produced solar power replaces the original meter described in the 2017 publications (*, **). The original kWh meter featured 1.200 pulses/kWh while the current meter ‘does’ 800. At 800 pulses/kWh a consequence is relatively long periods in between successive pulses, even at high power output of my solar panels. The longer the period the more accurate power calculation is, at the expense of sluggishness because after identifying one pulse the ESP8266 sits idle (while on alert!) until the next pulse arrives. Sometimes cloud conditions in my home town change extremely fast, with accompanying rapid acceleration/deceleration of solar power production. The pulse meter then lags behind or might become confused.
A 10 kΩ pull up resistor placed on pin D1 improved the accuracy of the pulse counting. Next steps will be direct kWh meter S0 port pulse counting by the current device, and the development of a sketch to use the wifi functionality of the microcontroller board to report to a cloud-based logging system.

Libraries needed

  • Adafruit_GFX.h
  • Adafruit_GC9A01A.h

Sketch
bucket_ESP8266_CG9A01_pulse_meter.ino

Download
bucket_ESP8266_CG9A01_pulse_meter.ino – packed as ZIP file

References

(*) Arduino solar PV production ‘pulse’ logger with SD shield – TheSolarUniverse, May 5, 2017

(**) Arduino SD shield: bucket brigade logging-displaying solar PV power production – TheSolarUniverse – June 6, 2017

(***) An internet-synced clock: circular display with GC9A01 controller powered by an ESP8266. TheSolarUniverse – November 1, 2022