Posted on Leave a comment

Raspberry Pi Timelapse Video Generator Script & Full Script Pack Download

To cap off the series of scripts for doing easy timelapse video on the Raspberry Pi, here’s a script to generate a H.264 video from the images.


if [ -z $1 ]
    	echo "Raspberry Pi Timelapse Video Generator Script v1.0"
		echo "2015 Ben Thomson 2E0GXE"
		echo "This script will take an image folder created by the timelapse script & convert it into H.264 Video"
		echo "This script expects some options in the following format:"
		echo "./ <Folder> <File Prefix> <Output Video File Name>"
		echo "<Folder>"
		echo "The folder name with all the images"
		echo "<File Prefix>"
		echo "The file prefix before the frame number. Do not include the underscore before frame number."
		echo "<Output Video File Name>"
		echo "The output file name. The .mp4 file extension will be added by the script."
		echo "Running this script on the Raspberry Pi itself is likely to be very slow. Recommend running on a fast"
		echo "PC with a multicore CPU for high framerate."
		exit 0

avconv -r 10 -i ./$INPUTFOLDER/"$INPUTNAME"_%d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 $OUTPUTNAME.mp4


This should be run on a powerful PC rather than the Pi – generating video on the Pi itself is likely to be very slow indeed.

I have also done a quick update to the timelapse generator script to generate images of the correct size. This helps save disk space & the video generation doesn’t have to resize the images first, saving CPU cycles.


DATE=$(date +"%T_%m-%d-%y")
if [ -z $1 ]
		echo "Raspberry Pi Timelapse Script v1.2"
		echo "2015 Ben Thomson 2E0GXE"
		echo "Images will be taken in 1920x1080 format for transcoding into video."
		echo "This script expects some options in the following format:"
		echo "./ <File Prefix> <Frame Interval>"
		echo "<File Prefix> The script will prepend this name to every image as a unique capture session identifier."
		echo "A sequential number is appended to the end of the filename for frame identification."
		echo "<Frame Interval> This is the interval between frames, in milliseconds. Minimum 1250."
		echo "This minimum is required to retain stability & prevent dropped frames."
		echo "Every time the program is started, a new folder with the current date & time is created for the images."
		exit 0
		echo Frame Interval Too Low!
		echo This will cause dropped frames! Exiting!
		exit 0

mkdir -p ./$DATE-$1
echo Image Folder $DATE-$1 Created
echo Image Capture Interval $FRAME_INTERVAL ms 
echo Starting Timelapse Capture... CTRL+C To Exit...
raspistill -k -n -ex auto -awb auto -mm average -w 1920 -h 1080 -o ./$DATE-$1/$INPUTFILE.jpg -tl $FRAME_INTERVAL -t $RUNTIME

echo Timelapse Complete!
echo File Prefix: $INPUTFILE
echo Frame Interval: $FRAME_INTERVAL ms
echo Folder Name: $DATE-$1

[download id=”5595″]

73s for now!

Posted on 1 Comment

SainSmart Frequency Meter

Thanks to Lewis, M3HHY for lending me this one 🙂

Here’s a quick look at a Sainsmart frequency counter module. These are useful little gadgets, showing the locked frequency on a small LCD display.

It’s built around an ATMega328 microcontroller (µC), and an MB501L Prescaler IC. The circuit for this is very simple, and is easily traced out from the board.

Frequency Counter
Frequency Counter

Here’s the back of the board, with the µC on the left & the prescaler IC on the right. This uses a rather novel method for calibration, which is the trimmer capacitor next to the crystal. This trimmer varies the frequency of the µC’s oscillator, affecting the calibration.

Input protection is provided by a pair of 1N4148 diodes in inverse parallel. These will clamp the input to +/-1v.
The prescaler IC is set to 1/64 divide ratio. This means that for an input frequency of 433MHz, it will output a frequency of 6.765625MHz to the µC.

The software in the µC will then calculate the input frequency from this intermediate frequency. This is done because the ATMega controllers aren’t very cabable of measuring such high frequencies.

The calculated frequency is then displayed on the LCD. This is a standard HD44780 display module.


Power is provided by a 9v PP3 battery, which is then regulated down by a standard LM7805 linear regulator.


I’ve found it’s not very accurate at all at the lower frequencies, when I fed it 40MHz from a signal generator it displayed a frequency of around 74MHz. This is probably due to the prescaler & the software not being configured for such a low input. In the case for 40MHz input the scaled frequency would have been 625kHz.


Posted on Leave a comment

Water Management System PCB Revisions

OK, a few revisions have been made to the water management PCB, mainly to reduce the possibility of the brushed DC motors in the water pumps from causing the MCU to crash, with the other changes to the I/O connector positioning & finally upgrading the reverse blocking diode to a 10A capable version rather than 5A.

Water Management PCB
Water Management PCB

Thanks to Mayhew Labs with the WebGerber image generator for the render.

Posted on Leave a comment

Hydraulic Generators, Missing Valves & Liars

