Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / C#
Article

Controlling Floppy Drive Stepper Motor via Parallel Port

Rate me:
Please Sign up or sign in to vote.
4.92/5 (80 votes)
15 Mar 200710 min read 436.2K   10.2K   140   70
Controlling a floppy drive stepper motor using computer's parallel port

Sample Image - floppyStepper.jpg

Warning

The PC parallel port can be damaged quite easily if you make incorrect connections. If the parallel port is integrated to the motherboard, repairing a damaged parallel port may be expensive, and in many cases, it is cheaper to replace the whole motherboard than to repair that port. Your safest bet is to buy an inexpensive I/O card which has a parallel port and use it for your experiment. If you manage to damage the parallel port on that card, replacing it will be easy and inexpensive.

Disclaimer

While every effort has been made to make sure the information in this article is correct, the author cannot be made liable for any damages, whatsoever, for loss relating to use or implementation of this article. Use this information at your own risk.

Introduction

In this article, we will connect a 3½ inch floppy drive to our computer's parallel port and write a program to control its stepper motor. We won't be taking the stepper motor out from the floppy drive because a floppy drive has a built in controller which can be easily used for controlling its stepper motor. The advantages of this are:

  • We will not have to worry about making the electronics for controlling the stepper motor.
  • Assuming that you can use a recycled floppy drive, this project shouldn't cost you anything. Old, unused floppy drives can be salvaged from junkyards and old computers.
  • A good knowledge of electronics is not a prerequisite since we'll only be making a few simple connections.

However, if you have a good background of electronics and you're interested in controlling a stepper motor without the disk drive electronics, read Stepper Motor Control through Parallel Port by Bhaskar Gupta.

Before we begin, I would recommend you to go through I/O Ports Uncensored - 1 - Controlling LEDs (Light Emitting Diodes) with Parallel Port by Levent Saltuklaroglu and be sure to read the sections on Parallel Ports and Hexadecimal / Decimal / Binary if you haven't already done so. Also, make sure that the floppy drive you use is in working order. I've wasted an entire day trying to make a broken one work. It's a waste of time.

Stepper Motors

What they are?

Image 2

So, what are stepper motors and how are they different from conventional electric motors? Simply put, a stepper motor is a brushless, synchronous electric motor that can divide a full rotation into a large number of steps. Conventional motors spin continuously while a stepper motor moves only one step at a time. Therefore, stepper motors are useful for precise motion and position control.

How they work?

Image 3

The simplest way to think of a stepper motor is a bar magnet and four coils. When current flows through coil "A" the magnet is attracted and moves one step to the right. Then, coil "A" is turned off and coil "B" turned on. Now, the magnet moves another step to the right and so on…

A similar process happens inside a stepper motor, but the magnet is cylindrical and rotates inside the coils. For a stepper motor to move, these coils should be turned on in the correct sequence. However, we don't have to worry about this since we will be using the floppy drive's built in controller.

The Floppy Cable

The floppy cable is usually a flat, gray ribbon cable similar to the standard IDE cable. The floppy cable has 34 wires (odd colored wire is wire 1). There are normally five connectors on this cable, but some cables, like the ones I'm using, have only three. These connectors are grouped into three sets:

  1. Controller Connector: This is the single connector on one end of the cable and is used for connecting the floppy disk controller, either on a controller card or the motherboard.
  2. Drive A connectors: The pair of connectors (or single connector in the case of a three-connector cable) at the opposite end of the cable is for the A: floppy drive.
  3. Drive B connectors: The pair of connectors (or single connector in the case of a three-connector cable) in the middle of the cable is intended for the B: floppy drive.

An image from The PC Guide illustrates:

Image 4

You will notice that there is an odd "twist" in the floppy cable, located between two pairs of connectors intended for the floppy drives. The twist changes the connection of the drive on the far end of the twist so that it is different from the drive before the twist. This is done to make the drive at the far end of the cable appear as A: to the system and the one in the middle to appear as B:.

3.5" Drive Connector pin-out

Image 5

Pin #Function
Odd pins (e.g. 1, 3, 5 etc)Ground
2High Density Select
8Index Pulse (produced by the spindle motor for timing)
10A: Motor on
12Drive select B:
14Drive select A:
16B: Motor on
18Direction of movement of the stepper motor
20Step Pulse
22Write Data
24Write Enable (a Low turns on the write circuit)
26Track 0 (a Low puts the head stepper over track zero)
28Write Protect
30Read Data
32Select head (a Low selects head zero)
34Disk Change Switch

Floppy Power Connector

Image 6

Pin-out

Pin #ColorDescription
1Red+5 V
2Black+5 V Ground
3Black+12 V Ground (Same as +5 V Ground)
4Yellow+12 V

