Sunday, 16 December 2012

Approaching a working version of Arduino Solar Monitor

Christmas is coming, so I have to get a working version of the Arduino Solar Panel monitor.

My original intent was that it would have the following features:

  1. Measure the collector differential temperature.
  2. Infer the water flow rate from pump speed.
  3. Calculate the instantaneous power being collected.
  4. Calculate hourly and daily average powers.
  5. Log this information to an SD card.
  6. To achieve (5) easily, derive the time from an external Real-Time-Clock (RTC).
Now, features 1-3 are working, phew.   Feature 5 is implemented, but I need to think about what I really want (is daily average power useful?  Or should I just integrate total heat collected in a day?

Features 5 and 6 are proving troublesome, as I think I am starting to get to the limit of a single Arduino board (or more precisely the ATMega 328 controller on the board).

The main problem is that I am running out of RAM, and am going to have to give some serious thought to how to manage it better (just like old times programming a Zilog Z80A.....).

One problem is the number of different interfaces (and hence libraries) that I am having to use to achieve this.  The base software uses:
  1. OneWire.h and DallasTemperature.h to do the temperature monitoring, using a One-Wire bus.
  2. LiquidCrystal.h to drive the LCD display, using parallel data transfer
To add SD card support and a real time clock, I will need:
  1. Wire.h and DS1307RTC.h to access the real time clock from an I2C interface.
  2. SD.h to access the SD card from a SPI interface.
Each library uses a bit of ram , and there is only 2k of ram on the chip, so I am running out of it rapidly.  When I tried to add the RTC code, the board re-booted every few seconds, which I think was an out of memory issue.

So, the de-scoped system is not going to do SD card logging.  As compensation I have added switches to the two spare digital lines to use to provide a simple user interface so you can scroll between instantaneous, hourly and daily data, and maybe even set the clock (but I do worry about running out of RAM again if I get too adventurous!

Given this, I have put the 'Version 1' hardware together, and mounted it in a cheap 2 gang socket pattress box with a blank cover cut out to hold the board:
The toggle switch on the front is for the display back-light - I thought that would be easier than a push-button if you were trying to use buttons for the interface - the new buttons are facing the bottom of the picture on the side of the front panel, so you can't see them on this photo (and I made a mess of cutting the holes for them, so it looks a bit ugly...).

Right, just got to sort out the software now.  Current version is on github.

Sunday, 9 December 2012

Odd Behaviour of Arduino

I think I have got too used to working on large computers, which have essentially infinite resources, as far as my little projects are concerned, so I am having a bit of trouble with Arduino.   The two interesting problems I have seen are:


  1. Low Battery:  The symptoms were the device operating ok for quite a while (initially around an hour, but later ~5 minutes), then doing very unexpected things - what I saw was the pin 13 LED flashing on and off, but my software was not doing anything with that pin.   It looked like the board had just lost its marbles.   It turned out that the issue was low voltage on the 9V battery that was powering it - I did not realise initially because the LED back light on the display worked fine, which is the test I was using for 'it has got power'.  When I put a volt meter on it, it was only providing around 5.3V, so I think that this was insufficient to start the arduino properly...but surprisingly was enough to light the LED ok - I have always thought that LEDs need more power than little electronic devices, so if the LED is ok, it has enough power - this is not true, so I must think of another simple check!
  2. Out of Memory:  My solar thermal monitor now works nicely with an LCD display, and I made a simple test program to write data to an SD card.  The odd thing is that merging the two together results in a program that compiles ok and loads onto the device, but when it tries to write to the SD card, the arduino re-starts (I had worse effects earlier when it would just not start at all, until I removed some code in the setup function that writes to the SD card).  I think it must be running out of memory, but I need to do some work to check this...will update this once I have fixed it.

Sunday, 2 December 2012

Arduino Based Solar Panel Power Monitor

My dad has a solar thermal collector on his roof (2x20 vacuum tube collectors).   His commercial controller gives total kWh collected, but I want an instantaneous kW indication.   I am developing this using Arduino (see Microcontrollers Revisited).

Version 1 used a 7 segment LED display:
But I have now received an LCD display off the slow boat from China courtesy of Ebay, so wanted to update it to give more information on the display.
The updated board is shown below:

I made a little mistake when I was modifying the circuit board, and when I added the LCD contrast potentiometer, I accidentally left it one of the digital output pins connected to ground if you turned the potentiometer too far.   The Arduino board suddenly stopped working altogeher, so I thought I had fried it.  I was pleasantly surprised when I powered it from a 9V battery rather than from the USB socket, because it came back to life and appeared to work normally.
We installed it on the panel, and started to get sensible readings off it this morning (see above picture), but it was reported dead this afternoon, with the Pin 13 LED flashing every now and then (which is odd because my software does not use Pin 13)....It starts to work if you power it down for a few minutes, but within 10 mins it crashes again with Pin 13 LED flashing.....So I think it is dead - will de-solder the nano and put another one in instead....

Well, replaced Arduino nano on the PCB with a new one.   It worked fine....for a while (10-15 mins), then as I was packing up, I noticed that the display was very dim, but the LED back light still worked ok, which made me think the battery was ok.   5 minutes later, it was doing the same behaviour as the previous one - no LCD display, and the Pin 13 LED flashing.   This time though, the new Aruino Nano has a working voltage regulator on the USB port.  When I plugged the board into the computer via USB, the board reset and is working fine again.....I must put a current meter on the 9V battery to make sure it is not pulling a ridiculous current or something.  If I am lucky it was just a dead battery, but I am still surprised that the LED backlight worked ok, when the arduino could not boot...I'll have to think about this a bit more...

There was definitely a dead battery involved - the 9V battery was only giving 5.9V, so I can see why the 5V voltage regulator may have been struggling.  The thing I need to find out though, is why is the battery dead?  This should be a nice low power circuit, but I will have to get a new one and check the current it is drawing.