While sourcing the main propulsion hydraulic system for nb Tanya Louise in the summer, we thought that it would be convenient to have an on board generator that didn’t require dragging off the boat & highly explosive petrol to operate.

As the hydraulics were already being fitted, we decided to add a hydraulically driven generator to solve this issue.

And this is where the problems began…


We were referred to Mike Webb of to supply the equipment required for this part of the project, this was to include the alternator itself, hydraulic motor to drive the alternator, the required adaptor plates to mate the motor to the generator head & a control valve block to regulate the oil flow & pressure to the motor.
After a phone call to Mike on 16-07-2013 to discuss our requirements, we settled on a system. I received the following E-Mail the next day from Mike:

Good morning, reference our conversation, Martin from BSP has given me details as to what he will be supplying, on that basis and in light of the special price I have offered, this is what I propose to supply,


1 off New 8kVa – 7kW Hydraulic driven generator 220v single phase 50hz c/w flow control valve, pressure relief valve and on/off solenoid valve,  Martin did say that the engine idle is between 1000 and 1200 rpm and  max speed is 3600 rpm, valves will be rated accordingly. I have the alternator and parts available now, in order for me to be able to offer this at a significantly discounted price of £ 1.200.00 nett, I will need to utilise the components I have in stock now, so I will need payment asap, delivery will be approx. 7 days, primarily due to the fact that the coupling is fabricated to suit, I can either deliver the unit to you when ready or BSP or hold onto it until everything else is in place.  The alternator is a Meccalte S20W that I bought for another customer a few weeks ago, but he cancelled and I don’t have, at this time, anyone else interested in it, so either I do a deal with you at the above price or wait until someone else comes along and wants the unit.


With regards to installation, let me know if you need any help, but it would be best to install when the engine is being installed and the rest of the system hosed up, I assume BSP will be sorting this, in which case I’ll liase with Martin.


I trust that this meets with your approval and look forward to hearing from you.

At this point an order was placed with Mike, & the money transferred so he could begin building the unit for us. As can be seen from the E-Mail, a lead time of 7 days was stated.

After a few phone calls over the following month, firstly being told that the custom parts to mate the generator to the motor had not come back from the engineers, I sent another E-Mail to Mike on 10-09-2013, and got no reply.
Following another phone call, I was told that the generator had been shipped, however Mike would not give me any tracking details for the shipment, and would not initially tell me who it was shipped with.

Again the generator didn’t turn up.

More phone calls ensued & I was told at this point that the shipping company had been confused by the address given, shipped back to Mike. At this point I was informed that the shipping company had actually LOST  it. Several more phone calls later I was promised that a replacement generator would now ship no later than 08-10-2013. A follow up E-Mail two days later also generated no reply.

At this point I was beginning to wonder if I would ever see the goods we had paid for, but finally a shipment arrived from Mike
~15-10-2013, over TWO MONTHS after our promised delivery date. However, even having been delivered, all was not well with the goods.

Generator Pallet
Generator Pallet

Above is the generator supplied. No mounting bracket, no integrated valve block, in short, nothing like what was described in Mike’s documentation & website. The original documentation is available here for reference: [download id=”5564″]

The valve block supplied was this:

Valve Block
Valve Block
Missing Solenoid Valve
Missing Solenoid Valve

Flow control: check.
Pressure relief: check.
Control solenoid valve: Gaping hole….

As can be seen, there is an open port on the side of the valve block. This is where the ON/OFF control solenoid valve is supposed to be located.
After several more unanswered E-Mails & phone calls, I had to get somewhat more forceful in my messages, as now Mike had begun outright lying about what was specified in the original order. In which that there was no solenoid valve required. So the following E-Mail was sent 21-10-2013:


Having had a conversation with Martin, about him attempting to contact you regarding what you have supplied to us, I need this resolving ASAP now, as I am being held up by the fact that there is an open port on your valve block where the solenoid control valve is supposed to be located.

As it stands the valve block & therefore the generator you have supplied to us is useless for it’s intended purpose & I will be seeking legal advice on this matter if a resolution cannot be made this week, considering you have not replied to any E-Mail I have sent since the unit’s massively delayed arrived.

In your original correspondence it is certainly indicated that this valve was to be fitted, which was also Martin’s instruction to you.  

I await your expedient response.

This threat of legal action actually spurred a response from Mike, who finally replied with the following on 25-10-2013:



Sorry about all this, I have been away and down with a bug for the last week, I will sort this today and will have the required parts shipped to you on Monday for Tuesday delivery.




Another promise of a delivery date, so I waited a little longer, until the Friday of that week. Still no delivery. No surprise there then.
(I didn’t believe the story about illness either).

At this point I again attempted contact, but got nowhere, even with legal threats. So I’ve given up completely on this & been forced to source the parts elsewhere at extra cost.

This company is not the one to go to if you require a hydraulic generator unit for any application, as you’d be lucky to get any part of what you order on time, if at all.
Operations are run by an all out liar who seems to be happy to accept money but not ship the goods that had been paid for.

