Samsung GT-E1200

Well, the iPhone 3GS lasted a long time. About a month after getting it working on O2 it decided to switch off halfway though a call and then not come back on again. After a days faffing with it, I got it to return to life, only for it to expire again precisely 24 hours after it had first gone tits-up (and 48 hours after the OS had been upgraded).

So, faced with the choice of dealing with the Apple Support people (and paying £25 for no help at all), buying another phone to use on O2, or switching back to 3 and using the now-restored and fully working Samsung Galaxy Europa, I chose the latter.

But, like most of my plans, things didn’t go well. If you are using a pre-pay SIM, O2 won’t tell you the Porting Authorisation Code, or PAC (certainly not PAC Code!) for your number unless you call from that number or happen to know the exact balance that you have left. Neither are really feasible if you have a bricked phone and don’t know anyone else who uses O2.

After checking my impressive collection of old phones, I found that none of them worked with O2, so I set off to Tesco to buy the cheapest phone possible.

Hence, the £15 SIM-Free Samsung GT-E1200:

2012-11-18-21.05.36

For less than the cost of something that costs more that £15, you get a phone with a mind boggling list of features:

  • Making and receiving calls
  • Text Messaging
  • Alarm clock and Stopwatch
  • A choice of a few pleasant ringtones and TWO background pictures
  • A game
  • Nothing else.

Wow! This must be the second worst phone in the world, after the VX-1?

No, actually. For some people it might be the ideal phone. Old people and young kids (neither of which should be allowed any where near the internet), people who want a second phone that only certain people know the number for (nothing nefarious, obviously, I was thinking of taxi drivers who want a number to give out to customers and not be bothered by random drunken calls at 4am).

Besides, I kind of like it. The ringtones and bleeps sound pleasant, and I’ve not charged it for about a week despite playing the one game on it a lot.

I’m still going to switch back to 3 for my main number sometime this week, and maybe use this one for work related stuff. That way the tax man can pay for it.

Or, just let the girlfriend have it after her extremely old Sagem phone bit the dust.

Protocol of the Ardunio Dalek

Ok, so now I’m just making Doctor Who episode titles up…

Anyway, while eagerly awaiting the release of the Raspberry Pi, which should be available within a month, I’ve been playing about with the communication method twixt Raspberry and Arduino.

As the ‘berry will be running Debian Linux, my Ubuntu server had been used as the test host, despite it being far too massive and heavy to be carried by the Dalek. I have a very long USB cable for such eventualities.

The plan has come down to initially sending single character commands to the Arduino over the serial port, and listening for a response. The responses will be a 5 character code with optional additional data.

The single character commands, their actions and return messages are:

Command Action Response
q Move forward and left MOVSF Ok
w Move forward MOVFF Ok
e Move forward and right MOVFS Ok
a Spin left MOVBF Ok
s Stop MOVSS Ok
d Spin right MOVFB Ok
z Move back and left MOVBS Ok
x Move back MOVBB Ok
c Move back and rigt MOVSB Ok
h Return last movement order MOTOR {motor status} Ok
v Return version number VERSN {version number}
l Get distance from left sensor DISTL {distance in cm}
r Get distance from right sensor DISTR {distance in cm}
  Unknown command UNKNW

So, here is the Arduino Sketch for this protocol:

// Project: Dalek control system – Receive and process commands from USB
// Version 1.0 (2012-02-09-09-06)
// Tony Blews tony@tonyblews.co.uk

int MotorDirectionR = 10;
int MotorDirectionL = 11;
int MotorPowerR = 12;
int MotorPowerL = 13;
int IRPinLeft = 2;
int IPPinRight = 3;
String motorStatus = String (“”);

void setup()
{
pinMode(MotorDirectionR, OUTPUT);
pinMode(MotorDirectionL, OUTPUT);
pinMode(MotorPowerR, OUTPUT);
pinMode(MotorPowerL, OUTPUT);
motorStatus= String(“MOVSS”);
Serial.begin(9600);
Serial.println(“START Serial control Dalek system starting…”);
}

void 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
Serial.println(distance); // print the distance
delay(100); // arbitary wait time.
}

// 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);
motorStatus= String(“MOVSS Ok”);
Serial.println(motorStatus);
}

// move straight ahead
void modeFF()
{
digitalWrite(MotorDirectionR, LOW);
digitalWrite(MotorDirectionL, LOW);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVFF Ok”);
Serial.println(motorStatus);
}

// move straight backwards
void modeBB()
{
digitalWrite(MotorDirectionR, HIGH);
digitalWrite(MotorDirectionL, HIGH);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVBB Ok”);
Serial.println(motorStatus);
}

