Category Archives: Dalek

The Arduino Dalek Master Plan

All has been quiet on the Arduino Dalek front for a while now, as I’ve stopped all work on it pending the release of the Raspberry Pi credit card sized sub-£20 computer

For those not in the know, the Raspberry Pi will be an ARM11 700Mhz based computer running Debian Linux and capable of operating from 4 AA batteries. The “Model B” will have 2 USB ports and on-board ethernet.

There will be plenty of space inside the Dalek to accommodate one of these, along with the extra battery packs required.

So, assuming that they start shipping these things soon, the Master Plan (oh just guess where the title of this post is derived from) is:

  • Strip down the existing code for the Arduino version so that it just accepts commands to drive the motors and read the sensor data (pretty much like version 0.1 did).
  • Work up a protocol for the Raspberry and Arduino to communicate with. Then implement it.
  • Fit the Dalek with all the connectors for the Raspberry (RCA, HDMI, Ethernet, USB via an unpowered hub, Audio jack and micro-USB power)
  • Recode the current “free-roaming” software to run on the Raspberry.
  • Source a suitable USB WiFi dongle and camera to install.
  • Jig up a web based “Control Panel” for the beastie.

The above list includes “USB via an unpowered hub”, as I currently envision needing more than 2 USB ports:

  • USB connection to the Arduino (direct)
  • USB WiFi dongle (via hub)
  • USB Keyboard (via hub on case exterior)
  • USB Mouse (via hub on case exterior)
  • USB Memory stick/Disk interface (via hub on case exterior)

Now why, you may be thinking, would I be needing the keyboard, mouse and storage (and video outputs)?

Well, the objectives are now two-fold. Primarily I still want to build the original free-roaming robot idea, but I also want it to double as a cool set-top box to connect to our stupidly large television which has been gathering dust since the Digital Switchover (our TV aerial is really shite and Freeview is UNWATCHABLE).

I could do that using a second Raspberry as a dedicated set-top box, but that would not be as cool.

Imagine: The Dalek is connected to the TV, playing a copy of an old Doctor Who episode featuring Daleks. The on-board camera is pointing at the TV, relaying the images to a web server. So a Dalek is watching a Dalek on a Dalek (not in that way). Open up another window and the Dalek is also watching itself. Thats the kind of thing that Christopher H. Bidmead could only dream about.

I’ll be buying a second one anyway, to it inside one of these keyboards.

But as I said, it is all on hold until the Raspberry Pi ships (and I remember how to program in C again).

Then maybe I can actually make use of the contrived acronyms DAVROS (Dalek Automatic Roving Vehicle Operating System), and SKARO (Stupid Kludged Arduino Remote Operation).

Vision of the Arduino Dalek

Ok, so that post title isn’t based on a Doctor Who episode title. Sue me.

Recently I’ve bought two Sharp GP2Y0A21YK Infrared Proximity Sensors from RoboSavvy. These little things can detect object in a range of 10cm to 80cm.

irsensorSo, the task now is to wire them up, and use them to detect when the Dalek get within 20 cm of an obstacle.

The circuitry is fairly easy. The Red wire goes to the 5v connection, the Black goes to GND, and the yellow wire goes to one of the Analogue inputs on the Arduno. I’m using pins A2 and A3, one for each sensor.

My soldering is, as ever, attrocious, so we’ll not have a picture of of that. Instead, here is a picture of the sensors Blu-Taked on to the front of the thing.

irmounted

And, as a bonus, a picture of the button that I’ve also fitted (and wired to Digital Pin 8).

dalekbutton

So, what we are going to do now is have the Dalek spin left if detects an obstable to the right, and spin right if it sees something to the left.

Also, if the button on the back is pressed, it will sleep for five seconds.

Portions of this code come from Lucky Larry’s website.

// Project: Dalek control system
// Version 0.3 - IR Sernsors
// Tony Blews tony@tonyblews.co.uk

int ButtonPin       = 8;
int MotorDirectionR = 10;
int MotorDirectionL = 11;
int MotorPowerR     = 12;
int MotorPowerL     = 13;
int IRPinLeft       = 2;
int IRPinRight      = 3;

void setup()
{
 pinMode(MotorDirectionR, OUTPUT);
 pinMode(MotorDirectionL, OUTPUT);
 pinMode(MotorPowerR, OUTPUT);
 pinMode(MotorPowerL, OUTPUT);
 pinMode(ButtonPin, INPUT);    // declare pushbutton as input

 Serial.begin(9600);
 Serial.println("Serial control Dalek system starting...");

}

float check_distance(int IRpin) {
 float volts = analogRead(IRpin)*0.0048828125;   // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
 float distance = 30*pow(volts, -1.10);          // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
 return(distance);                               // http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/     
}

// modes for the motor control
// convention here is modeXX - where X is F for forward, S for stationary and B for backwards
// first X is the left motor, second X is the right one
// for direction control, the LOW if forward and HIGH is backward
// for power control, LOW is off and HIGH is on

