Category Archives: Arduino

Solar Datalogging project is working again!

I’ve been curious about solar energy for quite a long time.   Not really from a ‘renewable energy’ point of view, more the physics and efficiencies.   I recently went to the Mediterranean and saw a LOT of solar thermal and photo voltaic installs.   So here is an experiment to test how they both work in the UK climate.

The experiment uses the following collectors

  • 10W 12V solar cell (I had it spare from a previous project that went nowhere)
  • 58mm diameter x 500mm long evacuated tube heat pipe solar thermal collector.   I love ebay!

Both are mounted to the wall of my garage at the same angle as the roof.   Essentially emulating a system placed on the garage roof.   Why the garage?   Just cos its easier and the roof points the same way as the house.

The test load for the PV is pretty simple.   a 30ohm resistor on a heatsink.   I measure the voltage and power is V^2 * load resistance.

The solar thermal isn’t quite so easy.   First plan involved thermocouples, pumps and flow meters.   But when you actually work out the accuracy of the flow meter and thermocouples vs just how little temperature gain you will get the numbers would have been so fuzzy and worthless.   OK, take two!

Second plan involved a peristaltic dosing pump and some Dallas DS18B20 temp sensors.   Dosing pumps give a known volume of liquid per revolution and the DS12B20 could be put right in the flow.   No analogue wires to pick up noise.

I got a tiny pump from ebay.   Cost only a few quid.   Basically a 360 motor with a 3 rotor pump head and some 2mm ID silicone hose.   I fitted it with an IR reflective sensor to measure the RPM.   Worked well!

dosing

The whole setup was run by a Raspberry Pi with a GertDuino addon board.   Not enough IO on the raspberry and I can code Atmels in my sleep.   And the spare IO was connected to the leftover parts of an old Maplin wireless weather station.   Result!

_1020700

The data was logged with WeeWx.   Its simple and easy to modify, although Python is the work of the devil.

I used copper brake pipe to make a heat exchanger for the solar thermal collector.   Brake pipe can be a mare to work with and making a tight coil is hard.   I have a lathe so I made a jig to bend the pipe around.

_1020694

The final coil fitted snugly over the top of the heat pipe.

_1020695

The whole lot would be covered in 1″ thick pipe insulation.   No way heat is leaking out!   30% glycol solution would ensure no freezing!

P1040403

Small box on the solar cell is the outdoor temp and humidity sensor, it doesn’t live there normally!   The pipe insulation is to stop me catching my arm on the corners.

It worked well for about a month.   Then I started getting really bonkers thermal readings.   Turns out the little pump which was spinning at 100+RPM had split its silicone tube and leaked everywhere!   Couldn’t find any suitable tube to replace it so shelved that part for a while.

The weather station and PV logging worked for another 2 months or so before a power cut claimed the file system on the Raspberry Pi.   My fault for not backing it up!   So 4 month ish of data lost.   Bah!   Take three!

So gone is the ebay dosing pump and the Raspberry Pi is off to a new home on something less 24/7.   OK, what next?   Well as I’d based this on a GertDuino I decided to go whole hog and use all Arduino based hardware.   I had an Uno lying around and ordered up an ethernet shield.   Job done, send the data straight to my server which has a big UPS powering it.

I found a stepper motor based peristaltic pump which would be ideal apart from the price.   This whole project has cost very little as its basically odds and ends and cheap bits from ebay.   the Pi and GertDuino were the largest capital investments so far.

Hmm.. I have a stepper motor and drive spare.. I have a workshop where I can make stuff.. how hard is a pump?   Well not very!   A block of delrin made the base and some aluminium made a rotor with some more delrin for the rollers.   A length of santoprene tube finished it off.   One DIY stepper motor pump.

P1040401

From left to right:

  • Cooling coil for the fluid returning from the solar collector (yes, its a failed brake pipe coil)
  • 1ltr container for the heat transfer fluid (Tesco mini chocolate rolls, yum!)
  • Pump, 3.5cc per revolution
  • Upper right hand end – Arduino Uno, ethernet shield and some veroboard for signal conditioning and connectors
  • Lower right hand end – PV load and heatsink

So now we are back in business and logging data!   A bit of fine tuning to do but it will be done before June 21st!   Want to get that high sun logged.

Arduino – They got it mostly right!

