Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(2) Arduino SD shield: bucket brigade logging-displaying solar PV power production

by Floris Wouterlood – Leiden – the Netherlands – June 6, 2017

Summary

In this paper I expand a previous project wherein an Arduino-based logging device is connected to a digital kWh meter1. The kWh meter registers 230V AC power produced by my grid-connected solar photovoltaic panels. Every time that 0.5 Wh of solar electricity has passed through the meter a led on the meter flashes and the meter’s S0 port shorts for a few milliseconds. This event, called here a ‘pulse’, is registered by an Arduino microcontroller board and counted. Through a logging shield, the counter is with intervals written to a data file on a SD memory card.

The logging shield does its work invisibly. With a LCD display the total number of pulses counted and the amount of solar kWh produced can be seen live. In the current project I discuss pulse data display on a 20×4 LCD unit. Two solutions are presented: a) single solution: connecting a LCD display directly to the Arduino/logging shield, b) bucket brigade:  the SD shield is connected to an Arduino Nano that controls the LCD display. A bucket brigade can be expanded endlessly, bucket after bucket.

Introduction  

The production of the solar photovoltaic panels that decorate the roof of my home is registered with a modern digital kWh meter equipped with a led that flashes every time a half watt-hour of power has been delivered (2,000 pulses/kWh). Simultaneously with the flashing led an optocoupled device inside the digital meter is activated for approximately 90 milliseconds. This device acts as a switch: two contacts (the S0 port, contacts on the meter numbered 20 and 21) are shorted. If a voltage is placed over the S0 port it will change every time the led flashes. An Arduino can supply such a voltage, can be programmed to notice rises or drops in voltage, and it can count. An Arduino can also write to file and an Arduino can be connected to a LCD display  In other words: an Arduino microcontroller board is perfectly capable to do the job of logging pulses. The number of pulses per time unit can be used as an indication for power and for production, and with a spreadsheet program nice graphs can be produced from the data.

In a previous project1 I constructed a logging device based on an Arduino Uno. The Uno provides 5V to one contact of the S0 port of the kWh meter while the other contact of the S0 port is connected to pin D2 of the Arduino Uno, one of the two pins on an Uno with Interrupt functionality. The very moment that the led on the kWh meter flashes and the S0 port is shorted the Uno notices a voltage rise on pin D2. This event is checked for validity, and if it meets the criterion of a true ‘pulse’, one unit is added to a counter.

Note on safety

For a safe workflow and to prevent frying the microcontroller a S0 port on any kWh meter should electrically be completely isolated from the main 230V AC power current. The manufacturer of the kWh meter bought by me guarantees this aspect. In the previous project I successfully connected the S0 port of a digital kWh meter with an Arduino. For electrical safety considerations the solar kWh meter is located in its own cabinet several meters away from the logging/displaying device.

Real time clock (RTC) and logging to file

In addition to the microcontroller platform necessary for counting pulses I needed a timing device because an Arduino does not support multithreading. A real time clock (RTC) is a device that supplies the exact time to the Arduino. Finally we need to record the numbers of pulses per time unit over a daytime cycle. Among the several solutions to accomplish this I opted for the one that writes data to a file on a SD card. On the market are Arduino Uno compatible shields that feature both a RTC and a SD card slot.

Hardware required

While the Arduino Uno can do an amazing lot it has also its limitations. It has a limited amount of memory to store instructions, and the number of communication pins restrict the number of devices that can be connected. The jobs in the current project with the associated hardware are listed in the table below. The Arduino supplies the instructions that controls the hardware. A basic condition was to work with the Arduino Uno or Nano (an Arduino Mega is much more versatile). A survey:

job hardware required
pulse generation digital KWh meter with S0 port
detection of pulses Arduino
counting pulses per time unit Real time clock (RTC)
writing to file on SD card SD card writer
display the production on a LCD display LCD display

 

