GertDuino for Raspberry Pi

GertDuino board to expand Raspberry Pi

Pictured above is the new GertDuino board, developed by Gert van Loo – inventor of the popular Raspberry Pi add-on (GPIO extension) Gert Board.

The GertDuino is designed as a Raspberry Pi add-on, and gives the best of both worlds – the low power consumption and many input/output options of Arduino with the processing power and connectivity of the Raspberry Pi.

Gertduino board mounted to Raspberry PiThe image above shows the GertDuino connected to the Raspberry Pi.

The GertDuino is based around the popular Arduino Uno with a non-surface mounted ATmega328 microcontroller which can be programmed directly from the Raspberry Pi with code written and compiled on the Raspberry Pi. The GertDuino is compatible with all existing Arduino shields (Uno).

Once programmed GertDuino can be used as a standalone board or left coupled to a Raspberry Pi if the project calls for it. When connected to Raspberry Pi, it takes its 5V power supply directly from it, but as a standalone an external 5V power supply is required.

In addition to all the functionality and input/output of the Arduino Uno, a second microcontroller has been added to GertDuino (a surface mounted ATmega48) which gives an IrDA interface to the board (infrared receiver), a real time clock (with battery back up power supply – CR1025 3V button cell, not included – and high precision crystal). There is also an RS232 interface, and a couple of user push buttons and an array of six LEDs. And all this comes at a cost comparable with an original Arduino Uno board at £22.20 inc VAT available from Farnell / Element14.com.

Of most interest to us at REUK is the ability to use the GertDuino and its real time clock to wake up the Raspberry Pi only when it is needed – for example, the GertDuino could be used to monitor battery voltages or a solar water heating system, and turn on the Raspberry Pi for just a few minutes every 12 hours to process and publish the collected data. The overall power consumption of such a system would be far less than keeping the Raspberry Pi active all the time, making it much more economical to run everything from solar power. (See our article Solar Powered Raspberry Pi for details).

The user manual for GertDuino is full of information, schematics, and more on this new Raspberry Pi add-on. Click here to download and view the GertDuino User Manual (30 page PDF).

Arduino Solar Water Heating Pump Controller Design and Code

Following on from our recent blog posts Arduino Solar Water Heating Pump Controller and Arduino Introduction, we have received a few requests for the source code (sketch) and design for a very simple Arduino based solar water heating pump controller.

We thought it would be an interesting exercise to show how just a few components and twenty or so lines of code can be turned into quite an effective controller, so here it is.

REUK.co.uk Arduino simple solar water heating pump controller - Arduino nano

For the schematic (and our own testing) we used an Arduino Nano, but pretty much any Arduino board could have been used. To that we just need to add a couple of LM335Z temperature sensors, a relay, an NPN transistor (we used a BC547), a few resistors, and a diode.

Here is a screenshot of the source code (the link to download it is at the end of this blog post):

Sketch for REUK Arduino simple solar water heating pump controller

This really is about as basic an effective microcontroller based solar water heating pump controller as it is possible to make.

The two temperature sensors connect to the (arbitrarily chosen) A0 and A2 analog pins, and the relay which switches the pump on and off to the D12 digital pin through a transistor (to limit the current drawn from the pin).

The variables diffON and diffOFF are used to set the number of degrees Celcius by which the solar panel must be hotter than the hot water tank for the pump to turn on, and then to turn off respectively. We used 6 degrees for diffON and 3 degrees for diffOFF – you may choose to use different values. These give hysteresis which prevents the pump switching on and off repeatedly and rapidly (since the temperature difference has to fall before the pump is switched off, and then rise before it will be switched on again).

The temperatures are measured every quarter of a second – delay(250) causes the programme to pause for 250 milliseconds. If the solar panel temperature is more than diffON degrees hotter than the hot water tank, the pump will turn on; and then when the temperature difference falls to diffOFF or lower the pump will turn off. And that’s it – simple, but does the job.

These LM335Z temperature sensors output a voltage of 2.73V + (X * 0.01V) where X is the temperature in degrees Celcius. The analogRead command digitises this analogue voltage to a whole number in the range 0 to 1023 with 0 corresponding to 0.00V and 1023 corresponding to 5.00V.