// all stop
void modeSS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,LOW);
}

// move straight ahead
void modeFF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// move straight backwards
void modeBB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// spin left
void modeBF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//spin right
void modeFB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//main program loop
void loop()
{
 if (digitalRead(ButtonPin) == HIGH)
 {
 modeSS();
 delay(5000); // sleep for 5 seconds if button pressed.
 }
 modeFF();
 if ((check_distance(IRPinLeft) <20) && (check_distance(IRPinLeft) <20) )
 {
 //back up a bit
 modeBB();
 delay(1000);
 //rotate on spot for 2 sec (approx timing for 180 degrees)
 modeFB();
 delay(2000);
 }

 if (check_distance(IRPinLeft) <20)
 {
 // rotate on spot for 1 second (approx timing for 90 degrees)
 modeFB();
 delay(1000);
 }
 if (check_distance(IRPinRight) <20)
 {
 // rotate on spot for 1 second (approx timing for 90 degrees)
 modeBF();
 delay(1000);
 }
}

Video coming soon, I promise.

Power of the Arduino Dalek

It has been a while since I’ve messed with the Dalek project, so this is just a brief update of the minor twiddling I’ve done.

Firstly, the Dalek now has a USB Type B socket on the rear of the casing replacing one of the “Dalek Bumps”, as shown:

dalekusbAcquired from Maplin (part no N57FL), this USB Panel Mount Socket is reversible, with a Type A socket on one side, and a Type B on the other.

As a PC generally has a Type A socket, and the Arduino I’m using has a Type B socket, I opted to have the Type B on the outside.

This will allow the use of a normal A-B cable to connect between the PC and the case socket, and require a short A-B cable to connect between the case socket and the Arduino (as having a 3m cable curled round inside the thing seems a bit stupid).

Sadly, getting a short USB A-B cable isn’t easy. So I had to chop up an existing cable and butcher it.

usb-cable1

usb-cable2

Now, the Arduino can be left inside the Dalek case, which can be screwed shut again.

However, when the Arduino isn’t connected via the USB link, it loses power (tenuous link to the title of the post). Luckily, the Arduino Duemilanove that I’m using has a 2.1mm socket, and will run from a 9v battery.

So we need a PP3 9V battery clip, and a 2.1mm DC power plug.

powerparts

Solder the battery clip’s black wire to the outside connection of the plug, and solder the battery clip’s red wire to the centre connection of the plug.

For clearer instructions, and clearer pictures (I have a crap camera), see the relevant page at Arduino Playground.

powerlead

The yellow tape is not being used to hide a massive solder disaster this time, but merely to keep the wires together.

So, now I have a Dalek with a battery pack for the motors (from the original casing), a battery pack for the Arduino (ok, a PP3 taped inside), and a USB socket on the casing.

Now it can be programmed, unplugged, and be left to trundle into things.

So here is some code to make it wait for five seconds, spin right for one second, wait for two seconds, spin left for one second, and repeat for ever (or until the power is removed):

// Project: Dalek control system
// Version 0.2 - Sit and spin
// Tony Blews tony@tonyblews.co.uk

int MotorDirectionR = 10;
int MotorDirectionL = 11;
int MotorPowerR     = 12;
int MotorPowerL     = 13;
long randNumber;

void setup()
{
 pinMode(MotorDirectionR, OUTPUT);
 pinMode(MotorDirectionL, OUTPUT);
 pinMode(MotorPowerR, OUTPUT);
 pinMode(MotorPowerL, OUTPUT);
   randomSeed(analogRead(0));

}

// modes for the motor control
// convention here is modeXX - where X is F for forward, 
//S for stationary and B for backwards
// first X is the left motor, second X is the right one
// for direction control, the LOW if forward and HIGH is backward
// for power control, LOW is off and HIGH is on

// all stop
void modeSS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,LOW);
}

// spin left
void modeBF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//spin right
void modeFB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//main program loop
void loop()
{
delay (5000);
modeFB ();
delay (1000);
modeSS ();
delay(2000);
modeBF();
delay(1000);
modeSS();
}

The next step will be to install some sensors.

 

USB Panel Mount Socket

Genesis of the Arduino Dalek

As previously mentioned here, I was recently given a broken toy Dalek, which I promptly took apart (in the name of Science).

Here it is before surgery commenced…

dalek-1

Having stripped the thing down, I found inside two perfectly good electric motors, and when you find two working motors inside a toy there is only one thing to do: Work out how to use a computer to control them!

So, figuring out that the easiest way of doing this was with an Arduino, I bought one.

I won’t bleat on about how good the Arduino is, or how easy it is to use. There are hundreds of sites that do that.

Instead, here is a list of things wot i dun to get a PC controlling the Dalek.

