ESP8266 happiness

It just goes to show that perseverance sometimes pays off. It turns out that the reason I couldn’t get the Olimex esp8266 to work properly was that my USB/serial converter was faulty. The replacement one arrived today, and now I can program the wifi module using the arduino IDE with no problem. Five seconds after programming it, it had connected to my home network and was sending temperature readings via MQTT to my raspberry pi server. There are plenty of IO pins exposed on the Olimex module, so I can do lots more with it than with the wi07c module I was using before. Watch this space.

ESP8266 disappointment

I found a very promising new ESP8266 module, from Olimex (a Bulgarian company).


It’s a breadboard-friendly board with an ESP8266 and 512k of flash memory on it, and it’s dead cheap. There’s even a carrier board for it, with a relay and a reset button, also dead cheap. I bought a couple, because it exposes all the pins from the microcontroller, so I can (a) use more than one I/O, and (b) hook up the reset pin so that I can put the device into (and, more importantly, wake it up from) deep sleep mode to extend battery life. There are videos on line of how simple it is to program these devices using the new arduino IDE.

The (insert strong adjective here) problem is that I can’t (insert strong adjective here)-well get it to work. I can connect it up to my PC fine. I can even put it into flash mode perfectly well. In neither case will it respond coherently to anything sent to it from the PC. In ‘normal’ mode, it just repeatedly sends the word ‘Error’ over the serial link, and does not respond to any AT commands.

Olimex ESP8266 errors

In reflashing mode, it simply fails to respond to the reprogramming commands. I’ve tried two of these modules, and both behave the same. I’ve contacted Olimex both by email and on their forum, and had no response. It’s a shame, but I think these modules are destined for the rubbish bin. At least they weren’t expensive.

Update: Olimex have got back to me, and have made some helpful suggestions. They don’t know what the problem is, though, and it’s not one they have seen before. It may well be something to do with my serial adapter. I have another on order, so I guess I’ll find out in due course.

The King is dead. Long live the king!

For a while now, I’ve been playing with the super-cheap esp8266 WiFi module. It’s been a bit of an uphill struggle, mostly because of the poor documentation (actually, that’s not fair – the documentation may well be excellent, but my understanding of Chinese isn’t) and the lack of easy programming tools. Until now, there have been essentially three ways of using the module:

Serial for breakfast

The initial method was to control the module via a serial link. As supplied, it can communicate with an arduino (or anything else) using a simple serial connection, using AT-style commands which will be familiar to anyone who has worked with modems, especially GSM ones. It works, but it’s a bit clunky. By and large, I think people have stopped doing this.

C for elevenses

Pretty soon after it became available, smarter people than me figured out that the module is powered by a general-purpose microprocessor (and a pretty powerful one at that). It also became apparent that you could reprogram this directly, and use its spare capacity (and spare I/O pins). Thanks to the manufacturer’s release of an SDK, it became possible to write code directly on the module, without the need for an arduino or any other processor. For less than five pounds, you could have a general-purpose microcontroller with build in WiFi.

Of course, there’s a catch. The tool chain required to do this programming is hard to set up and complicated to use. It also means programming in C and understanding a pretty complex SDK. It’s not particularly friendly. There were some valiant efforts to make this easier, notably Mikhail Grigorev’s bundling of everything into the eclipse IDE. This works well, but it still requires you to program at quite a low level.

lua for lunch

More recently, there has been nodemcu. This is a new set of firmware for the esp8266, which builds in an implementation of the lua language, with the SDK functions wrapped and easy to use. Nodemcu allows you to write programs in lua, upload them to the esp8266 and run them on it. This works pretty well. I’ve had temperature sensors in my house using it for a while, It has some drawbacks, principle amongst which is that the nodemcu firmware takes up quite a lot of the available memory, leaving fairly little for your programs. Add to this the fact that your programs are sent to the device as source code, and interpreted (or compiled) in place, and you find that there really isn’t much space to write more than simple programs. This shouldn’t be an issue for small sensor nodes, but I found myself scratching around trying to save a byte here and a byte there just to get my code to run.

Arduino for dinner

What everyone has been secretly waiting for, of course, is the ability to program the esp8266 like an arduino. And now we can. There’s a new version of the arduino ide 1.6.1 which gives you the ability to program the esp8266 using familiar arduino code. The wifi functions are easily available, as are most other arduino functions. It’s insanely easy to write something which connects to a wifi router, gets an ip address and sends data to a server. Or indeed to run a server on the device. Because the arduino language is compiled to native code before being uploaded, there’s loads of space for programs. Some of the normal arduino libraries have not been ported yet, but I’m sure they will be in the coming weeks. I won’t be going back to any of the other methods. Long live the king!