The calculation done on those analogRead 0-1023 values converts them into temperatures in degrees Kelvin. To convert degrees Kelvin into degrees Celcius you just subtract 273.15. That was unnecessary in this example since we are only interested in the difference between the two temperatures, but if you wanted to display the measured temperatures by connecting the Arduino board via USB to a PC that is how you would get them in Celcius.

Obviously there are a lot of things which can be added to this controller to make it more effective and reliable – e.g. time delays before the pump turns on and off, user programmability, manual override, frost protection, maximum temperature shut off, data logging and processing, and real-time temperature and system status display etc, but this is a good starting off point. There are vast amounts of resources online to help you learn more about Arduino – start with the official Arduino website to find out more.

Click here to download the Arduino source code for the REUK Simple Arduino Solar Water Heating Pump Controller as pictured above.

If you have any questions about the above or if you would like to share your modifications or enhancements to the code or design, please email neil@reuk.co.uk.

Arduino Solar Water Heating Pump Controller

The REUK 2013 Solar Water Heating Pump Controller (pictured above) is one of the most popular products on the REUK.co.uk website. With a temperature sensor on the solar water heating panel, and a second on the hot water tank, this controller decides when to turn the pump on to circulate solar heated water from the panel to the tank.

This controller is based around a PICAXE-08M2 microcontroller which gives a good balance of programmability and simplicity. It does however have one large disadvantage – it can only do integer arithmetic, i.e. performing operations on whole numbers only.

Therefore when we come to make modifications to the controller for particular customer requirements – e.g. frost protection and maximum temperature shut offs etc – things get unnecessarily complicated. Additionally there is limited memory on a PICAXE-08M2 which becomes a serious problem as the complexity of the desired programming increases.

For this reason we are currently porting a lot of our PICAXE based controllers to Arduino which allows floating point arithmetic and far more memory space.

Pictured below is our latest Arduino solar water heating pump controller. It is functionally identical to the standard 2013 PICAXE controller, but offers much more flexibility for modifications and added features.

Arduino pro mini based REUK solar water heating pump controller

The Arduino board used here is the Pro Mini – the smallest of the Arduino range. The red board plugged on to the blue Arduino board in the above photograph is used to connect the Arduino to a PC via USB for programming and/or so that data can be outputted to a serial monitor in real time or for later analysis as shown below where the temperature of the solar panel and of the hot water tank is outputted once every second. If monitoring is not required then this break out board can be removed.

Serial terminal output for arduino solar water heating pump controllerIf you have any particular requirements for a solar water heating pump controller which are not met by our standard controller range, email neil@reuk.co.uk with details of what you need.

If you are interested in building and programming your own solar water heating pump controller as a project, click here for our simple Arduino Solar Water Heating Pump Controller Design and Code which should help you get started.

Arduino Introduction

We have been receiving a lot of questions about Arduino lately, so in this blog post I will attempt to briefly cover the topics about which we are most often asked – how to get started and which Arduino boards to use.

NEW – We are now publishing the full Arduino source code for many of our projects and products here: Arduino Projects.

The official Arduino website describes Arduino as an open-source electronics prototyping platform, and it is designed to be used by anyone interested in creating interactive objects or environments. We for example use Arduino primarily in a wide range of timers and controllers which act upon measurements made of the surrounding environment using sensors such as light detectors, temperature sensors, and many types of switches.

Arduino Uno board

For anyone getting started with Arduino we would recommend the Arduino Uno board pictured above which retails in the UK for around £20. It can be powered from the USB cable which is connected to a computer when uploading your sketch (Arduino program code) to the board from the Arduino IDE (see below), or via an external 7-12V DC power supply.

Click here to download the Arduino IDE (integrated development environment) software to your PC (Windows or Linux) or Mac. This is where you will write your sketches, communicate with your Arduino board, and find lots of useful example code.

There are a wide selection of alternative Arduino boards offering different features, numbers and types of inputs and outputs, and different physical sizes and prices. These are detailed on the Arduino website.

