Controlling Motors Without A Microcontroller

serial

Think you need a microcontroller or a proper motor driver to control a motor? Not really. Because RS-232 serial ports are a hack in and of themselves, you can control two motors with only a serial port and a bridge driver.

Instead of using the data pins on the serial port, this circuit works on with the DTR and RTS control signals of an RS-232 interface. Unlike the data lines of a serial port, these control signals are high when they’re enabled and can also provide a small amount of current – enough to control a pair of pins on a TA7291P bridge driver.

The rest of the circuit consists of a few resistors and a pair of motors, and the software simply turns the DTR and RTS lines on and off. It’s enough for a small robot to waddle across a table, and given the correct driver is simple enough to mash together out of parts from a junk drawer.

63 thoughts on “Controlling Motors Without A Microcontroller

    1. If you read the first paragraph of the article, he says the project is to control a motor via a USB port using a $4 USB-serial adapter.

      It still seems to be a lot of trouble to avoid using a microcomputer– why not use a uC with USB that can control motor speed, perhaps limit the current with switching and feedback instead of piles of parallel resistors, plus you don’t need to worry about timing of python scripts and ajax web accesses.

      I guess the answer is that we need better uC development systems so someone can easily plug in a cheap USB-enabled microcomputer. Arduino is easy, but expensive.

    2. ” They were outlawed in 1982 for being so slow and dangerous”

      Snork…

      Hint: Embedded folks have been && will continue using serial ports for the basic reason they are simple. I am an Embedded Systems Engineer. The first thing I get working is a serial port for a Command Line Interpreter (CLI). Good to have a back door for the real work – none of that GUI nonsense.

      1. My motherboard is new enough to have PCIe 3.0 slots, but it has two COM ports, a parallel port AND an IrDA port all broken out to headers. From what I’ve noticed, it’s much more common on AMD boards like mine than any Intel equivalent.

          1. Really? I defer to your experience, but isn’t that a pretty pointless way to add that to a motherboard? Even if it’s built into the Southbridge, or whatever they are these days, seems kinda a bizarre thing to add via USB when you’ve got the system bus(ses) available directly.

      2. I’ve heard some of the Intel Atom motherboards have parallel ports (and, I’m assuming, serial ports). Last time I looked, they seemed to be pretty popular with the LinuxCNC crowd for this reason. They’re a good source of info on stuff like this since they not only need parallel ports (unless they’re willing to shell out for more expensive dedicated controllers) but they also need those parallel ports to be implemented correctly (meaning high reliability/stability and low latency). Even many systems that have parallel ports have them tacked on and not build as a core part of the system bus meaning that they have high and very inconsistent latency (this is, supposedly, especially true for many laptops).

    1. Even if your computer doesn’t have serial ports, if it has a PCI slot or a PCI-e slot or a micro-PCI-e slot, then you can get a board for cheap with a fully-supported, real hardware serial port.

  1. The described pinout is wrong

    1: DCD
    2: RX
    3: TX
    4: DTR ***
    5: GND ***
    6: DSR
    7: RTS ***
    8: CTS
    9: RI

    The *** indicates the pins you want to use.

    In other hacks, you can get about 3..4 mA out of these pins.

      1. (accidentally hit “report comment” – oops)

        RS vs EIA: I am an old curmudgeon so I will continue to call it RS232, RS422, RS485.

        Just like I use DB9 and DB25 which are not correct, at least for one of them. Deal with it. The people I talk to about them understand and that is the critical part.

      2. You are correct about the line break, although there are two issues:

        1. RS levels are not TTL levels. A TTL one = 5v (the idle state for TX), and .LT. -3v for the RS level (-6v is typical). The TTL zero = gnd, and .GT. 3v for RS level (typical = 6v)

        2. the line break logically emits a TTL 0 for the data biits. You will actually get 9 bits low, including the stop bit (assumes no parity & 8-bit data). You will get a following one or two stop bits, which are TTL ones. Thus, you basically get, for one byte, a duty cycle of 9/10 or 9/11

        Note using the TX line you can hack a PWM output.

        3. you would need to continually send the line break instead of setting DTR or RTS once to change their states.

      3. #1: I specifically used the “RS232” term “logical 0″ to signify whether the signal is asserted, not the actual voltage level or logic family. It is even used in that “RS232” wiki link.

        Neither are the other handshake lines you pointed out as TTL levels. So not even sure what points you are trying to make here except that you are unfamiliar with the subject.

        Hint: “Line break” is not a real character. It is a condition when the TxD line is held low for longer than one “word time”. Hence I specifically said “By using a Line Break” instead of the word “sending”.

        http://byterunner.com/16550.html
        LCR BIT 6: (LINE CONTROL REGISTER (LCR) )
        Break control bit. It causes a break condition to be transmitted (the TX is forced to low state) when set to 1.

        You set that bit on the UART (or equivalent in USB or OS call) and the TxD line is set to “logical 0” until you reset that bit in the register. So in the host, you can treat it as a output port pin.

        Your #2 and #3 assertions are incorrect.

        Hopefully someone else would learn something from this.

        1. I know normal RS232 very well – nothing I said about voltage levels was wrong. Quiescent (non-assert) TX TTL is VCC (5/3.3); asserted is gnd. RS232 de-asserted is .lt. -3v and asserted is .gt. 3v. This is the reason the original hack works (assuming you use the right pins).

          I have actually never used a line break. I did make an assumption, which you caught. So, I got #3 wrong. Thank you for the correction.

          Now, one CAN use the TX as a PWM signal, with the caveat that you will have one low bit and 1..2 (actually 1, 1.5, or 2 bits) high for the time period – assuming you continually send characters. Depending on the receiving device, the duty cycle is #times_high / #total time, ie 50% duty cycle is half of the time high, half low. The receiving device *might* assume all of the high time is first in the period, maybe not.

          My #2 is wrong for line break – you are correct. However, if you send a 0x00 byte it is true – again, I don’t use line break. You would need to continually send the desired character.

          Note that RS232 bit order is: …

          Handshake lines:

          The handshake lines, if used, are at RS232 levels because (by default on systems) they go thru a level shifter, ie a MAX3237 or MAX3241 or similar chip.

          If you are building a system and want two boards to exchange data, you can use a UART on both and keep the TTL-level signals. We did this on an E1 clock sync box to allow boards to communicate over the backplane.

          If you read the RS232 IEEE spec, circa 1996 [rev D] (when I lived with it for several weeks), the handshake and data names apply to the CONNECTION not the PINS, because you are connecting a DTE and DCE ftp://ftp1.digi.com/support/cabling/dte_vs_dce.pdf (quote below)

          “This is one of the most misunderstood areas of RS-232. DTE stands for Data Terminal Equipment, and DCE stands for Data Communications Equipment. DTE is typically either a dumb terminal or the serial port on a computer/workstation. DCE is typically a modem, DSU/CSU, or other piece of data communications equipment, hence the names. This is all most people really need to know about these terms.

          Where it gets confusing is when you start to talk about signal definitions and direction. For example, it’s easy for someone to understand that when you transmit data, you send it out. However, when you talk in terms of DCE, it becomes an input signal. This is because the specification was written from the perspective of the DTE end of the link. Another example is the Receive Data signal is an input to DTE, but an output from DCE.”

          Note the standard PC serial port is DTE. The easiest way to tell which pin on a port or cable, assuming DB9 – oops DE9 – is to know pin 5 is ground. Use a meter with the minus lead on pin 5. The pin 2 or 3 with voltage is TX (if quiescent, will be around -6v) – most useful when looking at a cable to determine if the cable is straight-thru or cross-over.

  2. I got yelled at a few weeks ago for suggesting the jacks have been largely deprecated, despite the fact that very few, if any recent computers have this port. My 2009 Dell Precision lacks them.

    I think a USB->RS 232 FTDI cable would do fine. But an FTDI cable costs as much as some USB-enabled microcontroller boards.

    Peachy Printer forgoes a microcontroller and uses the analog audio jacks, to save all of a buck or two more needed to place a uC on the board.

    1. any computer with expansion slots can take a serial port card

      “an FTDI cable costs as much as some USB-enabled microcontroller boards.”

      if you look on ebay or dealextreme, you can find ftdi cables or adapters for about $5.00 or maybe even less.

        1. Be wary of those kind of serial port cards depending on what you want to do with it. For example, the guys in the LinuxCNC community (who rely on parallel ports, not serial ports, but the same kind of issue may apply) have found that even system that have parallel ports installed by default aren’t always capable of supporting their needs. Some parallel ports (seemingly mostly laptops and newer systems where the port was tacked on instead of being part of the core bus design) don’t provide the low latency and/or consistent latency values they need for highly responsive control of their stepper motors.

      1. “if you look on ebay or dealextreme, you can find ftdi cables or adapters for about $5.00 or maybe even less.”

        That’s the thing, I think you can get microcontroller boards for similar cost. Adafruit Trinkets run $8.00, a Chinese cloner wouldn’t have to do much to go under $5 each.

        1. I bought about 30 of the Pl2303 chips for a total little over $3 with free shipping. I thought ~$0.1 per chip was a typo. :) It takes me less than 15 seconds to desolder/recover those packages, so it was a risk worth taking.

          Out of 4 chips I tried, 3 of them works fine as is with latest drivers for Win7 x64. That 4th one would probably work with older uncrippled driver or libusb. I can see its usb info, but the driver knew it was a “fake” part.

          I built a USB-Serial converter with an old Dell desktop +/-12V GD75232 chip (powered by a beefy external switcher) for my old programming dongles.

          I am planning to use one to as a bitbang SPI to drive a 74HC54 for more output pins!

    2. “I think a USB->RS 232 FTDI cable would do fine.”

      Not really. Those kind of controllers are almost always designed for very limited use-cases. The differences between between how USB and RS-232 work mean that developing a converter that is stable beyond extremely short bursts of info is extremely difficult. Most adapters don’t bother trying, meaning that any attempts at stable long-term connections (more than maybe a few seconds to a few minutes) will break in the middle of communications.

      The testing lab I used to work at ran into this problem while trying to use USB-to-RS232 adapters to connect to the previous generation of RS-232 only data acquisition units for high channel count measurement of heat values over extended test periods (hours, days, weeks, etc.). We ended up having to do a lot of comparative testing and found that the only unit that could handle even a moderately long-term stable connection was the USB-to-RS232 adapter from National Instruments (which makes sense since they sell data acquisition hardware). Unfortunately, as can be expected, those units don’t come cheap.

      1. The problem with USB/serial adapters is the USB protocol itself. This is a polled protocol. Any usb device can’t send data to host computer until asked for. So if your application stream serial data to usb/serial dongle this one will buffer it and transmit data when polled by host PC. This imply delay and possible buffer overun in the dongle if there is no hardware handshake between the appliation board and the dongle. USB host polling interval may be as much as 1msec ore even more. Not good for realtime application.

      2. The modern day chips have 128 bytes (or 256 or even more) of data for each of the 1ms or so between USB poll. So you are looking at 128×10 bit/1ms = 1.28Mbps ballpark which still *should* work fine in theory.

        More likely those pesky power management would shut down the hub or the chip and the level shifter if they have been idling for a while. They probably don’t wake up in time to catch the next burst of data. Or it could be firmware and/or driver bugs etc.

      1. Its really odd though. Dell doesn’t seem to care to include that in their list of features. although they also don’t list the Ultra small form factors that we use either. I know HP also has a series of PCs that have it as well

  3. I do appreciate machines that still have serial ports – and yes, sometimes they are only available as headers on the mobo, but they are still there! Also, some docking stations have real serial ports (not USB dongles). I still have plenty of serial-connection hardware and *use* my serial ports for data.

  4. the argument that parallel or serial does not exist on a brand new state of the art computer is moot.

    if you only own one computer, you arent quailified for the job.

    if i owned a company i would only hire people that walk through the door with
    THREE laptops.

    fast dualboot (XP or newer / linux)
    old dualboot (win9x / oldlinux)
    and ancient dualboot (dos / win31 / veryoldlinux)

    why? cuz he can get the job done in 3 minutes including booting up.
    that saves the boss hours of him installing virtual operating systems andor allowing them to use port from within VM.
    … or fiddling with drivers only to find out the three USB-serial converters he has are not compatible with robot XYZ.
    when the 1million$ robot was created, they assumed that the owner would have five (freaking) dollars spare for a used laptop to upload the new design file.

    only boring consumer software is guarenteed to use the serial port in a standard way.
    everything else needs direct, hardware registers.

    PS: my desktop computer has hardware serial and it is dualcore. my ram is measured in GIGAbytes, yet i can signal to the outside word. LED if you will.
    stop FINANCING the end, buy one with serial!

    PPS: you could always BUILD ONE…
    if you use sata diskdrives(CD/DVD/ect) then you have free IDE cable!
    if your not looking for RS232 and only want direct parallel then throw a few logic chips at your IDE/PATA port and tell windows it is a standard LPT port.
    then you can open avrdude and tell it your using parallel at IDE address.

    1. Lucky for us you don’t own a company then. And lucky for you as you couldn’t get anyone to hire anyway ;)

      But seriously: for many people having more than one computer is a problem so the decreasing number of machines with serial ports is a real trouble.
      For desktop machines it’s still relatively easy to add ports via expansion cards and, as you point out, will most likely support at least one ATA port.
      Notebook/laptop computers is much harder to do hardware hacking with. ATA was dropped ages ago, Expresscard slots are reserved for mobile workstations and even usable internal PCI express minicard slots are almost non-existant. If one can live without WLAN support it could be possible to hack a Expresscard serial card into that slot, IFF one can find a true PCI express -> serial bridge Expresscard and not a (the usual case) USB->serial one.

      USB->serial sometimes works, many times not. USB->parallel almost certainly will not work for anything.

      There is one chance that one could tap into the LPC (low pin count bus – a shrunken ISA bus) and wire a super-IO chip into it. But that’s a slim one.

  5. No ports?

    I’m here on my lunch break at work. My workstation is this little Dell thingy about the size of a three-ring binder and only a couple of years old. It clearly has a serial port sticking out the back.

    Maybe things have changed in 2 years? I just did some random clicking on motherboards on newegg.com. Sure enough.. no serial ports. But… they do still have PCI and PCIE slots. It really isn’t that hard or expensive to add a serial port or ten. Actually… it isn’t hard to add parallel ports… 8 inputs, 8 outputs as well as a number of control lines. It’s almost like a whole Arduino built into your computer!

    Better yet, you don’t have to check each time you plug in if it’s TTYUSB0, TTYUSB1… TTYUSB9352. It’s always the same every time! You don’t even have to fool around with udev to make it stick to one port, (and do it all over again every time you update udev and the config files get overwritten or the format for them changes).

    USB just doesn’t seem ready for real world use to me when you have to go into /dev (or the device manager) find the device number and update it in some software preference every time you re-plug a device in. And that’s for attended use. If you want to set something up that is automated USB is pretty much worthless!

  6. There’s nothing wrong with taking apart and soldering directly to a USB serial adapter if that is all you are ever going to use it for I guess. It’s kind of presented as the only option though. A quick look at Ebay finds 10 packs of DB9s going for less than $2! I didn’t even browse much to be sure there weren’t better deals nor did I look for a single connector price.

    You could just get a bunch of connectors, solder them to however many projects and then keep re-using that USB to serial converter by just plugging it in. As a bonus, you could switch which project your serial convert is plugged into without disturbing the USB side of the connection. That way your device number doesn’t have to change all the time.

  7. Ha-ha “new guys”, I mean anyone who hasn’t been involved in electronics for 20 years or more. Always trying to kill off a communication or connection standard because their new PC doesn’t think it needs it anymore. LONG LIVE THE SERIAL PORT!!! I’ve built several high end PC’s in the last several years and every single one has a serial port. Maybe not on the connector panel, but on a header at least. Most widgets take that fancy PITA to use, licensed, pay to play USB connector and dumb it down to 9600 serial via a UART. If you were taking to a real RS232 line, you could probably even get away without using a level converter even (as with PICs). USB is great and fast for external drives and such, but most things don’t need the speed and expense to implement it.

  8. Ive actually thought of this myself. The reason is that multi-port PCI-E serial port boards are cheap and readily available. In fact, you could even use dirt cheap dual port boards, either two or three in spare slots,or get one of those 1-4 pci bridges that the bitcoin miners use and connect them through those. There are tons of different options. And its connected directly to the PCI Express buss. (The reason that you dont want to typically control motors over USB is that the latency is variable.)

    I never looked deep enough to see if it would work but the idea was, you have RTS and DTR as outputs on a standard serial port. RTS would be connected to the enable line of a stepper controller IC. DTR would control the direction. The transmit data line would be your step line. It would need a level translator of course. When the line is idle, its in the 0 state. So you just manipulate the data and the baud rate to send your step pulses. If you want a single step pulse, you just send 0xFF at the appropriate baud rate to make the pulse as long as you need it. You also have digital inputs. There is CD,CTS, DSR and RI. (Four digital inputs per serial channel.) Two of those could be used for a quadrature shaft encoder.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.