It’s worth repeating that the esp8266 gives you a tiny board with a 32 bit processor running at 80MHz, at least half a megabyte of memory (my recent olimex ones have 2MB), multiple IO pins and wifi for less than five pounds. If I were arduino (whichever half of arduino you care to pick) I’d be worried.

Printed lathe parts online

Since I posted a video of my 3D printed lathe on YouTube, the video has now been viewed over 100,000 times. If a typical working day is 8 hours, and the working year is 250 days or so, then it’s the equivalent of about two solid years of someone watching it. That’s not a job I’d want.


Anyway, a number of people have asked for the STL files so they could make one themselves. I’ve finally got them in some sort of order, and you can now download a zip file with them all from here


If you haven’t seen the video, here it is:

Never mind the Buzzclock

Fair warning

So far, only one person I’ve told about this project thinks it’s a good idea. Everyone else looks at me wtih a mixture of pity and puzzlement, neither of which emotions seems to be mitigated by my explanation. Clearly, the best thing to do with the project is to bury it quietly, and where better to commit something to obscurity than on my blog?

A little bit of background

My eyesight is rubbish. With glasses on, I can see perfectly. Without them, I’m as blind as a bat. When I go to bed, I take off my glasses. If I wake up in the middle of the night, I am unable to find out what time it is without putting my glasses back on and looking at an illuminated clock. The problem is, that by the time I’ve done this (and waited for my ageing eyes to focus properly), I’m fully awake. If it turns out that it’s far too early to get up, it can take ages to get back to sleep.

The usual suggestions

Most people say “Can’t you get a clock with a big display?” It’s a logical suggestion, if you can see well. For me, the digits on a bedside clock would have to be about a foot tall for me to be able to read it without glasses. Others say “Can’t you turn on a light?”, but doing so brings me to full wakefulness (and runs the risk of disturbing my wife). Fools suggest “Can’t you just use an alarm clock?” I do. But if I wake up before it goes off, I want to know if it’s three hours before, or only one. If it’s only one, I’ll get up and do something useful.

The solution

Here it is, in all its glory:


No, it’s not the internet. It’s the Buzzclock. To use it, you press and hold the button on the top. It then tells you the current time by silently vibrating: one pulse for each hour, then one shorter pulse for each ten minutes past the hour. There is virtually no noise, no light and best of all no need to put on glasses. The time is not accurate to the minute, but it’s good enough to make the decision whether to get up or to go back to sleep.

Don’t laugh, it hurts my feelings.

Inside the box


It’s a bit of a squeeze. The brains of the device is an arduino Nano, connected to a battery-backed real time clock. The Nano is a very useful device – more or less the same functionality of an arduino Uno or Leonardo, but in a much smaller package. It’s also dirt cheap (about three of your earth pounds). You can plug it directly into a breadboard for prototyping, and then when you want to build the final device, you can solder it in to a PCB or stripboard, or you can plug it in to a terminal block breakout board, as I did.

nano adapter

The real time clock (RTC) module I used came from ebay, and also cost about £3. It uses a DS3231 chip, has a rechargeable backup battery and (unnecessarily) has 32k of flash memory on the same board. I guess the flash is there in case you want to use it for datalogging. The RTC chip also has a built in thermometer (I don’t know why).



The RTC and the arduino communicate over the two-wire I2C interface. This makes the wiring really simple. There are handy arduino libraries available to do all the heavy lifting. Thsi is a good thing, because the RTC chip has its own protocol for getting and setting the clock time, and the libraries wrap this into a nice simple set of commands.

The final component in the build is the vibration motor. This is one designed for mobile phones. As usual it’s from ebay and cost about a pound. This is a thing of beauty. It’s a small dc motor (it runs off 5V – the arduino can power it directly from an output pin) with an eccentric weight on its output shaft. When the motor spins, it vibrates. There is nothing special about that, except that it is tiny. The whole assembly is only about 10mm long. The engineering that goes in to mass producing those must be just staggering.


How it works

THe button is just a push-to close switch. As long as you hold it down, the arduino gets power. Let it go, and the power is cut. This way, the arduino uses no power at all when not in use. The RTC has its own backup battery, so it keeps track of time without using the main battery.

