Misc‎ > ‎

Parallel Port

YouTube Video

I used the code from eagerfish to make a simple parallel port control. There's
a BC547 transistor controlling the relay. The LED's are all connected to the parallel
port outputs through a 1K resistor.

This is the basic code I used - it's for linux (I use Ubuntu), there's plenty of windows examples
around though, if that's what you use. I added some code to read a file and output a number
to the parallel port depending on the contents of the file. I'll update the page when it's finished.

I used this code to control this wire forming machine below :

YouTube Video

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>

#define BASEPORT 0x378 /* lp1 */

int main() {
char c;
int n, tem;

printf("Hit any key to stop\n");

//set permissions to access port
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

tem = fcntl(0, F_GETFL, 0);
fcntl (0, F_SETFL, (tem | O_NDELAY));

//main loop where actual blinking is done
while (1) {
//if some key is pressed, break out from loop
n = read(0, &c, 1);
if (n > 0) break;

//write 'on' bit on all data pins and wait 1/4 second
outb(255, BASEPORT);

//write 'off' bit on all data pins and wait 1/4 second
outb(0, BASEPORT);

fcntl(0, F_SETFL, tem);
outb(0, BASEPORT);

//take away permissions to access port
if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}