There are also a selection of Arduino Shields which connect to Arduino boards to give additional advanced functionality – e.g. Wifi, GSM, and ethernet connectivity, motor control, SD card slot for datalogging, real time clocks, LCDs, or simple prototyping boards for you to use for added external components and/or sensors.

arduino nano and pro mini

Pictured above are the Arduino Nano and Arduino Pro Mini. These small boards are excellent for embedding in projects thanks to their small size. The Pro Mini for example is a tiny 0.7″ x 1.3″ small.

The Arduino Nano retails in the UK for around £20-25, but as Arduino is open-source, much cheaper clones are available with prices starting at around £6 only including a USB cable and air mail delivery!

Clones of the Arduino Pro Mini are available from around just £3 each, but as the image above shows, this board does have a USB connection. In order to programme the Pro Mini you need a breakout board such as the one pictured below.

ftdi basic breakout board for arduino pro mini

This is an FTDI Basic Breakout For Arduino USB-TTL 6 PIN 3.3/5V. When you want to programme the Pro Mini, you connect it to this breakout board and connect that via USB to the computer. These boards are available from around £5.

FTDI board connected to Arduino Pro Mini board

Here are the labels on the Pro Mini terminals which are hidden in the image above to show what connects to the FTDI breakout board.

Connections for ftdi breakout board on arduino pro mini board

When programming is complete, you disconnect the Pro Mini and use it in your project, and you still have your breakout board. Therefore if you are doing a lot of embedded projects, the Pro Mini is the most cost effective Arduino board to use.

The other option for projects is to prototype using an Arduino development board, and then make an Arduino standalone. For this you programme the microcontroller on the board, and then remove it (possible with the Arduino Uno and older Duemilanove boards) and add it to your own circuitry. We detail this option here: Standalone Arduino on a Breadboard.

It is getting harder to find the Uno and Duemilanove boards now as they have been superseded with the latest Arduino boards which have surface mounted microcontrollers. But, you only need the one board for prototyping and programming, and when you have one, it is easy to get the ATmega328 chips with the Arduino bootloader pre-installed for your projects.

Here are some useful links to help you find the above described items:

Arduino Uno – Rev 3.0 boards with USB cable supplied. £17+ for official boards, or from £6 for compatible clones. Make sure to choose a ‘development board’ (not surface mounted microcontroller) if you want to remove and embed the microcontroller chip in your projects. See image below (development) compared to the surface mounted version at the top of this posting.

arduino uno development board

Arduino Nano – from £12 for official boards, and from £6 for compatible clones (mostly available with included USB cable). Note that headers are usually not soldered onto cloned nanos (so they do not spike through the package in the post), but will be included for you to solder.

Arduino Pro Mini – from under £3. Supplied with headers for you to solder.

FTDI Breakout – for the Arduino Pro Mini – you just need one which you can reuse. Prices from around £5.

Arduino Duemilanove – from £10 for clones, and up to £20 for official boards. Not many available now compared to the Uno.

ATmega328 – chip supplied pre-loaded with duemilanove bootloader or Uno bootloader (choose the correct one for your board). Comes with the clock crystal and capacitors required for an Arduino standalone.

Analogue Inputs with Raspberry Pi

We have been doing a lot more work with Raspberry Pi over the last few months on some interesting projects which we will soon be covering on the REUK.co.uk website.

Raspberry Pi has an infinite number of uses and offers a great mixture of power, flexibility, and price, but it is lacking in one regard – its GPIO (general purpose input output) does not offer analogue input (ADC – analog digital converter) pins. Therefore it cannot be connected directly to non-digital temperature sensors, light detectors, or measure voltages etc. (This is in comparison to the similarly priced Beaglebone Black which offers seven  12-bit ADC pins for analogue inputs, or Arduino.)

mcp3008 10 bit adc analogue to digital converter 8 channelThere are however simple and relatively cheap ways around this, one of which we will cover here: the MCP3008 10-bit 8 channel ADC pictured above. This is a microchip which can take up to 8 analogue inputs, and communicate their digital equivalent values (0-1023) to the Raspberry Pi via the SPI serial interface.