Theoretically all functionality can be met with only one Arduino Uno topped with a RTC/SD shield and connected to a LCD display. Such a complex device is called a ingle solution’. However, apart from power and GND, the auxiliary equipment requires access to pins on the Arduino, sometimes dedicated and non re-routable pins. On an Arduino Uno this easily leads to conflicts and it can be quite a challenge to figure out which pins to use and which not to use. Pulse detection needs one of the two available interrupt pins, the RTC needs 3 pins, the SD card writer needs 3 pins and the LCD needs 6 pins. Accumulation of jobs also increases the size of the sketch which translates into memory allocation in the Arduino and possible overload. For practical considerations two linked Arduinos might be handy: a Uno topped with a RTC/SD shield and a next-in-line Uno or Nano that deals with displaying calculated numbers on a LCD display. Such a string of Arduinos is called here a bucket brigade (fig. 1)

Figure 1: Setup of a ‘bucket brigade’. The solar panels produce DC power which is converted into 230V AC by the solar inverter. The kWh meter produces pulses in proportion to the amount of power delivered to the wall outlet and returned to the grid. Pulses are registered by an Arduino Uno fitted with a SD logging shield (SD) and a real time clock (RTC). For every pulse registered the Uno sends a signal to a secondary Arduino, here a Nano, that displays relevant data on a LCD display

Single solution

The single solution consists of an interface board, Arduino Uno, RTC-SD shield and LCD display (figure 2). The construction of the interface board, the wiring and software instructions have been dealt with in the previous paper1. Here we focus on connecting a LCD display.

Electronics and supplies

(apart from the digital kWh meter): 1x Uno microcontroller board, 1x Uno SD shield with real time clock (RTC), 30×70 mm soldering board, 5x 220Ω resistor, 2x 10 kΩ resistor, 1x 10 kΩ pot meter, 1x red led, 1x green led, 1x yellow led, wires, 20×4 LCD display, SD card (FAT32 formatted).

Figure 2: Setup of the single solution. Pins 20 and 21 of the kWh meter (the S0 port) are connected to 5V and D2 of the Arduino. The LCD display is wired via non conventional pin connectivity: pins D5,D6, A3,D9,D8,D7.

Because there is one Arduino, there is only one sketch necessary to run the entire device. The sketch ‘single-arduino-sd-lcd-pv-logger.ino’ can be accessed and downloaded via the url listed at the end of this paper.

Bucket Brigade

The bucket brigade solution uses multiple Arduinos. Figure 3 shows semi-schematically the wiring of the bucket brigade.

Electronics and supplies

(apart from the digital kWh meter): 1x Arduino Uno and 1x Arduino Nano microcontroller board, 1x Uno SD shield with real time clock (RTC), 30×70 mm soldering board, 6x 220Ω resistor, 2x 10 kΩ resistor, 1x 10 kΩ pot meter, 1x red led, 1x green led, 2x yellow led, wires, 20×4 LCD display, SD card (FAT32 formatted).

Figure 3: Schematic wiring of the ‘bucket brigade’. The wiring between the solar kWh meter and the logging Arduino SD shield is described in detail in the previous paper. Pin D7 on the SD shield is programmed to get HIGH for 60 msec for every pulse counted. This pin therefore acts as a ‘pulse forwarder’. D7 is connected to pin D2 on the secondary Nano (note the 10 kΩ pull down resistor). On the Nano incoming pulses are translated into screen activity of the LCD display: number of pulses counted and the calculated amount of produced kWh.

In the ‘bucket brigade’ configuration, the Arduino Uno detects, counts and writes to file the number of pulses detected per 5 minutes, and stores this information on a file on the SD card. In addition it sets pin D7 HIGH for a short period each time it detects a pulse. This action could be called ‘pulse forwarding’ The Nano, via its interrupt pin D2, detects the pulse forwarding and reports the state of its own pulse counter on the LCD screen.

 Activity breakdown

  1. Pulse generation and interface board

The Arduino Uno supplies 5V to the S0 port of the kWh meter. The circuit is completed by connecting the return wire from the S0 port with pin 2 on the Uno. For the sake of flexibility an interface board is placed between the S0 port and the RTC/SD shield. If the kWh meter pulses, the voltage on the Uno’s pin 2 will shortly spike from 0V to 5V. Because a red led on the interface board also receives 5V during the pulse time it will flash: the ‘pulse echo led’ (figs. 2,3). Notice that the pulse echo led is not programmed to flash in the sketch but instead flashes ‘spontaneously’ when the kWh meter pulses.

