Mini Project: Porting RFM69 Library from Arduino to MBED

TLDR: Here is an RFM69 OOK library for MBED.

For an upcoming project I am using the RFM69 module by HopeRF.

The RFM69HW is a transceiver module capable of operation over a wide frequency range, including the 315, 433,868 and 915MHz license-free ISM (Industry Scientific and Medical) frequency bands.

Continue reading “Mini Project: Porting RFM69 Library from Arduino to MBED”

Mini Project: Infra-red Repeater

As part of a larger project I’m thinking about, I wanted to see how easy it would be to make a TV remote control repeater. What it needs to do is listen for a TV remote control command, learn the command and then repeatedly send out that command.

Only 3 external components required. (I used four).

Only 3 external components required. (I used four).

For the processor I am using an Arduino Mega 2560 rip-off with the Arduino bootloader removed so that it is effectively just a development board for an Atmega2560. This has far more pins than I need, but it is very suitable for development. I am programming it using Atmel Studio 6.2 in C via an AVRISP MKII.

On the input I am using a TSOP31238 Infra-red receiver module. There are thousands of variations of this type of component, but this one has three pins:

GND Connect to ground
VCC 2.5V-5.5V
OUT Outputs low when there is a 38kHz IR signal incident on the receiver, otherwise outputs high

Therefore, it is easy to detect when an IR pulse is sent from a TV remote by listening to the output pin and waiting for it’s voltage to drop.

On the output, I am using an IR LED connected directly to the output of the Atmega, in series with a 156Ω resistor (actually a 100Ω + a 56Ω). This limits the current to about 20mA.

The code is relatively simple in concept. When the processor detects the first falling edge on the input pin, it starts a timer. Each time the input pin changes state, it stores the value of the timer in an array and resets the timer. If the timer overflows, this is taken to mean the command is over. This leaves us with an array of integers indicating how long the signal must be low or high.

The input from the IR Receiver module. The signal drops low when there is a 38kHz signal incident.

The input from the IR Receiver module. The signal drops low when there is a 38kHz signal incident. (Timebase in milliseconds).

The processor then uses the same timer to activate the output pin with the same timing as the input signal by reading back the array of integers.

There is a slight complication in that the output signal has to modulate a 38kHz square wave. This is achieved by using another timer to generate a 38kHz signal, which is then outputted to the LED only if the other timer indicates that the output should be high.

The output from the processor. The red blocks are actually 38kHz pulses.

The output from the processor. The red blocks are actually 38kHz pulses.

It then sends the signal once a second.

This works very well and it can easily copy the signals from my TV remote and repeat them to the TV. The only issue at the moment is that this method of storing the pulses takes up a relatively large amount of space – approximately 300 bytes for one command.

Project: Smart Watch – Case First Attempt Part 2

I like to think today has been pretty productive. Major advances on the case have been made to the extent that it can now be strapped to my wrist. 20140720_20221820140720_202225 Clearly there is no power the the watch, because the strap is only temporary and doesn’t contain a battery. Furthermore, the buttons are covered by a layer of plastic and cannot be pressed (more on this in another post). However, I am happy with the shape of it and am confident it can be progressed. The case consists of only two parts which will (probably) be held together with a rubber band.

Structure of the case

Structure of the case

The next step will be to drill holes for the power wires and also attach velcro for the strap.

Project: Smart Watch – Main Circuitry complete

After a bit of a break, I finally continued with the project. The first thing to do was to solder on pins to which the power is connected – pretty simple.

Then came the harder bit of attaching the bluetooth module. This was scary as it was so close to the dodgy jumpers I had soldered before and I didn’t want to melt the solder holding the jumpers in place. To minimise damage should this occur, I covered the jumpers in super glue so that, even if the solder melted, the jumpers would be held in place. With a quick dab of solder the joints were made and everything worked. A small anti-climax but a large relief.

I later realised that the bluetooth module isn’t quite parallel to the other two board, but there’s no way I’m desoldering it.

I modified my original code to fit the new board and tried it out. Here are the results:

It might be a little fragile, but it works and hopefully when it is in it’s case, it will be protected and comfortable.

Project: Smart Watch – Making PCB + Destroying PCB (oops)

Today was the day I etched the (first) PCB. I began by printing the design onto paper and ironing the trace onto a copper clad board (remembering to mirror the image because it is SMD).



I then etched the board in Ferric Chloride, washed it, cut it to shape and drilled the necessary holes.


After multiple rounds of checking connections and scraping off incorrect connections it was time to ATTEMPT to solder the SMD components.

I began with the resistors. What I had done before was to pre-solder the pads before placing the components down. Massive mistake. This deposited loads of solder on each pad meaning I had to reheat and “solder-suck” repeatedly resulting in traces melting off the board and ruining it 😦

Accepting that this was a lost cause I chose to practice different methods of soldering.

I finally came upon the perfect method: Flux on the component, a tiny bit of solder on the component, flux on the pads, hold the component down with a sewing needle and heat each pad. This resulted in really neat joints which somewhat made up for the disaster.


Sorry for the poor image quality

Perhaps you can just make out some very neat resistors to the left and right and a complete massacre in the centre. I think this speaks for itself.

I will repeat this process again tomorrow, hopefully with happier results.

Project: Smart Watch – First Thoughts on Case

Perhaps a bit prematurely, I wanted to start designing the case for the watch.

The main principles of this case will be:



Attachable/Removable to/from a watch strap

Two contacts to allow for power input.

Ideally I would like to 3D-print the case, but since I don’t have a 3D-printer I need to make sure I get it right first time because it’s pretty costly to buy individual items online. (Or perhaps I could get access to one at uni?)

Therefore I have decided to first make a prototype of the case by layering up 1mm thick cross-sections of plastic.

I used PTC Creo Parametric 2.0 to design a first draft of the case and this is what I came up with:

PTC Creo design. Left to right: Hidden line, shaded, 3rd angle drawing

PTC Creo design. Left to right: Hidden line, shaded, 3rd angle drawing

So, this design includes:

Floor/short-edge panels at each end for a large metal contact set into the body. A small screw will pass through the body to connect GND and VCC to the outside of the strap.

Outer edge panels (each with a small screw) to connect the transparent top cover. Having not actually designed the cover yet, this part may well change.

I’m pretty pleased with the design. Possible modifications include thinner walls, thinner pannels… and everything.

Project: Smart Watch – Circuit Board

The watch has to be skinny, and compact. I wanted as many LEDs as possible and a minimum of 2 switches, but 4 would be best.

In this vein I delved for the first time into surface mount (SMD) components. In the end I ordered 5 red, yellow, green and blue SMD LEDs from ebay as well as some nice SMD 680Ω resistors and some titchy little SPST switches.

Tiny SMD Switch

…Talk about tiny…

I had to check that I can even solder these, so I grabbed some strip board and my soldering iron.

I have to say it wasn’t as bad as I thought! Although I have no idea how to tell the polarity of an SMD LED. Google? So that includes a switch, an LED and a resistor – nuts. It runs at about 4mA according to my ammeter, which is on the boundary of acceptable, and if anything its too bright!

So time to design the PCB. I’ve etched a number of circuit boards at home before, but it’s never gone well. I always set my sights too high and make it too compact for home etching. I wish I was still at school with proper etching equipment.

My PCBs sometimes work out alright, after a few attempts

My PCBs sometimes work out alright, after a few attempts

Hopefully, being a small circuit board, it wont be too much of a gamble as to how well it etches.

Before I have always used Express-PCB to design my boards but since it isn’t installed on my new PC, I took that as an excuse to try out Eagle PCB.

My (hopefully final) design is as follows:


So this design basically includes 20 DIL Through-the-Hole pins to allow the arduino to connect by its header rails and 4 SIL TTH pins to allow the bluetooth module to connect by a header. Everything else is surface mount. There are 4 switches, 6 LEDs and 6 accompanying resistors. Begrudgingly I had to use jumpers as far as I can see in order to get the power to the bluetooth module without increasing the area of the board. On the plus side, the arduino has internal pull-up resistors meaning I don’t need extra space for them. The rectangle represents the area I will remove to make room for the micro-usb port on the arduino.

I hope to etch it next week.

Project: Smart Watch – Basic Layout

So I had two basic options as to how to lay out the internals of the watch:

Stacked or adjacent.

A stacked layout will provide a skinny appearance but will be taller and potentially more annoying.

An adjacent layout will be wide and flat which could be equally annoying.

After playing with some cardboard models etc I decided that it would be best to stack the design.

watch structure

This is the design I settled on. I reckon I can get it down to around 7mm thick which could be ok.

The battery will be mounted on the underside of the wrist with wires coming through the straps. (Probably won’t work).

Projects: Smart Watch – Power

So, I spent a LONG time looking around the internet for suitable batteries. They had to be small and have decent capacity.

I decided 150mAh was the minimum. And in the end I settled on these little 3.7v Lithium-Polymer cells with 250mAh.

250mAh LiPo Battery

Since these are only 3.7v each I either have to put two in series OR use a voltage booster to achieve the 5.5-12V range.

A nice little voltage booster like this should do.

The batteries haven’t actually arrived yet – I ordered them from China so it could be a week or two still before they turn up. There’s no point buying a voltage booster until then.

But I actually had very little idea how much my circuit used. So I tested it using my ammeter and as it turns out, the Bluetooth module uses 5mA when connected and idle, ~20mA when connected and transceiving, and ~35mA when unconnected.

5mA is acceptable and so I will do my best to keep data transmission to a minimum in order to minimize power usage.

I was pretty shocked to find that the arduino uses around 30mA when running even the simplest of loops. And so I spent a couple of days sorting this out.

I found that if I put the arduino into “sleep mode” the power consumption dropped to about 0.5mA which is much more up my street. Luckily, the serial pin on the arduino could be used as an interrupt to wake the module up from sleep, so all I have to do is send some junk data to the arduino so it wakes up in time to catch the real data.

However, in the periods when the arduino was awake, ie when flashing LEDs, transmitting data etc it still used about 30mA which is pretty unacceptable.

By reducing the clock frequency from 16MHz to 1MHz, this can be reduced to around 16mA which is just about acceptable as hopefully it will be asleep most of the time. I daren’t reduce it any more.

So, as it turns out there are approximately 3 general states the watch can be in:

Completely idol using approximately 5mA

Idol but with the bluetooth module awake using approximately 16mA

and fully going for it at 32mA.

Overall I estimate that the average usage will be around 8mA which should give a battery life of well over 20 hours. Yay.

On top of this will be the LEDs, but by using largish resistors I hope to keep the current down to 2-4mA each and they shouldn’t be on too long anyway.