Every time you press the button, the arduino boots up. It then contacts the RTC to get the time from it, and sets its own clock. The output pin connected to the motor is brought high for half a second then low for half a second for each hour in the current time. After a full second pause, shorter pulses are used to indicate the tens of minutes after the hour. And that’s all it does. At four o’clock in the morning, when all is pitch black, its a very quick way of working out it’s too early to get up.

Setting the time

At the moment, you can only set the time by connecting the arduino to a PC and sending a string over the serial port. This is not a big deal, because the RTC keeps time over a long period. It’s only an issue when the clocks change to or from daylight saving time, and I can cope with the effort twice a year.

Cracking the cube

I can’t take any credit for this.

Earlier this summer, I built a Rubik’s cube solver from a Lego Mindstorms set. I simply followed the plans for the Mindcuber design. It seemed to work quite well, but my Rubik’s cube had one face which was much stiffer to rotate than others, and the power available from the Lego motors was insufficient to reliably turn it. So it’s been sitting in my office for a while doing nothing. Today, however, Rob lent me a speed cube he bought from Amazon. It’s designed to take as little torque as possible to rotate, and has nicely chamfered edges so it doesn’t jam if it’s slightly out of alignment when you try to turn it. In the picture, the speed cube is the one on the left.


The cube-solver robot loves it. I’ve posted a video of it on the YouTubes at .

The whole thing is a supremely pointless exercise, but it is rather hypnotic to watch.

…and we’re back!

As a close follower of my blog, you will doubtless have noticed that it has been off the air the last few days. I didn’t. Rob drew my attention to its non-existence. It turns out that there were hosting troubles, and to cut a dull story short I’ve had to move the blog to a different hosting provider.

It’s more or less fixed now, but still has a few niggles to sort out. Sorry for any inconvenience.

Creating 3D models is hard

3D printing is easy. You can buy a 3D printer off the shelf for a few hundred of your Earth pounds, download patterns from thingiverse and be printing solid stuff straight away. Creating your own 3D models is harder, and it seems to me that this is now the bottleneck (at least, if you don’t want to spend a lot of money). There are several options. You can scan a real item, if you have a 3D scanner, and then use really awkward tools to manipulate the mesh. You can persuade powerful and confusing tools for animation and modelling like Blender to create models. You can use infuriatingly limited free versions of commercial tools like Sketchup. Or if you have really deep pockets, you can buy a proper CAD system.

I don’t like any of the above. I’m a programmer, and have a mechanical engineering background. I want to create precise, preferably parametric, models of components which I can then print out and fit together with other components to make machines. Up till now, I’ve been using OpenSCAD, and it’s been pretty good. OpenSCAD allows you to define shapes precisely using numbers, and combine them exactly (wrong word, I know) to create useful things. I love it. But it’s always had one major flaw (and a few little ones, but that’s another story). Building a model in OpenSCAD is like writing a program: it supports functions and loops, but it doesn’t support variables. At least not variable variables. You can assign a value to a variable and use it later, but that value cannot change. This is a bit of a pain, and it limits what you can do. Now there is an alternative, and that makes me happy.

The new kid on the block

OpenJSCAD is an entirely browser-based (yes, you read that right) editor and renderer for 3D models. It uses a language quite similar to OpenSCAD (indeed, it can import OpenSCAD files), but more powerful and a bit like C. And it supports proper variables. Hurrah! Here’s a screenshot of a little something I knocked up in it:


Try doing that in OpenSCAD. I did, and the spiral ramp was not easy. Here’s an assembly of a few of them, printed out and stacked together. A ball bearing runs around them very nicely:

ball chute

Try OpenJSCAD. If you don’t like it, I’ll give you your money back.

Here’s my .jscad file which created the ball chute. You can simply cut the text and paste it into OpenJSCAD if you want to try it.

// title: Spiral ball bearing chute
// author: Peter Robinson
// license: None.  Free for all.
// description: A stackable spiral chute for ball bearings.

var radius = 50;
var slotwidth=6;
var wallthickness=1;