The interface board was constructed by soldering the following components on a small (30×70 mm) soldering board: red ‘pulse echo’ led, yellow  led (‘flush’ and ‘error’) and a green ‘SD write’ led. On the board is also a female pin header that connects with the S0 port of the digital kWh meter. This pin header is visible in figure 4 in the left lower corner. The wire connecting the S0 port on the digital kWh meter and the logging unit has a length of approximately 10 meters.

Figure 4: Interface board and Arduino Uno with RTC/SD shield, ready for action.

  1. Pulse detection

Pin 2 on Uno is also programmed as interrupt pin, that is if an event happens at these pin the microprocessor will be informed of the event, interrupt any activity, and perform an action in response to this interrupt. Here, the pulse related action consists of checking the validity of the pulse (‘is this a real pulse or some random wire jitter’) and if accord to increase the value of a variable called ‘counter’.

  1. Writing to a file on the SD card

Activity such as sampling, writing to file, and error situations, are reported by led activity as well. These ‘activity leds’ are mounted together with the pulse echo led on the interface board. Their activity is controlled by the sketch.

  1. Displaying data on a 20×4 LCD display

The 20×4 display is a standard 2004A 16-pins 20×4 LCD device. Wiring of the device is different from standard wiring schemes. Standard wiring of LCD the 2004A LCD display is via pins 11, 12, 2,3,4,5 and 6 of the Arduino. With some experimenting I discovered that pins 5 through 9, and A3 are available for action without interfering with the performance of the RTC-SD shield. In the table below the connectivity between the Arduino Uno (that is, the RTC-SD shield) and the LCD display is given.

Pin on LCD Single solution Bucket brigade
Pin on Arduino Uno Pin on Nano
1 (VSS) GND GND
2 (VDD) 5V 5V
3 (V0) Wiper 10kΩ pot meter Wiper 10kΩ pot meter
4 (RS) GND GND
5(RW) D5 12
6 (E) D6 11
7 (D0) (not connected) (not connected)
8 (D1) (not connected) (not connected)
9 (D2) (not connected) (not connected)
10(D3) (not connected) (not connected)
11 (D4) A3 D4
12 (D5) D9 D5
13 (D6) D8 D6
14 (D7) D7 D7
15 (A) 5V with 220Ω resistor 5V with 220Ω resistor
16 (K) GND GND

 

  1. Additional

Apart from the different wiring of the LCD display device and, of course, the application of two Arduinos in the bucket brigade solution, the bucket brigade solution features and extra yellow ‘blink led’ which in the single solution is omitted for the sake of liberating one precious pin for LCD control. It should be noted that in the bucket brigade solution GND of the Arduino Uno is connected to GND on the Nano. If this GND-GND wire is absent the Nano and the LCD display will not function properly. Furthermore, in the bucket brigade solution the Nano and the LCD can be placed several meters away from each other. Finally, a bucket brigade can be repeated as many times as necessary or appropriate.

 

Sketches

There are three sketches.

Sketch 1 (for the single solution).

This sketch does the following

 

  • prepares the Arduino Uno;
  • initializes the LCD display
  • initializes the SD card writer
  • calls a time stamp;
  • recognizes via pin 2 a ‘pulse’ event
  • reports every pulse by blinking the red ‘pulse echo’ led on the interface board;
  • stores the number of pulses recorded in 5-minute intervals;
  • writes data comma delimited to file on the SD memory card every 10 minutes;
  • blinks the green led to report a write-to-SD card operation;
  • blinks the yellow led to report a flush operation or an error situation.
  • displays on the LCD the number of pulses counted;
  • calculates and displays on the LCD the amount of kWh;
  • calculates and displays on the LCD the average power over a 30-second period (Watt).

 

Sketches 2 and 3 (for the bucket brigade)

Sketch 2 runs on the Arduino Uno with the RTC/SD shield

Sketch 3 runs on the Nano-LCD display combination