// spin left
void modeBF()
{
digitalWrite(MotorDirectionR, LOW);
digitalWrite(MotorDirectionL, HIGH);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVBF Ok”);
Serial.println(motorStatus);
}

//spin right
void modeFB()
{
digitalWrite(MotorDirectionR, HIGH);
digitalWrite(MotorDirectionL, LOW);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVFB Ok”);
Serial.println(motorStatus);
}

// move forward left
void modeSF()
{
digitalWrite(MotorDirectionR, LOW);
digitalWrite(MotorDirectionL, LOW);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,LOW);
motorStatus= String(“MOVSF Ok”);
Serial.println(motorStatus);
}

// move forward right
void modeFS()
{
digitalWrite(MotorDirectionR, LOW);
digitalWrite(MotorDirectionL, LOW);
digitalWrite(MotorPowerR,LOW);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVFS Ok”);
Serial.println(motorStatus);
}

// move backward left
void modeSB()
{
digitalWrite(MotorDirectionR, HIGH);
digitalWrite(MotorDirectionL, LOW);
digitalWrite(MotorPowerR,HIGH);
digitalWrite(MotorPowerL,LOW);
motorStatus= String(“MOVSB Ok”);
Serial.println(motorStatus);
}

// move backward right
void modeBS()
{
digitalWrite(MotorDirectionR, LOW);
digitalWrite(MotorDirectionL, HIGH);
digitalWrite(MotorPowerR,LOW);
digitalWrite(MotorPowerL,HIGH);
motorStatus= String(“MOVBS Ok”);
Serial.println(motorStatus);
}

//report distance left
void lookLeft()
{
Serial.print(“DISTL “);
check_distance(2);
}

//report distance right
void lookRight()
{
Serial.print(“DISTR “);
check_distance(3);
}

// report Status back to host
void helloDalek()
{
Serial.print(“MOTOR “);
Serial.println(motorStatus);
}

//report software version
void reportVersion()
{
Serial.println(“VERSN 1.0”);
}

//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
// L and R are used to “look” left and right for distance sensing
// H is for Hello. To report the status of the device.
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;
case ‘l’:
lookLeft();
break;
case ‘r’:
lookRight();
break;
case ‘h’:
helloDalek();
break;
case ‘v’:
reportVersion();
break;

default:
Serial.println(“UKNWN”);
break;
}
}
}

Again, parts of this come from Lucky Larry‘s site.

And the C part:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <getopt.h>

void usage(void);
int serialport_init(const char* serialport, int baud);
int serialport_writebyte(int fd, uint8_t b);
int serialport_write(int fd, const char* str);
int serialport_read_until(int fd, char* buf, char until);

int main(int argc, char *argv[])
{
int fd = 0;
char serialport[256];
char buf[256];
int rc,n;

fd = serialport_init(“/dev/ttyUSB0”, B9600);
if(fd==-1) return -1;
strcpy(buf,argv[1]);
rc = serialport_write(fd, buf);
if(rc==-1) return -1;
usleep(100 * 1000 ); // sleep milliseconds
serialport_read_until(fd, buf, ‘n’);
printf(“read: %sn”,buf);
exit(EXIT_SUCCESS);
} // end main

int serialport_write(int fd, const char* str)
{
int len = strlen(str);
int n = write(fd, str, len);
if( n!=len )
return -1;
return 0;
}

int serialport_read_until(int fd, char* buf, char until)
{
char b[1];
int i=0;
do {
int n = read(fd, b, 1); // read a char at a time
if( n==-1) return -1; // couldn’t read
if( n==0 ) {
usleep( 10 * 1000 ); // wait 10 msec try again
continue;
}
buf[i] = b[0]; i++;
} while( b[0] != until );

buf[i] = 0; // null terminate the string
return 0;
}

// takes the string name of the serial port (e.g. “/dev/tty.usbserial”,”COM1″)
// and a baud rate (bps) and connects to that port at that speed and 8N1.
// opens the port in fully raw mode so you can send binary data.
// returns valid fd, or -1 on error
int serialport_init(const char* serialport, int baud)
{
struct termios toptions;
int fd;

//fprintf(stderr,”init_serialport: opening port %s @ %d bpsn”,
// serialport,baud);

fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) {
perror(“init_serialport: Unable to open port “);
return -1;
}

if (tcgetattr(fd, &toptions) < 0) {
perror(“init_serialport: Couldn’t get term attributes”);
return -1;
}
cfsetispeed(&toptions, B9600);
cfsetospeed(&toptions, B9600);

