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.

Sunday 25 November 2012

Microcontrollers Revisited

Quite a few years ago (probably 10), I started getting interested in using microcontrollers to do small computing tasks that required input-output, and low power consumption.   I did not get very far with them because every time I wanted to do something, I would have to write software from scratch (to talk to a display or sensor etc.).  Also there was a lot of soldering involved to put the boards together, with crytstals, capacitors etc. to support the microcontroller.

I recently discovered Arduino (http://arduino.cc), which is a simple microcontroller with a standard PCB board layout, where assembled boards are sold cheaply.  The Arduino Uno seems like a good one to use for prototypes, as all the I/O pins are taken out to headers that you can attach jumper wires to easily.   For 'production'  versions though, the Arduino Nano seems like a better option, as it is much smaller, and you can solder connections directly onto the board rather than using jumpers etc.  I bought a few of these (or at least clones of them) very cheap (~£11 each) off Ebay.

You can download a simple development environment where you can write the code for the boards in C/C++, compile it, and load it onto the board via USB - seems to work very well.

By far the best feature of Arduino though is the user contributed libraries - there are libraries for accessing one-wire devices, LCD displays etc., so you do not have to start from scratch for each project, which makes development much, much quicker.

So, I am starting to think of all of those 'I could make one of those, but it is a bit of a waste to use a full-blown computer for it' projects.   The ones I am starting on are:

  • Solar Thermal Monitor (Power Meter for water heater solar panel) - I have a first version working - see the solThMon directory in my Github repository.  A bit more description is provided in the github wiki.
  • Alternative Weather Station Receiver - the idea is to use a simple 433MHz radio receiver to read the signals from our weather station, so we do not need the big LCD display that came with it (no progress yet, but I have the hardware for it...).
To give an idea of what these things look like, here is a picture:

Sunday 29 July 2012

Making Videos from Images

My daughter collected a nice series of images of the demolition of the old Steetley chimney in Hartlepool:

There are 25 images, so we thought it would be nice to make a little movie of them.
First they need a bit of processing, because the horizontal is not level.   We rotated the images, and trimmed off the edges to straighten them up using ImageMagick using:
mogrify -resize '700' -rotate 4 -shave '50x60' -resize '640' *.JPG 
This re-sizes the images to 700 pixels wide, rotates clockwise by 4 deg, shaves 50 pixels of the top and bottom, and 60 pixels off the sides.  It then re-sizes to 640 pixels wide. We then turned it into an mp4 avi movie file using mplayer's mencoder using:
mencoder "mf://*.JPG" -mf fps=4 -o Steetley.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800 -vf scale=640:480
This plays nicely using mplayer, and uploads to flickr too.

Final movie is here:
Or on Flickr here








Saturday 7 July 2012

Webcam using NLSU2 and OpenWRT

I am trying to set up a simple web camera to take some photos and videos of birds on our bird table.
I have had an edimax ip camera for a long time, but have had some trouble with using and configuring it from Linux.  So, I am having an attempt with a different approach from bits of hardware I have around.   There is a Linksys NLSLU2, which is made as a network storage device, and I just picked up a logitech usb web camera.   I decided to use OpenWRT as the operating system, because I used that on a previous project (bifferboard weather station).
This post is a few notes of where I have got to, and the problems encountered.

Operating System

  • Download OpenWRT:   To start with I used a tarball of OpenWRT 'backfire' 10.03, but it problems with packages not being compatible.   Rather than understand why, I went for checking out the latest source code from the 'backfire' branch of the OpenWRT SVN repository.
  • Build OpenWRT:  This is as simple as changing into the source directory and doing 'make menuconfig', selecting the target system as 'IXP4xx', then the profile as NSLU2, exiting and typing 'make'.   This creates a flash disk image as bin/ixp4xx/openwrt-nslu2-squashfs.bin.
  • Put the NSLU2 into upgrade mode by powering off, pressing and holding the reset button with a paper clip then powering on.  Wait for ~10 sec until the top LED changes colour (very difficult for me to tell as I am colour blind...), then release the reset button.  The top LED now flashes two slightly different colours.
  • Connect the computer with the OpenWRT image on it to the same ethernet network as the NSLU2 - Wireless connections do not work!.
  • Flash the new image onto the NSLU2 using 'sudo upslug2 -i openwrt-nslu2-squashfs.bin'.
  • Once the flashing is complete, the NSLU2 reboots and you should be able to telnet into it - default ip address is 192.168.1.1, which is a pain if that is the same one as your router...
Configuring OpenWRT
The basic OpenWRT build does not do much, so it needs to be configured and the extra required packages adding:
  • Default IP Address - this can be set by editing package/base-files/files/etc/config/network [there is probably a better way to do this, but this works...].
  • Add the drivers for the USB video cameras - using menuconfig select them in the kernel config section - make sure they are selected to be built-in [*] rather than modules [M], because otherwise they are not included in the flash drive image.
  • Add some software to do something with the video source - add the mjpg-streamer and motion packages.
  • Re-build OpenWRT and re-flash it.
  • You should now be able to look at :8080?action=stream and see the image from the camera from mjpeg-stream
Making it Do Something Useful
  • mjpg-streamer seems to work nicely and produces a jpeg stream that can be viewed on a browser.  No sound though - will have to look into how to deal with that.
  • motion also seems to work - need to modify /etc/motion.conf to tell it what to do.
  • I would really like to to record video clips when motion is detected, so am currently trying to see if I can build ffmpeg to link that to motion.....
  • I have run out of time this weekend.  What I have done is just used motion and removed mjpeg-streamer, as motion provides a mjpeg stream too.  The basic set-up is:
  • Logitec usb web cam.
  • Motion records images to /tmp/cam1/// - separated into different directories to stop the numbers of files getting out of hand.
  • A little php script /cgi-bin/browse.php is used to browse through the directories and view the images.
  • I could not get ffmpeg to compile, so no videos for now.
  • This is going to be installed at my sisters, so will have to talk her through setting up her router so I can ssh into it remotely to fix it when it does not work.....
  • My version, using the same motion and php script set up, but using the edimax ip camera can be seen at http://maps.webhop.net/webcam.

Tuesday 8 May 2012

Trouble with Ubuntu 12.04 LTS

Over the last few days I have upgraded my family's computers from Ubuntu 11.10 to 12.04.   I had been getting a bit over-confident at how good Ubuntu was, and so was not really worried about things going wrong during the upgrade, as I would have been in the past - it had been getting to the state that it 'just worked'.   So I made the mistake of doing the upgrade over a weekend when we were particularly busy, which meant it was a particular pain when things went wrong.   The issues we have had are:

  1. Our PackardBell OneTwo was un-useable - booted to a black screen - didn't have chance to work out why so I just saved some logs to report the bug later, and re-installed 11.10.
  2. My home server (my old Fujitsu Amilio laptop) appeared to upgrade without problems...but every time I tried to access it, it was dead.   I think it was suspending, even though I had set the power settings to never suspend.   Have tried leaving the lid open, with me logged in, with the screen blanked - seemed to be working when I left - need to work out what was going on there....

Monday 7 May 2012

More on Samsung CLP-325w on Ubuntu

I have been pretty pleased with the Samsung CLP-325w - working nicely from my daughter's Ubuntu PC.
Have just had to re-install Ubuntu 11.10 on that (see separate post), so need to get the printer working again.
I had received a question about why I did not use an open source driver, and used the Samsung one last time.   The main reason was that the 'Recommended' driver when I installed the printer only worked in monochrome, not colour.
Just tried again, and used the 'recommended' driver, which was a generic PCL6 one.  Again this printed monochrome, until I realised that under the 'Printing' options it defaults to 'Normal (monochrome)' print quality.  Changing that to 'Normal' got it printing in colour.
Currently using it plugged into the USB port on the computer, because having a bit of trouble with network printing - job for next weekend.

Ubuntu 12.04 on Packard Bell OneTwo

Some of my previous posts have described my experiences of running Ubuntu Linux on my daughter's Packard Bell OneTwo 'all in one' touch screen computer.

Ubuntu 11.10 was working fine, but updated it to 12.04 last night.   No errors during update, and it was late when it finished so switched it off and went to bed.   This afternoon she reported that she had to resort to booting Windows because Ubuntu does not work - she got a black screen that she left waiting for 5 min, before giving up and booting Windows.

From a quick fiddle booting in 'recovery mode' and trying the safe graphics option, I think it is something to do with the graphics hardware not working, but am going to have to investigate more....just lent her my laptop to do her homework for now....

Went through a few options that I found on the internet, but none seemed to be quite my problem.  Also tried running 12.04 from a memory stick in case the upgrade had gone wrong, but it failed to work that way too....So I gave up - saved a selection of files from /var/log/ and re-installed Ubuntu 11.10.

Saturday 14 April 2012

Android Development on 64 Bit Ubuntu

I have been getting back into Android development over the last few days (more on that in future post).  Because I was travelling I initially set up the development environment (Eclipse) on my work laptop running Windows XP.   All worked fine.
Then I tried to continue work on my Lenovo laptop running Ubuntu 11.10, 64 bit edition.   It refused to build R.java, which contains all the resources such as screen layouts.  No errors to say why......

After much grumbling, searching on google and reinstalling eclipse and the android sdks without success, I discovered that to get it to work on a 64 bit machine you need to install a package called ia32-libs.   (http://developer.android.com/sdk/installing.html#troubleshooting).  Don't know why, but installing it has got it building android packages again - phew!   Should have read all the way to the bottom of the page, rather than just scanning.....

Friday 3 February 2012

Ubuntu 11.10 on a Lenovo G570 Laptop

I have just bought myself a new laptop.  I got a Lenovo G570 from PC World for just under £450.  It seems pretty good Intel i5 processor with 4GB Ram.

Installed the 64 bit version of Ubuntu 11.10.  Installation went without hitch.  Initial boot hang for some reason, but switching it off and on again solved that, and it has worked fine since.   Basically everything I have tried worked out of the box - screen, track pad mouse, web cam, USB.   Therefore absolutely no issues - a very good advert for Lenovo and Ubuntu.

I was really surprised at how powerful it is - I just installed a simple OSM tile server on it using the instructions at http://wiki.openstreetmap.org/wiki/Ubuntu_tile_server.   Loading the british isles OSM data extract took less than 2 hours.   My home server (ex laptop) - an intel dual core processor and 2GB Ram running 32 bit Ubuntu takes almost 24 hours.

I am thinking I should have bought 2 of them and use one as the server - it only uses 20 Watts when running at low load, which is probably less than my existing one.....

Sunday 1 January 2012

Using Blender 2.5

My daughter and I have been trying to learn to use Blender 2.5 to crate 3D models for use in our simple games for Benjamin.   It has proved harder than I had expected!   The main issue seems to be that most tutorials are written for Blender 2.4, and there are lots of changes to the user interfaces in 2.5.  Plus the official documentation is still for 2.4 and documentation for 2.6 is in preparation...but not 2.5.

This is a few reminders for us for how to do things.   I will add more as I work them out.

Adding an armature to pose a model:
See http://www.youtube.com/watch?v=nNTyE9SGRYw for details of linking bones using inverse kinematics.  The author has a web site with a lot of additional information here.
  1. Add a bone in Object Mode
  2. Go to edit mode and position the bone within the model mesh.
  3. Extrude the bone to add a joint (e.g. elbow)
  4. In Object mode select the model mesh then shift-right click to select the bone.   Do control-P to bring up the 'parenting' menu and select Armature Deform with Automatic Weights.
  5. Set the model view to solid (or texture), and in the armature properties menu, select X-Ray so that you can see the bones.
  6. You can now enter pose mode and move the armature to pose the model.
  7. To do a complete skeleton you should set up the back bone to be the parents of all the other bones so you can just grab the back bone to move the model.