In classic Fast Show style – this week I have been mostly programming Arduino.

After the demise of my RaspberryPi/Gertduino weather station project I decided to go fully Arduino.   I’d bought 2 Uno clones from ebay and never did much with them, so time to put them to use!

Next I bought the ethernet shield.   About £10 has bought be an ‘internet of things’ building platform.   The plan was to have the weather station based in the garage reporting via IP to the Linux server in the house.   That way the outboard station was all flash based with no local storage.   I’ve used Atmel AVRs a LOT and know they are pretty robust.   No more worries about SD cards eating themselves!

All the code for the gerduino (which handled the time critical and analogue elements of the weather monitoring) was all written in vanilla C.   As I’m used to.   Lots of use of interrupts, printf (yes, I’m lazy) and some bit bashing too.

As I wanted to use the ethernet shield I could either convert to the Arduino build env or try and mate the Arduino libs with vanilla C.   A quick look around showed that using the C++ libs with vanilla C was like trying to drink the water of life.   Many have tried, few have come out of the experience with their sanity intact.

So time to get friendly with the way the Arduino IDE works.   The setup and loop is very neat, you can get something working in very few lines of code.   Even the ethernet libs were pretty simple.   Take up acres of flash, but pretty simple! 🙂

Stumbling blocks… I use the 1ms(ish) interrupt for things other than just counting milliseconds.   I don’t want to put time critical stuff in the loop section as the timing in there is uncertain.   I don’t want to use timers 1 or 2 as they are used to control the solar thermal experiment. (details later, it needs a new pump)   So cue a bit of core code hacking to add a function pointer to the end of the timer0 overflow.
static volatile voidFuncPtr intMsFunc = 0;

// volatile static voidFuncPtr twiIntFunc;

void attachMsInterrupt(void (*userFunc)(void)) {
intMsFunc = userFunc;
}
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(TIMER0_OVF_vect)
#endif
{
// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsigned long m = timer0_millis;
unsigned char f = timer0_fract;

m += MILLIS_INC;
f += FRACT_INC;
if (f >= FRACT_MAX) {
f -= FRACT_MAX;
m += 1;
}

timer0_fract = f;
timer0_millis = m;
timer0_overflow_count++;

if(intMsFunc)
intMsFunc();
}

So I’m pretty much on track.   Didn’t bother to use the library ADC functions as I oversample to get 12 bits.   The cheap chinese wind direction I’m using sensor is a bit crude and some of the direction values are too close together for accurate detection in 10 bits.

The onewire lib worked first time.   EEprom, serial, TCP sockets etc.. all seemed to fall into place.   They’ve  all done a good job.   TWI was a bit funky as the examples are a bit lacking.   Its also interrupt based which is something I’ve not done on the atmega.   And of course it takes the address shifted down by 1… they don’t really mention that bit 🙂

So what about gotchas… the serial writes!   Don’t use them in interrupts, they don’t work 🙂   To stop the serial writes from blocking they use a software buffer and interrupts.   Makes sense, anyone coming to this new won’t realise that sending strings at 9600 baud takes a really long time and it will mess up your carefully calculated delays.   But of course when in an ISR in atmel world all the interrupts are turned off!

Also, just like with printf you use up huge amounts of SRAM with the format strings.   Remember to put F() around your text!   Saves hundreds of bytes.   I always use rom_printf.   An inline that puts the format string in PROGMEM.

Just to make life complex I found arduino-netboot.   A small bootloader that uses BOOTP and tftp to update an ethernet equipped Arduino.   Luckily I have a JTAGIceMkII to hand so could re-program the bootloader.   That was the easy bit… turns out my 3com switch blocks BOOTP when spanning tree is turned on… that took me a while to figure out…

It needs a binary file for the tftp.   Not easy getting these from the Arduino IDE.   Simple way is to find the temp dir and avr-objcopy them yourself.   Yuk!   I wrote a bat file that creates the .hex and a .bin and copies it to the tftp dir.   Hacked platform.txt to make it call my bat file instead of avr-objcopy.   Would have been nice if they’d used makefiles… ho hum.

So now I have a fully Arduino based weather station based in the garage which boots off the network and reports back to WeeWx over TCP.   Lets see how reliable this incarnation of my ‘made from spare parts’ weather station is.