// 8N1
toptions.c_cflag &= ~PARENB;
toptions.c_cflag &= ~CSTOPB;
toptions.c_cflag &= ~CSIZE;
toptions.c_cflag |= CS8;
// no flow control
toptions.c_cflag &= ~CRTSCTS;

toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl

toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
toptions.c_oflag &= ~OPOST; // make raw

// see: http://unixwiz.net/techtips/termios-vmin-vtime.html
toptions.c_cc[VMIN] = 0;
toptions.c_cc[VTIME] = 20;

if( tcsetattr(fd, TCSANOW, &toptions) < 0) {
perror(“init_serialport: Couldn’t set term attributes”);
return -1;
}

return fd;
}

This is a canibalisation of code from Tod Kurt‘s site.

My botch of this just takes a single character as a command line option, passes it the Arduino and prints the reply. eg:

$ ./dav s

read: MOVSS Ok

$ ./dav v

read: VERSN 1.0

$ ./dav l

read: DISTL 42.15

$ ./dav k

read: UKNWN

In other news, I’ve ordered a DIY Shield Kit from Amazon, so I can tidy up the hardware a bit, and a miniscule USB webcam which I intend to fit into the head part of the Dalek. I also plan to move all the clever bits of circuitry into to the top half, of the Dalek, and Meccano-up a set of brackets to hold the various battery sets that are needed in the bottom half.

The Arduino Dalek Master Plan – Episode 2

Looking back on my grand ideas, I’ve decided on a bit of a change of plan.

The current scheme will not have ports for video, or extraneous USB holes for keyboards and things of that ilk.

The current list of ports to stick on the Dalek is:

  • Ethernet – as i think I’ll need it in case the wifi fails
  • USB (using the already fitted port) for power while testing

The Raspberry will need USB for these:

  • Connection to the Arduino
  • Connection to the webcam (unless i can get a camera that uses the on-board connection)
  • Some form of microphone

So it still looks like I’ll need an unpowered hub.

It will also need a speaker connection for whatever sound output I decide to use.

Also, at some point i intend to get the ear lights working again.

Evolution of the Arduino Dalek

The DIY Arduino Shield Kit arrived from Amazon, and has been soldered up.

emptyshieldAnd it looks really boring, without the other parts stuck on it.

The parts in question are four 5v DPDT relays (Maplin part no N05AW – which seem to be out of stock a lot of the time, but are better that the alternative BT Type 47s, as the coil isn’t fussy about the polarity of the voltage), four 1N4004S diodes (part no QL78H), and a mess of wires. Rather than try to describe the layout, I’ve drawn a really bad diagram.

Circuit-ComponentsThis is the view from the component side. The yellow boxes show the relay placements, the four vertical block are the connections to the arduino. The Cyan areas are connections on the other side of the board, either whopping great solder blobs or lines joining the pads drawn with a pcb pen. The other technicolour lines are various wires.

Although that diagram gives the impression that I’ve used a double sided board, I haven’t. In retrospect that would have made things a lot easier.

Another collosal lack of planning (ie putting the Arduino header blocks too close to the top of the board) means that the Massively Ugly Blob Of Solder at the top sits directly over the ICSP header on the <a href="http://arduino best ed pills non prescription.cc/en/Main/arduinoBoardDuemilanove”>Arduino Duemilanove that I’m using, requiring a bit of electrical tape to stop it shorting.

Here is what it looks like now, shitty soldering included for free:

2012-02-24-16.47.06 2012-02-24-16.47.19

Maybe you’ve spotted some things that aren’t on the diagram. Such as the 2 pin header, the two 3 pin headers and and 4 pin header. Well, the 2 pin is for the motor power input, and the 4 pin one is for the motor driver outputs. They were an afterthought, as were the two 3 pin headers which are for the distance sensors input, and are currently not connected. That bit comes next.

Samsung Galaxy Europa

I recently bought a Samsung Galaxy Europa from 3, to replace my old Sony Ericsson W595 which had become increasingly unreliable following a freak rollercoaster accident back in September.

The Europa, AKA the GT-I 5500 is an alleged smartphone, running Android 2.2. It cost me 50 quid, plus 15 quid pre-loaded on a SIM card. Not too bad, unless you want to keep your old number, in which case you end up with a spare SIM with 15 quid on it, which expires within one month.

One of the reasons, besides the obvious need of a phone replacement, that I bought the thing was my desire to replace my current “smartphone” combination of an old 3rd generation iPod and MiFi dongle thing. Carrying the pair of them around was a pain, considering the battery life of each, so I was looking for something about the same size that wouldn’t entail a pocket full of cables and mains adapters.

europa-ipod