Note

Some connectors might supply only two wires, usually the +5 V and a ground pin. This is because the floppy drives in most new systems run only on +5 V and do not use the +12 V at all.

Making the connections

This part is really easy. All you need are:

  • A parallel port cable
  • A floppy cable
  • 3 short single core wires (for connecting the floppy drive connector to the parallel port)
  • A screwdriver (for opening the outer cover of the floppy drive)
  • A multimeter for continuity testing (not essential but if you want to test your connections, this can be really helpful)
  • A floppy drive (duh!)
First of all, open the outer cover of the floppy drive. Check out my pictures below:

Image 7

Image 8

Connect the 3.5" Drive "A" Connector on your floppy cable to your floppy drive. Now, make sure your computer's off and unplugged. Open your computer and take out the floppy power connector. Carefully plug this connector to your floppy drive. Reversing the red and yellow wires could fry your floppy drive. You'll see five notches on the power connector. They should point upward when they're installed. Fortunately, these connectors are keyed and therefore difficult to insert incorrectly. Check out the picture below:

Image 9

Note

If you want, you can extend the power connector cord so that the floppy drive can reside outside the PC case. Just cut the wires (1 red, 1 yellow, 2 black) and patch in a couple feet. There's no need to extend the yellow wire since it carries +12 V, which will not be used by the floppy drive. As you can see in the picture above, I've only extended 1 red and 1 black.

Now, take the motherboard end of the floppy cable and follow the instructions below to connect it to the parallel port cable. Here's a diagram I've made to show the connections:

Image 10

Parallel Port Floppy Cable Connector

Pin # 2 (D0)------> Pin # 20 (Step Pulse)
Pin # 3 (D1)------> Pin # 18 (Direction)
Pin # 14 --> Ground (Drive Select A:)

Here's a picture of the connections I made:

Image 11

I was using a defective parallel port cable and so my parallel port pins are in reverse order. Don't let that confuse you. Just go with the diagram.

Finally, connect the other end of the parallel port cable to your computer. That's it! Make sure all your connections are correct and there are no short circuits.

Writing the code

It's time to write some code. This is a fun and tricky part. It's tricky because even a small bug in your program could prevent the stepper motor from moving. I have used inpout32.dll for interoping. Download it from http://www.logix4u.net/inpout32.htm [^]. After downloading it, put it in your System32 folder and import it into your project:

C#
using System;
using System.Runtime.InteropServices;

private class PortAccess
{
    [DllImport("inpout32.dll", EntryPoint="Out32")]
    public static extern void Output(int address, int value);
}

For sending values to our parallel port, we'll be using PortAccess.Output. This method takes in two parameters, address and value. For knowing your parallel port address, go to Control Panel > System > Hardware > Device Manager > Ports (COM & LPT) > Printer Port (LPT1) > Properties > Resources > Resource Settings. Here, you'll see the address of your parallel port. Mine is "0378 – 037F". This is in hexadecimal form. 0x378 (Hexadecimal) = 888 (Decimal). If you are using LPT2, your address would probably be "0x278" (Decimal equivalent is 632).

For moving the stepper motor, we will have to pulse pin 20 on the floppy drive connector. The direction of movement will depend on the high/low state of pin 18. Now, since pins 20 and 18 are connected to pins 2 (D0) and 3 (D1) on the parallel port, pulsing pin D0 will move the stepper motor and its direction will depend on the high/low logical state of D1. So, here's a sample code for moving the stepper motor 10 steps in one direction:

C#
for (int i = 0; i < 10; i++)
{
    PortAccess.Output(888, 1);
    System.Threading.Thread.Sleep(50); // Delay
    PortAccess.Output(888, 0);
    System.Threading.Thread.Sleep(50); // Delay
}

I'm sending the values 1 and 0.

1 (Decimal) = 0001 (Binary)
0 (Decimal) = 0000 (Binary)

Here, I'm changing the high/low state of D0 but I'm keeping D1 constantly low. Therefore, the stepper motor will move 10 steps in one direction.

Notice that I'm delaying the execution of the code after sending a value. This delay is needed to provide enough time for the magnetic field inside the coils to build up and move the magnet. Without this delay, the coils will switch on and off so fast that the magnet wouldn't move.

To move the stepper in the other direction, send the values 3 and 2:

C#
for (int i = 0; i < 10; i++)
{
    PortAccess.Output(888, 3);
    System.Threading.Thread.Sleep(50); // Delay
    PortAccess.Output(888, 2);
    System.Threading.Thread.Sleep(50); // Delay
}

3 (Decimal) = 0011 (Binary)
2 (Decimal) = 0010 (Binary)

Here, I'm changing the high/low state of D0 but I'm keeping D1 constantly high.