mcp3008 board to connect to raspberry pi with light detector and other analogue inputs

Pictured above is a small board we have made with the MCP3008 at its centre. Coming in on the left side are six connections to the Raspberry Pi GPIO – 3.3V and GND power connections, and the four connections for the SPI interface.

male to female jumper links for raspberry pi

To make the connections to the GPIO we used male to female jumper links. The female end pushes over a GPIO pin, and the male end goes into a screw in terminal on our MCP3008 board.

raspberry pi GPIO analogue inputs

In order to set up the Raspberry Pi to use the SPI interface there are some commands which are required and you also need to install the SpiDev module. This is all detailed together with connection diagrams in the links to some external resources at the end of this post.

Python code for raspberry pi analogue light detector input

The above shows the simple Python script we used to measure the light level of a light detector connected to our MCP3008 board (making a voltage divider with the light detector and a 10K resistor and feeding the output voltage into channel 0 of the MCP3008 ADC chip. The script simply measures the light level once per second and outputs it to the terminal.

Python light detector on raspberry pi outputThe measured light level is given a digital value from 0-1023. As we wired it, higher values correspond to darker light levels, so the above screen shot shows the results as the light detector was slowly shaded.

Having got the digital value for the analog light level in the Raspberry Pi, you can do anything with it – control lights, detect dawn and dusk, control motorised curtains, log it, view it online and so on. It is also possible to use the exact same technique and MCP3008 to measure a huge range of other analogue signals including temperature sensors, voltage measurement, potentiometers, etc.

Here are links to some useful resources online to find out more information about reading analogue signals with a Raspberry Pi:

Analogue Sensors on the Raspberry Pi Using an MCP3008 – this offers comprehensive details on setting up the Raspberry Pi for SPI as well as connecting it to the MCP3008 and related Python scripts.

Analog Inputs for Raspberry Pi using MCP3008 – a guide from Adafruit.

MCP3008 Datasheet – get a better understanding of the ADC.

Target Controller for Competitive Shooting

Pictured below is a controller we have just made for use in competitive shooting. The competitor has a line of five targets to hit, each of which has a microswitch which closes when the hit target flips over. When each target is hit, an LED lights up, and when all five targets have been hit and all five lights lit, the lights flash on and off five times before the system resets for the next competitor.

Controller for competitive shooting with five targets and five lights which turn on when targets are hit.

We made this as a standalone Arduino project with the ATmega328 microcontroller. This has more than enough IO (input/output) pins to cope with the five inputs (target microswitches) and five outputs (LED lights switched by MOSFETs). The lights are 12VDC powered, so the controller was also made to be powered by 12VDC.

24V Low Voltage Disconnect with Data Display

We have just finished working on a new low voltage disconnect project for a customer who supplies batteries and power inverters to consumers. Quite often his customers make complaints that the batteries have failed after a relatively short period of time, but he had no way of knowing if there was a problem with the battery or (more likely) a problem with the way the battery has been used and cared for.

connection diagram for 24v low voltage disconnect with LCD displayPictured above is the low voltage disconnect with datalogger we made to solve this problem.  The low voltage threshold at which the connected power inverter will be turned off, and the cancellation voltage at which it will be turned back on again can be set before installing the system. A low voltage of 22-24V is likely to be used and a cancellation of voltage of 24-26V for this 24V battery system.

So that the treatment of the batteries can be assessed later, this controller has a built in datalogger. Every 12 hours it records the voltage measured on the connected batteries. Up to 200 data points can be stored in memory for a record of 100 days of activity. If more than 200 are collected then the earlier data points are over-written so that only the most recent 200 are stored.

24V low voltage disconnect with datalogger and display

If/when the system is returned, an LCD display can be connected which enables the 200 data points to be stepped through from most recent to oldest, and a summary is also generated which displays how many times each voltage (from 1V to 35V) was recorded over the last 100 days. Using this data it is possible to see if the batteries were left uncharged for an extended period of time (very harmful to battery life), and how often they were run down to low charge levels (also bad for batteries).

If you need a low voltage disconnect and/or a datalogger, contact neil@reuk.co.uk with details of your specific requirements.