As you can see, the Europa is smaller than the iPod, with a considerably smaller screen, so consequently the on-screen keyboard is far too small and fiddly for a normal sized human to use, let alone a giant ham-fisted oaf like me.

The Europa has a 2 mega-pixel camera, which is crap. Any more information about it would be superfluous.

The processor is woefully underpowered, and apps keep crashing. A particular problem is the WiFi system failing to work and the settings page just reporting “Error!”. Useful.

If by some arcane magic the Wifi system does work and the Europa is used as a mobile hotspot, the data rate is deplorable.

Note that I was is Stafford at the time, which is considerably more than 50 miles from Morecambe. Hence I could not see the Chinese Synchonized Swimming Team practicing.

Also, using the phone as a hotspot causes you to fall foul of Three’s piss-awful censorship. Most URL shorteners seem to be blocked.

So it looks like I’ll be keeping the MiFi for a while yet. And, considering how ropey the phone is, (despite my hatred of Apple) the iPod too.

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

Return of the Ubisurfer

ubirev2-1

Back in January I bought a Datawind Ubisurfer, a small netbook running Linux. You can read my first impressions of it here.

It wasn’t too bad for the price, and I used it a lot at work and whenever I was stuck on a train.

Back in May, I attempted to upgrade the software on it and it went all wrong. The internal GPRS modem refused to be recognised, the MP3 player packed it, and it stopped recognising USB memory sticks.

After a few email exchanges and a bit of confusion (two tech support people with the same name!), I finally got around to sending it back to them at the end of July.

It’s back, and this time it’s WinCE!

Firstly, some hardware specs (again):

  • Display: 7 inch TFT – Wide screen display, 800 x 480 pixels (WVGA)
  • Memory: 128MB Ram; 1GB Flash
  • Networking: Embedded Cellular Modem,Wireless LAN WiFi IEEE 802.11 b/g, 10BaseT Ethernet Interface
  • Control: Touch Mouse Pad – Dual Button, Standard 80 Key Keyboard
  • Battery & Power: Lithium Polymer (Approximate Working Time: 3 hours), or External DC Adapter
  • Size/Weight: 222 x 165 x 29.5 m, 700 grams
  • Ports: Push-Push SD card socket, USB Port, Earphone & Ethernet jacks.

As for software, the thing is now running Windows Embedded CE 6.0 Core, which means that it goes from Off to Usable in about 7 seconds.

Softmaker Office 2008 comes pre-installed, which includes the usual suspects of a spreadsheet, wordprocessor, presentation maker and Outlook-a-like mail client.

Browsing is done with either the UbiSurfer browser, which works through the embedded cellular modem, and a somewhat restricted version of Internet Explorer 6.

ubirev2-2.

The UbiSurfer browser uses a proprietory protocol to have your pages rendered on one of Datawind’s servers and then sent ina compressed form to your machine. While this was painfully bad on the Linux version, it actuall seems to work fairly well this time. Once you’ve got the think connected, which takes about 30 seconds, and loaded the home page (above), it is reasonable speedy for a cell-phone connection. While taking longer than the 7 seconds quoted in the bumph, mine loads the BBC News page in a about 10 seconds. Sometimes it can be annoying and take a while to tab between fields, but generally it works.

Using a WiFi connection and Internet Explorer gives you pretty much what you expect, but ActiveX and Flash cause problems, making Facebook and Google Mail annoying. And it constantly asks if you really want to visit pages with outdated certificates. Pretty much par for the course with IE6.

With WiFi you can apparently also use the Chat program which I really can’t be bothered to test, and a YouTube viewer which I haven’t managed to get working yet.

There’s also a PDF viewer, general media player and ebook reader on there. They work fairly well, but the PDF reader is very slow.

Games wise you get Allure Xonix, one of those draw boxes and capture an area while avoiding bouncy things games, Tile Fall, one of those click on blocks to destroy them in the right order games, and Paint, one of those not real a game but lumped in with them games. A better menu title might have been Entertainment, but probably not.

Finally, there is a thing called Terminal, which seems to be neither use nor ornament. It seems to be written to access the on-board modem, but doesn’t seem to work. Neither does it support Telnet, which is a bit of a pain in the arse.

All in all, and it pains me to say this, the Windows CE version is miles better that the older Linux version. It’s actually usable for a start. Apart from the lack of a telnet client, obviously.

UPDATE:

The telnet problem is now solved, by installing PocketPuTTY.

Download “PocketPuTTY 2007-02-28 dev build for PPC2002 (release)” from the PocketPuTTY Downloads page, and copy the putty.exe file from the archive to your device. Either dump it on the desktop or put it somewhere else and create a shortcut to it.

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.

moan, moan, flippin' moan