To start with, I think we’ll have a bit of circuit design. Below is a simple circuit that takes 2 inputs from the Arduino and runs a motor either forwards or backwards. One input decides the direction of the motor, the other whether it is on or off.

relay-circuit

All very nice and abstract, but to be of any use it’ll need to be built. The quickest and easiest way is on Veroboard. So here is the design for that:

relay-vero

The relays do the switching, and the diodes are there to protect the Arduino from back-emf currents when the relays toggle. Two of these circuits will be used, one for each motor. I built them on separate strips of board to make things easier for myself. This is what they look like when all connected up and dumped onto the Dalek chassis:

dalek-wired1

The small board in the top left of the picture is just a plug I bodged up to make connecting the thing easier.

The parts used are 4x 1A5VDC DPDT relays, 4x 1N4004 diodes, a 10×39 strip of Veroboard and some wires.

After all that soldering and burning my fingers, the next step is to write some code to make the thing move.

Each motor can be controlled to go backwards, forwards or stop. This gives nine possible movements, as this table shows:

dalek-matrix

And now its time to test this whole think by writing a program that takes keyboard commands (the letters in red, above) and sending signals to the circuitry to control the motors. Heres it is:

// Project: Dalek control system
// Version 0.1 - Written before my Arduino even arrived
// Tony Blews tony@tonyblews.co.uk

int MotorDirectionR = 10;
int MotorDirectionL = 11;
int MotorPowerR     = 12;
int MotorPowerL     = 13;

void setup()
{
 pinMode(MotorDirectionR, OUTPUT);
 pinMode(MotorDirectionL, OUTPUT);
 pinMode(MotorPowerR, OUTPUT);
 pinMode(MotorPowerL, OUTPUT);

 Serial.begin(9600);
 Serial.println("Serial control Dalek system starting...");

}

// modes for the motor control
// convention here is modeXX - where X is F for forward, S for stationary and B for backwards
// first X is the left motor, second X is the right one
// for direction control, the LOW if forward and HIGH is backward
// for power control, LOW is off and HIGH is on

// all stop
void modeSS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,LOW);
}

// move straight ahead
void modeFF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// move straight backwards
void modeBB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// spin left
void modeBF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//spin right
void modeFB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// move forward left
void modeSF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,LOW);
}

// move forward right
void modeFS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,HIGH);
}

// move backward left
void modeSB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,LOW);
}

// move backward right
void modeBS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,HIGH);
}

//main program loop
void loop()
{
 if (Serial.available() >0)
 {
 char inByte = Serial.read();
 // this version uses the QWEASDZXC "square" on the keyboard
 // as my laptop doesn't have a numeric keypad
 switch (inByte)
 {
 case 'q':
 modeSF();
 break;
 case 'w':
 modeFF();
 break;
 case 'e':
 modeFS();
 break;
 case 'a':
 modeBF();
 break;
 case 's':
 modeSS();
 break;
 case 'd':
 modeFB();
 break;
 case 'z':
 modeBS();
 break;
 case 'x':
 modeBB();
 break;
 case 'c':
 modeSB();
 break;
 default:
 modeSS();
 break;
 }
 }
}

And with that done, I suppose all that is left to do is show a video of the bottom bit of the dalek trundling around under computer control…

… which have to wait until the next post.

Dalek Autopsy

Daleks are great. I’ve wanted one for years. The idea of having a Dalek to order about appeals to me. I could have it make tea for me and then exterminate my enemies/co-workers.

Daleks instill fear in the weak and feeble. For example:

giant-dalekMy sister recently acquired a defunct radio control Dalek on a car boot sale and figured that I might be able to find something to do with it.

But first we need to see exactly what we’re dealing with.

autopsy1What we appear to have is a Doctor Who – 12″ Radio Control Black Dalek, missing its eyestalk and the relevant control unit.

Someone once said that once you break something to see how it works, you have left the path of wisdom. It might have been Merlin, or possibly Mr. Miyagi. In this case, the damn thing is broken and i left the path of wisdom years ago anyway.

So, off with the bottom!

autopsy2Here we see three things:

  • the base unit – which contains the RC receiver, speaker, battery unit and motors
  • the superstructure – which is what makes it look like a Dalek
  • some turkey mince – which would have been my supper, but was so far out of date that it was in danger of crawling away by itself.

Stripping off the burnt out RC receiver (and letting the mince run free) gives us a closer look at the base unit:

autopsy3An even closer look shows us the nubbin that connects to the drive shaft that rotates the head unit:

autopsy4Peering up the skirt of the Dalek shows us where the shaft connects to the nubbin, along with some wires that connect to the circuitry in the head:

autopsy5Just concentrating on the bottom we have:

  • a base unit with working motors that run off 6v
  • some duff circuitry which will be ignored
  • a piezo speaker which might come in handy later
  • nothing for my supper
  • a blog post which, having re-read the text, will probably rank quite highly in the results of porn searches.