function main(params) {

    var a=2;
    return union(


function section(){
    return union(


function hub(){
    return  difference(
            radius: 10,
            radiusStart: 8,
            radiusEnd: 7,
            radius: 6,
            radiusStart: 7.9,
            radiusEnd: 6.9,


function spoke(){
    return CSG.cube()

function spiral(){
    var hex = CSG.Polygon.createFromPoints([
            [0,slotwidth/2, 0],
            [0,-slotwidth/2, 0],
            [0,-slotwidth/2, radius],
            [0,slotwidth/2, radius]
        [0, 0.8, 0]
    var angle = 5;
    return hex.solidFromSlices({
        numslices: 365 / angle,
        callback: function(t, slice) {
            var coef = 1 - t * 0.8;
            return this.
            translate([0 , radius, t*10]).
            rotateZ(angle * slice);


function ramp(slotwidth,climb,innerradius_start,innerradius_end,basethickness){
    var hex = CSG.Polygon.createFromPoints([
            [0,0, 0],
            [0,slotwidth, 0],
            [0,slotwidth, 1],
            [0,0, 1]
        [0, 0.8, 0]

    var base = CSG.Polygon.createFromPoints([
            [0,0, 0],
            [0,slotwidth, 0],
            [0,slotwidth, 1],
            [0,0, 1]
        [0, 0.8, 0]
    var angle = 5;
    var radiuschange = innerradius_end-innerradius_start

    var bottom = base.solidFromSlices({
        numslices: 95 / angle,
        callback: function(t, slice) {
            return this.
            translate([0 , innerradius_start +t*radiuschange, 0]).
            rotateZ(angle * slice);

    var spiral = 
        numslices: 95 / angle,
        callback: function(t, slice) {
            return this.
            translate([0 , innerradius_start +t*radiuschange, 0]).
            rotateZ(angle * slice);

    return union(


More tiny WiFi success

As I have posted before, I have been playing with the super-cheap WI07C WiFi module based on the ESP8266 chip. I’ve now had sufficient success with it that I can publish a post on a working project. This simple setup uses an Arduino nano to read temperatures from to 18BS20 sensors, formats the data as JSON and then sends it over WiFi to a server on my home network. It’s cheap and simple. Here’s the fritzing diagram:


You may notice the Adafruit level shifter board in there too. That’s because the digital IO from the arduino is 5V, but the WiFi module needs 3.3V. The Adafruit module is a dead easy way of joining the two. The temperature sensors use a three-wire protocol which allows you to connect many in parallel and address each one individually. there’s a software library which takes care of this.

Here’s the Arduino sketch. It uses Miles Burton’s temperature control library to read from the sensors, so you’ll need to download that. NB: this code is not a shining exaple of style or completeness. It’s a quick hack to get something working. It does no error checking or reconnection if there are problems. You may find yourself pressing the reset button a lot.

You might also note that the hardware serial port is required for the WiFi module, which needs 115200 baud. This means that you can’t upload a new sketch to the arduino while it’s connected to the WiFi module. I just whip out the wires to the TXD and RXD pins on the arduino while I’m uploading, and all is well.

The sketch tries to join the WiFi network, and then tries to establish a simple TCP connection to a server IP address and port of your choice. Once the connection is established, it checks the temperature sensors every 10 seconds or so and sends the temperatures to the server in JSON format, thus: {"temp":[22.63,22.81]}. That’s all it does. You’ll need a TCP server listening on your chosen IP address and port, of course. It seems to work quite reliably for me.

#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define SSID        "MyHomeSSID"
#define PASS        "MyPassword"
#define TARGET_IP   "192.168.1.xx"
#define TARGET_PORT 5000

SoftwareSerial dbgSerial(10,11); // RX,TX
DallasTemperature sensors(&wire);

void setup()
   // WiFi module needs fast serial, so must use the hardware port which is also used for
   // uploading sketches

   // For debugging, we therefore need a software serial port.  This can be much slower.


  // Connect to the wirelsess network
  dbgSerial.println("Joining network...");

  // Just check that the WiFi module is joined to the network
  dbgSerial.println("Check connection...");

  dbgSerial.println("Initialising sensors...");

  dbgSerial.println("Connecting to server...");

  dbgSerial.println("Ready to rumble!");

int incomingByte=0;
bool echoLocal = true;

// Get the data from the WiFi module and send it to the debug serial port
void receive(){
  while (Serial.available() >0) {
    incomingByte =;

char temp1[10];
char temp2[10];

void loop()

  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  dbgSerial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures


  String json="{"temp":[" + String(temp1) + "," + String(temp2) + "]}";
  dbgSerial.print("Sending ");

  // Send the data to the WiFi module


This is a work in progress. I’ll be updating it soon. But for now, I’m very pleased with the simplicity of the WiFi modules, and even more pleased with their low cost (I am a Yorkshireman, after all).