Mike having explained to me that the shipping company had lost a generator, and he would have to build me another one to replace it also does not make sense, as in the initial phone call & mail he stated that the Meccalte generator that we eventually received was a single unit that was specially ordered for another client, and the factory build date on the unit certainly gave away the fact that the generator head had been sat around for some considerable time before I came along & made a purchase.

Hopefully this post will get a high Google ranking, to ensure that anyone else who happens to be looking for a similar piece of equipment does not have the misfortune to trust this man.
We were referred to him on good faith & unfortunately in this case it did not go well.

Posted on Leave a comment

Datakom DKG-171


Here is a teardown of the Datakom DKG-171 generator transfer controller. Here is the front of the unit, with the pictogram of the system, the indicator LEDs & the generator test button.



The rear of the unit features the connection points for the mains, generator & generator control I/O.

PCB Rear
PCB Rear

Rear of the PCB with the control relays. The two larger relays switch in the remote contactors to switch the mains supply over between the grid & the generator, while the smaller relay switches 12v power out to a terminal to automatically start the generator.

PCB Front
PCB Front

Front of the PCB with the control logic & main PIC microcontroller.



Posted on Leave a comment

nbTanya Louise Generator Transfer Controller

Contactor Box
Contactor Box

Here is the latest build & addition to the boat, in preparation for delivery of an 8kVa hydraulically driven generator unit – an automatic transfer switch.
Above can be seen the completed contactor unit, mounted in the engine bay.
This unit takes feeders from both the shore power socket & the generator unit & switches them independently through to the domestic 240v AC systems on board.

Contactor switching is done by a Datakom DKG-171 automatic generator controller.

Switching Unit
Switching Unit

Here are the contactors & isolators, before fitting to the wallbox. Power comes in one the left, through the large 25A isolating switches, before feeding to a pair of 30A contactors. The pair of outer relays next to the contactors are interlocks. These ensure that when one contactor is energized, the other is electrically locked out. Even if the interlock relay is manually operated with the orange flag visible on the top of the unit, they are wired to de-energize both contactors. This ensures that under no circumstances can both power sources be connected at the same time.

Panel Cutout
Panel Cutout

The generator controller requires a 68mmx68mm panel cutout for mounting. This was done in the main panel next to the electrical locker.

Box Fitted
Box Fitted

Here the contactor board has been fitted into the wallbox & the cable glands fitted before wiring.

System Online
System Online

The generator controller fitted & finally energized. The indicator LEDs on the front of the unit let the user know where power is currently being supplied from & which contactor is energized.



Posted on Leave a comment

Raspberry Pi Geiger Counter

Geiger Counter Setup
Geiger Counter Setup

Here’s my latest project with the Pi: interfacing it with the Sparkfun Geiger counter & outputting the resulting data to a character LCD.

The geiger counter is interfaced with it’s USB port, with the random number generator firmware. A Python script reads from the serial port & every minute outputs CPM & µSv/h data to the display.

The Python code is a mash of a few different projects I found online, for different geiger counters & some of my own customisations & code to write the info to the display & convert CPM into µSv/h.

This also writes all the data into a file at /var/log/radlog.txt

The code for this is below:

import time
import sys
import serial
import os
import RPIO
from RPLCD import CharLCD
from subprocess import * 
from datetime import datetime

# configuration settings

logfile = "/var/log/radlog" # location to save log data
serial_port = "/dev/ttyUSB0"
lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24], numbering_mode=RPIO.BOARD, cols=16, rows=4, dotsize=10) #Init LCD with physical parameters

f = open(logfile,"a")

ser = serial.Serial(serial_port,9600,timeout=1)

one = 0

#Init LCD with initial values.
lcd.cursor_pos = (0, 1)
lcd.write_string("Geiger Counter")
lcd.cursor_pos = (1, 2)
lcd.cursor_pos = (2,-3)
lcd.write_string("Please Wait...")
lcd.cursor_pos = (3, 0)
lcd.write_string(str(0) +" uSv/h")
f.write("Geiger Counter Initialized\n")
while 1==1:
  stamp = int(time.time())
  stamp == round(stamp,0)
  stamp = stamp + 60
  count = 0  
  while 1==1:
      ct = int(time.time())
      ct == round(ct,0)
      if ct > stamp:  break
      #Read from serial port
      bit =
      if bit != "":
          count = count + 1
          #Conversion of counts per minute to uSv/hr
          usvh = count * 0.01
  at = str(time.asctime())
  t = str(time.time())
  #Write line to log file & print info to console
  f.write("["+at+"."+t+"] "+str(count) + " CPM " +str(usvh) + " uSv/h\n")
  print "["+at+"."+t+"] Count "+str(count) + " " + str(usvh) +" uSv/hr"
  #Send measurement info to LCD
  lcd.cursor_pos = (0, 0)
  lcd.write_string('%b %d  %H:%M:%S\n'))
  lcd.cursor_pos = (1, 0)
  lcd.write_string("Radiation Level:")
  lcd.cursor_pos = (2, 1)
  lcd.write_string(str(count) +" CPM")
  lcd.cursor_pos = (3, -1)
  lcd.write_string(str(usvh) +" uSv/h")
Info Display
Info Display