Thursday, June 27, 2013

Solar Pi

2 x amorphous silicon 15Wp panels
(Make/brand is IPC Global Battery Saver Pro)
About 10 years ago when Maplin opened a local store, I picked up some solar PV panels, a 40Ah sealed lead-acid (SLA) battery and a charge regulator on special. For the past 10 years these panels have been sitting in a window in my guest room doing nothing but keeping my battery nicely charged.

Finally, I've put this setup to some better use. I'm experimenting with the idea of keeping a Raspberry Pi powered 24/7 using nothing but PV panels and a battery. I'm based in Galway, Ireland (53N, 9W) and here we don't get too much direct sun (clouds keep getting in the way :)... so this goal isn't completely trivial.

My setup so far: 2 x 15W-peak amorphous Silicon panels (300mm x 1000mm) usually laid flat on the ground. A 12V lead acid battery charge regulator, a 40Ah SLA battery. The charge regulator's function is to stop charging the battery when the battery reaches 14.2V.

So I have a nice 12V DC power supply from the battery. But the Raspberry Pi requires the standard USB 5V. A linear regulator could do the job but would be at best only 42% efficient (5V/12V). Instead I'm using a low cost USB car charger (listed as a recommended Pi accessory at Farnell / Element 14, SKU 2113630, cost about €5). This is a DC/DC switch mode converter.  I don't have efficiency figures for this, but I suspect it's somewhere in the 80% efficiency region.  Update: 2 July 2013: I've measured this to be 73% [1]

Low cost 12V to 5V (USB) DC/DC
converter available from Farnell
(SKU 2113630)
I chose a Model A Pi because it uses significantly less current than the Model B (due to the missing USB hub / ethernet interface chip). The down side is I need a USB hub if I want to connect more than one device (which I do!). I'm using a low cost "Technica" brand USB (unpowered) hub from Tesco. For networking I'm using the WiPi WiFi USB dongle (Farnell SKU 2133900).

I want the Pi to be able periodically log the battery voltage. Unfortunately the Pi doesn't have an ADC, so it's the Arduino (Leonardo) to the rescue, connected to the Pi via the USB hub.  But... the Arduino ADC only handles 0 to 5V, so a voltage divider is used to bring the maximum possible battery voltage (about 14V for 12V lead acid battery) into the 0 to 5V ADC range. I'm using a 39k/12k divider bringing the 0 to14V range down to 0 to 3.3V (I had originally planed to use a 3.3V logic board you see!).

My experimental setup. The yellow device (top right) is the battery charge regulator. The PV panels are outside in the garden.

Note there is a trade off in the choice of resistor values: you want them much lower than the impedance of the ADC input, but remember that current continuously flows through this divider, so if you make them two low you'll drain the battery! In my case the current is V/R = 12V/(39k+12k) = 0.24mA: an insignificant line item in the power budget. And those values are low enough for use with the Arduino [2] [3].

My original strategy was to take one ADC value and echoed it to the serial port, pause for a few seconds and loop. But I found the data was very noisy. So instead I wrote this Arduino sketch:

void setup() {
  Serial.begin(9600);
}

void loop() {
  uint64_t a=0; // Need 64 bits due to size of sum
  int i, n = 1<<14;

  for (i = 0; i < n; i++) {
    a+=analogRead(A0);
  }

  Serial.print((int)(a>>10));
  Serial.print ("\n");
}


So I sum 16384 (2^14) ADC samples, but divide by 1024 (2^10). This is ADC oversampling and not only smooths out the noise in the signal, but gives me extra bits of ADC resolution! [4]

So my battery voltage under load (Vbat) vs time chart looks like this:


The goal here is to always keep the battery voltage under load over 12.1V (which I'm estimating to be about the 50% discharge point). [5]

For the first two days I had the panels indoors against the window. I was losing about 0.1V at the end of each day: clearly not sustainable. So I moved the panels outdoors, and this looks a little better. On days 19 June to 23 June (cloudy days with a little hazy sun) I'm losing 0.05V/day. But 24 June and 26 June were sunny and resulted in a net gain in battery voltage.

So the conclusion so far: if we had sunnier weather in Galway this setup would probably provide sustainable 24/7 power to the Raspberry Pi, at least during the summer months when the days are long. But realistically that isn't going to happen. Also in a few months the days will get shorter and the sun lower on the horizon so the available power budget will be greatly diminished. I'm not going to invest in more PV panels, so therefore I need to find ways to shed some load. Hopefully I'll follow this up with a Part 2 in a few weeks.

Footnotes:

[1] I did a quick measurement of the efficiency of the car USB charger adapter using a 10Ω resistor as a dummy load. The input (at 12V) was drawing 244mA and the output USB 5V was drawing 426mA. So the efficiency is (5 * 0.426) / (12 * 0.244) = 73%. When connected the the Raspberry Pi, hub, Arduino and WiPi I measure a mean current of 212mA  entering the 12V side of the DC/DC converter. The (approximate) efficiency of a linear regulator is Vout/Vin.

[2] The Arduino (Uno, Leanardo etc) ADC impedance is often quoted as 10k. But that's a worst case scenario where you may be using several different ADC inputs with substantially different voltages. If you're continuously sampling something close to a DC voltage (as is the case with a battery) the impedance is more in the megaohm region.
http://forum.arduino.cc/index.php?&topic=116491.msg876799#msg876799

[3] For ultra low power applications a FET transistor could be used in series with the voltage divider to switch it off when not needed.
http://www.microbuilder.eu/Tutorials/Fundamentals/MeasuringBatteryVoltage.aspx

[4] See this link for an app note on ADC oversampling:
http://www.atmel.com/Images/doc8003.pdf

[5] Information about a 12V lead acid battery:
http://en.wikipedia.org/wiki/Automotive_battery

[6] Note on 'noise' in ADC signal. Actually this is mostly due to power fluctuations in the Pi (and peripherals). I notice a small spike each time I copy the the ADC log file over the network. Or if I run any CPU intensive task. Interestingly, Vbat appears to increase when drawing more current. This is because the additional current causes a small sag in the 5V supplied to the Arduino. The Arduino is using the 5V supply as the reference for the ADC. A small sag in the reference voltage means a higher ADC reading given the same battery voltage.

Other notes:

Similar projects:

Thursday, June 13, 2013

Using a powered USB hub to both expand the USB bus and power the Pi

While the Raspberry Pi is an inexpensive little computer, all the little accessories can add up. For many applications you'll need a powered USB hub to expand the number of devices that can be connected to the Pi. But you may also be able to power the Pi from the same hub, saving you from purchasing a USB charger. It tried this with the 7 port hub available from Farnell (SKU 2115058, €10) and it worked just fine with a Model A Pi. This compares favorably with a dedicated USB charger which typically costs €6 - €10.


Update (14 June 2013): It seems it's not even necessary to use the micro USB cable (at least in the case of this hub).

Update (19 June 2013): I just noticed that the possibility of powering a Pi from a USB hub that back feeds power was mentioned in the release notes for the Revision 2 of the Rapberry Pi hardware. This is made possible by the removal of the USB port poly fuses that were present in Revision 1 hardware. However it does note that the hub must not supply more than 2.5A under fault conditions (presumably because there is no over current protection supplying power this way).