USB2Serial Adapter As An I/O Device

There was a time when computers had parallel ports. For the hacker types, this meant an eight bit data port, and nine additional pins which could be interfaced with the real world via the 25 pin connector. This is no longer the case, although USB does help with suitable hardware. [Jabi] was working on a project that required controlling one relay to switch a strip of LED’s. His solution was to use a USB to Serial Adapter as an I/O device (Spanish, translated here).

He wrote a short C program, SioFus (Simple Input Output from USB2SERIAL), that converts a simple USB to Serial Port Adapter into an I/O device with 4 inputs and 2 outputs. It’s simple and gets the job done. The code uses ioctl and allows DCD, DSR, CTS and RI to act as inputs while DTR and RTS act as outputs. These pins then likely control transistors that switch the relays. The SioFus code is available on github and there are a couple of to-do’s on [Jabi]’s list if you would like to chip in.

The video after the break supposedly shows the hack in action. Seems like some kind of photo booth which then spits out a QR code, possibly a URL to the picture (post in the comments if you figure out what it does).

If you are looking for a more dedicated hardware, check out the Tiny Bit Dingus – a microcontroller stuffed into a USB plug with a few controllable pins.

19 thoughts on “USB2Serial Adapter As An I/O Device

  1. USBasp, an ATmega8 based Atmel programmer with firmware built around the v-usb library and available very cheap on Ebay can also be reused to provide a few pins of USB to GPIO. There’s also a v-usb based bootloader which emulates a USBasp floating about which enables firmware updates without any other hardware.

  2. Yeah, I’ve done the flow-control-lines-as-io before. It is incredibly useful if you just need to QUICKLY control / read something. I used this to measure the RPM of a motor I was playing with. The computer code, plus using an FTR232 (one of those sparkfun breakout PCBs) like this took all of like 20 minutes.

  3. Some of the bigger ftdi USB to serial chips have several gpio ports that can be used to do… Well, gpio. Haven’t used the feature yet, but now, as I’ve reminded myself of it I think I must expand my own serial dongle with a few extra pins…

  4. If all you need is a few pins and all you have is a serial adapter on hand, and can put up with the usual USB idiocies, then this is just fine.
    But if you want a USB->parallel adapter, there’s no need for microcontroller heroics: just buy the thing: Less than US$10 from a variety of vendors. You still have the pain of USB and can’t bitbang it like the good old days (e.g. driving three stepper motors simultaneously with timer interrupt-driven 1500 hz update rates, like I did on a 386 in 1991), but that’s progress…

  5. In case you wonder: that USB vendor id / product id belongs to an ATEN UC-232A, which is a Prolific PL2303 USB-to-serial converter. Pretty common chip these days. Unless it’s the SOP8 package variant, it has multiple GPIOs (between 2 and 12).

    Point is that you’d need to patch the linux PL2303 kernel driver to get nicely abstracted gpio features, and it seems that last september, that project fell asleep: https://lkml.org/lkml/2014/9/10/138

    So, anyone who feels like making the proposed changes to the patch are encouraged to do so. What you’d get in exchange would be a truckload of cheap adapters that suddenly gaining GPIO abilities.

    Abusing the flow control lines as GPIO is pretty common; I’m surprised to still see this blob up on hackaday; it’s so 80s :D I can see that this project was pretty much born out of “I have this lying around, and nothing else”, but of course just choosing an FTDI chip would have solved the problem; libftdi lets you do pretty much everything GPIO-wise.

    1. That is assuming the “truckload” of cheap PL2303 clone chips would work with the GPIO abilities that the real one has. The handshake lines part at least should work.

      The clone chips I have are only cloning HXA version and there are only 2 GPIO if they bother to clone that.

  6. “There was a time when computers had parallel ports. This is no longer the case.”

    If you do need a parallel port (a proper one for CNC use rather than a USB one) then many Dell PCs still have them.

    1. many mainboards also still have one, as a pin header, on board. Just because it’s not wired to the chassis back doesn’t mean it’s not there! Space has gone sparse on Mainboard connector panels, and I can’t blame anyone for the decision to include 4 USB3 ports instead of one parallel port these days.

    2. I doubt that these parallel port are the old fashion ones. On the old IBM PC the parallel port was a controller directly connected to to CPU mains bus (address, data, control). Nowadays every peripherals goes through north-bridge and south-bridge adapters chips and so often serial port and parallel port are in fact connected to an internal USB bus…

      1. “serial port and parallel port are in fact connected to an internal USB bus…”
        No way. At least on the higher-end mainboards we buy for our products. The ports would enumerate as USB devices in this case, and they don’t. Thank goodness. USB flakyness is our number one problem in our (semi-industrial) PCs, so we rely on hardwired RS-232 ports, or TCP/IP for the critical stuff. Keyboards, mice and user’s memory sticks are the only thing we let see USB.

        1. In modern PC’s typical place for serial and paralel ports (and other ISA-ish things that one expect PC to have like PIC, DMA controller, 8042…) is LPC, which stands for Low Pin Count, from software point of view it mostly looks like completely normal ISA bus while in HW there is large benefit of having 7 wires instead of at least 40.

          The link between northbridge and southbridge either is PCI or at least something that sufficiently looks like PCI (many Intel chipsets use what amounts to PCIe with different voltage levels). And on PCI there is special support for one device on each bus that handles othervise unhandled addresses, this device typically is ISA bridge (or equivalently LPC controller). Due to this mechanism, CPU sees ISA/LPC peripherals as if there was no PCI in between (as long as there are no address collisions with anything upstream).

      2. They may be hooked up on the LPC bus, but rarely USB… RPi is an exception, but it is not a PC motherboard.
        LPC bus emulates the old ISA bus maintaining the I/O address compatibility and behaviors for those peripherals.

Leave a Reply

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