In future, if you plan to use pins other than D0 and D1, always make sure that the values you send are correct. The Windows Calculator can be helpful for performing binary to decimal conversions.

Image 12

The first time I tried controlling a floppy drive stepper motor, I chose wrong values and my stepper wouldn't budge! I was checking the connections over and over but I had no clue that the problem was in my program! I wasted at least two days because of this.

Well, here's a screenshot of my 'working' application:

Image 13

Conclusion

We have reached the end of this article. I hope you enjoyed it and successfully controlled your floppy drive stepper motor. Now what? Just let your imagination go wild!! Stepper motors can be used to perform a variety of small tasks which require precise motion/position control (for e.g. in robotics). I used mine to pan a camera! Check it out on my blog: http://ashishrd.blogspot.com/2006/11/camera-panning-using-parallel-port.html[^]. If you end up making something interesting, I'd love to hear about it. Happy coding!!

History

  • 16-Mar-2007 - Added photo credits
  • 21-Dec-2006 – Minor corrections
  • 09-Dec-2006 – Initial publication

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
India India

Comments and Discussions

 
QuestionOk but how many steps take to move the head from track 0 to the last track? Pin
ArduAngel646-Nov-19 6:10
ArduAngel646-Nov-19 6:10 
Questionhelp plsss Pin
Member 86667847-Mar-12 1:09
Member 86667847-Mar-12 1:09 
where did you encode the code you use. what language I need to run the code. thank very much.
Questionhelp Pin
nek_121-Feb-12 2:41
nek_121-Feb-12 2:41 
GeneralTested & worked Pin
min_2_max3-Jul-11 15:12
min_2_max3-Jul-11 15:12 
QuestionDid you ever have experience controlling a HDD motor? Pin
min_2_max29-Jun-11 1:59
min_2_max29-Jun-11 1:59 
GeneralThank you Pin
jonathan chrimes15-Oct-10 6:30
jonathan chrimes15-Oct-10 6:30 
GeneralUnable to get it to work Pin
BillsR10013-Jan-10 11:57
BillsR10013-Jan-10 11:57 
GeneralStepper motor..prob with demo project Pin
vaibs4u28-Apr-09 5:09
vaibs4u28-Apr-09 5:09 
Generalproblem with stepper motor rotation Pin
vaibs4u28-Apr-09 4:19
vaibs4u28-Apr-09 4:19 
Generalnothing new..... Pin
harishfor19-Feb-09 1:28
harishfor19-Feb-09 1:28 
GeneralTrying at Home Pin
smarch16-Oct-08 12:50
smarch16-Oct-08 12:50 
GeneralRe: Trying at Home Pin
Ashish Derhgawen16-Oct-08 18:27
Ashish Derhgawen16-Oct-08 18:27 
QuestionRe: Trying at Home, followup ! Pin
smarch22-Oct-08 2:51
smarch22-Oct-08 2:51 
AnswerRe: Trying at Home, followup ! multimeter testing... Pin
smarch22-Oct-08 4:52
smarch22-Oct-08 4:52 
NewsRe: Trying at Home project working !!! Pin
smarch22-Oct-08 6:47
smarch22-Oct-08 6:47 
GeneralRe: Trying at Home mounting the beast on the floppy Pin
smarch23-Oct-08 14:58
smarch23-Oct-08 14:58 
JokeRe: Trying at Home mounting the beast on the floppy. SUCCESS ! Pin
smarch6-Nov-08 12:49
smarch6-Nov-08 12:49 
GeneralRe: Trying at Home mounting the beast on the floppy. SUCCESS ! Pin
Mazen el Senih27-Mar-15 6:40
professionalMazen el Senih27-Mar-15 6:40 
GeneralJust one question! Pin
andythepandy9314-Aug-08 8:49
andythepandy9314-Aug-08 8:49 
GeneralReal-Time Color Based Object Tracking Pin
Member 408503517-Feb-08 3:08
Member 408503517-Feb-08 3:08 
Generalinput to stepper motor Pin
vijkanse18-Nov-07 18:07
vijkanse18-Nov-07 18:07 
GeneralFloppy-Drive Interface caution . . Pin
Merv-18-Nov-07 14:43
Merv-18-Nov-07 14:43 
GeneralRe: Floppy-Drive Interface caution . . Pin
Ashish Derhgawen28-Feb-08 16:41
Ashish Derhgawen28-Feb-08 16:41 
QuestionAksing....... Pin
jonnykwest10024-Sep-07 11:44
jonnykwest10024-Sep-07 11:44 
AnswerRe: Aksing....... Pin
Ashish Derhgawen27-Sep-07 19:11
Ashish Derhgawen27-Sep-07 19:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.