control stepper motor controller by serial port


Thread Starter

Sumon Saha

I want to build a circuit that will control a stepper motor via PC serial port. Interfacing language must be Turbo C. Can anybody help me?

I have already build such type of circuit that control a stepper motor via PC parallel port. But now I want to switch on serial port. What to do and how?

Sumon Saha
Department of Mechanical Engineering
Bangladesh University of Engineering and Technology
That is not easy. The problem is that using the serial port you dont haver enough outputs (you need minimum 4 outputs). You may use an interfase (like a PIC microcontroller) were you connect your serial port and it will provide the control to your stepper.
Thank you for your suggestion. But I don’t have any basic idea to use microcontroller. I know there must be at least 4 outputs needed to control a stepper motor. And using a RS 232, 9 pin serial port, we have got only 1 output pin. That’s why I want to use a serial in and parallel out shift register to get at least 4 outputs simultaneously. Is it possible and let me know how to access serial port by turbo C language.

stepper motor

I need to control stepper motor with serial control, I need to learn about the clock, IC and that circuit.
<p>The code exercises the stepper with a series of "interesting" commands to test the accuracy of the BCD to binary conversion and the logic for the direction reversal code. Since there are the same total number of steps in both directions, your motor should (if you are lucky) end up back at the position it started.

<p>The whole test will take about 15 minutes to run, go and make some tea [email protected]
[email protected]

/* Test Suite for Stepper Motor Controller with serial interface */
#include #define STEPPER "/dev/stepper" int fd; /* file descriptor for comm port */
FILE *fp; /* same as a FILE * */ /* format of input command is */
/* A+xxxxx:nnn */
/* A = chip ident */
/* + or - is step direction */
/* xxxxx is 5 digits of step count */
/* : delimits step count from step rate */
/* nnn is step rate in milliseconds */
/* the string is terminated with a newline char */ /* define a set of "difficult" commands */ struct step {
char dir;
int count;
int dly;
}; struct step s[] = {
'+',96,2, /* one revolution is 96 steps (PJL) */
}; main()
char a[20];
int i;
int j;
int d;
int w;
int n = 1; open_comm(STEPPER); for(i = 0; i < sizeof(s)/sizeof(struct step); i++) {
a[0] = 'A';
a[1] = s.dir;
sprintf(&a[2], "%05d", s.count);
sprintf(&a[7], ":%03d", s.dly);
a[11] = '\n';
a[12] = '\0';
printf("%05d sending: ", i); fflush(stdout);
write(fd, a, 12);
a[11] = '\0';
printf("%s (%d mSec)\n", a, s.count * s.dly);
usleep(s.count * s.dly * 1010);
} int
open_comm(char *dev)
struct termios t;
unsigned char ret_code; if((fd = open(dev, O_RDWR | O_NONBLOCK)) < 0) {
printf("Can't open port %s, %s\n", dev, sys_errlist[errno]);
fp = fdopen(fd, "w"); cfsetispeed(&t, B38400);
cfsetospeed(&t, B38400); tcgetattr(fd, &t);
t.c_iflag = (ISTRIP|IXON|IXOFF);
tcsetattr(fd, TCSANOW, &t); return;
you possibly can't make it simple like with lpt port you can see that its name is serial port which means it has one transmission line that sends 1 bit at a time and 8 bits makes a byte and a byte can be character symbol number or other but the lpt port can send 8 bits at a time one bit in each pin from 2 to 9 so you can make what i suggest (for serial port)

use a 4017 chip and uln2003 chip connect outputs of the 4017 N#:0,1,2,3 to first 4 pins on the left of the uln2003

and power of the two chips and ground to the two chips and connect the ground rail to pin 5 on the serial port and the TX line to the clock on the 4017

the reset on the 4017 to output 4 the clock enable to ground and on the stepper motor. if it has five wires connect the black to power and if it has 6 wires then connect the black and white together to power and the rest of the wires connect them to the right side of the uln2003. if the left side is ordered 0, 1, 2, 3 then on the stepper side connect the wires like this: yellow, orange, red, brown. The 4017 power pin is #16.

the ground is #8. The uln2003 power pin is #10

and the ground pin is #9 please don't supply more than 15 volts for the 4017 and the uln2003 add npn power transistors between the motor and the uln2003 if the motor needed more than 15 volts.

send serial pulses in the TX pin to drive the motor using a terminal program

PS: you may need to add a 4.7Kohm resistor between the clock pin and the ground so it doesn't float.

Please contact me on this email: [email protected]