Sketch 2 does the following

  • prepares the Arduino Uno;
  • initializes the SD card writer
  • calls a time stamp;
  • recognizes via pin 2 a ‘pulse’ event
  • reports every pulse by blinking the red ‘pulse echo’ led on the interface board;
  • sets pin 7 HIGH for 60 msec after recognizing a ‘pulse’;
  • stores the number of pulses recorded in 5-minute intervals;
  • writes data comma delimited to file on the SD memory card every 10 minutes;
  • blinks the green led to report a write-to-SD card operation;
  • blinks the yellow led to report a flush operation or an error situation.

Sketch 3 does the following:

  • prepares the Nano and initializes the LCD display;
  • recognizes via pin 2 a ‘pulse’ event
  • reports every pulse by blinking a yellow ‘pulse echo’ led attached to pin 10;
  • displays on the LCD the number of pulses counted;
  • calculates and displays on the LCD the amount of kWh,
  • calculates and displays on the LCD the average power over a 10-pulse period (Watt).

Results

The SD logger had been tested both in single solution and bucket brigade configuration for more than one month, with very satisfying results. The advantage of the current solutions compared with the previous, visually ‘silent’ SD logging is live data display on the LCD device. I like to have at hand both visual and logging file output reporting the production of my solar panels in kWh.

 

Discussion

The current project exploits the ‘pulse’ feature of the digital kWh meter that registers electricity produced by the grid inverters of my solar panels. Actually this feature is not a pulse of real current. A ‘pulse’ on the S0 port of the kWh meter consists of the brief shorting of its contacts 20 and 21 the very moment that the indicator led flashes. The Arduino Uno supplies 5V to the S0 port and detects on pin 2 that the voltage briefly spikes from 0V to 5V when the S0 port shorts. A pulse therefore could better be described as a ‘voltage event’

An advantage of an all-in-one single solution is that the LCD can also display the time stamp and, based on the time, the Watts of power that is generated in real time.

The latter remains problematis in the current sketch because live power display depends on counted pulses. The sketch is in fact one big ‘delay loop’ at the end of which it is determined what the increment of the pulse counter is (the ‘delta’). Only then the average power in Watts can be calculated of the past sample period. One has to wait until the end of the first sample period before this is done. This can barely be called ‘live’. When there are no pulses, there is no new delta. As a consequence the watt counter is then based on the last delta recorded.

In the bucket brigade solution, a live power display can also be generated using the  millis() function. This is less accurate than a deriving time information from a RTC, but in practice with the low pulse frequency of a kWh meter it is not a big problem. In the bucket brigade sketch, every 10 pulses (5 Wh) the live power in Watts is calculated and displayed.

While the prototype is a jungle of shield, wires, breadboards and devices the entire configuration can be wired and soldered together into one compact apparatus with one power supply. On the other hand the power need of the single solution is very close to what the Arduino supplies, which is revealed by a flickering LCD display. Further stretching, or overloading the power supply may interfere with the accuracy of the logging. A bucket brigade features two Arduinos and two power supplies and is therefore thought to be more stable than a single solution. The main attraction of a bucket brigade however is its limitless possibility for expansion because every ‘bucket’ passes the pulse to the next.

The microprocessor in an Arduino is a sequential device. While time is externally supplied by the RTC unit on the SD shield, the time parameters are not  transferred to the next Arduino in this bucket brigade solution. It could be fun to experiment with serial communication (Tx-Rx, I2C) between the two Arduinos. As soon as I2C LCD displays are added to my display fleet a one- bucket solution with I2C LCD display may be considered. An attractive alternative is to connect the first or second Arduino via a network shield to the home network.

Previous project

Arduino solar PV production ‘pulse’ logger with SD shieldFloris Wouterlood – May 5, 2016

 

Sketches

 

Sketch 1 (for the single solution).

single-arduino-sd-lcd-pv-logger.ino

 

Sketches 2 and 3 (for the bucket brigade)

bucket-brigade-01.ino (runs on the Arduino Uno-RTC-SD)

bucket-brigade-02.ino (runs on the Nano-LCD display)

 

sketches can be downloaded from:

http://thesolaruniverse.wordpre\ss.com

they are bundled into a zip file: bucket_brigade_arduino_sketches.zip