Friday, March 27, 2009

Internet Controled Car v2 Parallel Port

My first version of the Internet Controled Car used a BASIC stamp to handle serial communication. This was a mundane task for a complex and expensive little microchip

This new version uses a parallel port printer cable which is controlled by a C program on the server. Using a parallel port also fixed an issue where the direction commands would get "stuck" if you hit two keys at once as the BASIC stamp code didn't have a buffer. I also mounted the components to a piece of wood and some standoffs so it wasn't a mess of wires all over the place.

The Parallel Port C Program

The parallel port program, written in C, will take a parameter to set the data lines, that is pins 2 through 9, to a logic high or logic low.

Example: ppp 1l 2l 3h 5h 8l

Here is the C source code for Linux.

#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/io.h>

//#include <asm/io.h>
// Didn't work, replaced with sys/io.h

char *binprint( unsigned char x, char *buf )
int i;
for( i=0; i<8; i++ )
return buf;

int main( int argc, char *argv[] )
char c;
unsigned char val;
char buf[9];
int x;
if( argc<2 )
printf("Example usage: ppp 1l 2l 3h 5h 8l\n");
return 2;
if( ioperm(888,1,1) )
printf("Couldn't find parallel port (888)\n");
return 1;
val = inb(888);
printf("old = %s\n",binprint(val,buf));
for( x=1; x<argc; x++ )
if( argv[x][1]!='h' )
val &= ~(1<<(argv[x][0]-'1'));
val |= 1<<(argv[x][0]-'1');
printf("new = %s\n",binprint(val,buf));
return 0;

To compile save the above code, in a text editor, as ppp.c
Then in the command line execute,
gcc ppp.c -o ppp

And then drop the compiled executable into $/bin/ so it can be executed from anywhere as a linux command.

Flash controller code:
The flash controller is pretty similar to netcar v1, it detects what arrowkey is being pressed and sends the information to the PHP script. I did change the variables though so use the new actionscript,


The PHP program, combined with the C program, is basiaclly replacing what the BASIC stamp did, turning pins high and low to control the relays.

The PHP program gets the command from the flash aplication and, depending on what that command is, executes the C program with the paramaters to turn the proper data pins logic high or low.

In my hardware configuration I mapped pin 2 for forward, so to make the car go forward you would execute,
ppp 1h
Pin 3 is mapped to backward so I make 2 a logic low because you can't be going forward and backward at the same time.

To make PHP execute a program you put the command in single quotes, for example 'ppp 1h 2l'

Let this PHP file sit in the same directory as your flash app.

The rest of the hardware, for me, is the same as Net Car v1 sans the Basic Stamp. You will have to find a parallel port cable to splice open and use a multimeter with a continuity check to find what wires correspond to the data pins and, of course, ground. If you can find a ribbon cable parallel port those are very easy to solder into a chip socket and can be plugged into and removed from a breadboard or another chip socket if you decide to make a circuit board.

The hardware interface to the car remote circuit will be a little bit different depending on how the remote works. I used some double pole, double throw relays, turned on by transistors, to make the connections on the circuit board, which replaced what would normally be the connections made by the controller sticks. Now that I think about it I could have just used the transistors. You may have to put a diode on the base to make sure no higher voltage can back-feed into the lower voltage TTL circuitry, because most car remotes operate on 9v. Please correct me if I am wrong!

Edit: A couple of people recommended in the comments to use optoisolators instead of relays. They draw less power off the parallel port and are simpler, and quieter, than having a transistor turn on a relay. Actually now that I think of it using relay's is probably the most ridiculous idea I have ever had! I kinda like the clicking sound though :-)

The next step is to put a mini wireless webcam on it and stream the video through a webcam service. Or you can just have a webcam look at the car in a room and drive it around with an overview.

Let me know if you complete this project successfully, take a video and post it as a video response to my youtube video.