1

I have a device that takes commands in the form of RS232 communication. I've connected the Arduino's USB port, through an adapter, to the device's 9-pin serial port, but no communication has happened.

The full chain of adapters is a printer cable (which would connect the Arduino to a computer), a female-to-female usb adapter, and a Sabrent USB to serial adapter.

I made sure the communication wasn't happening using the code while (!Serial) and blinked an LED in a certain pattern.

Is there something I'm missing? How do you get the devices to communicate?

2
  • 1
    This sounds a lot like an April fools joke.
    – Gerben
    Apr 1, 2017 at 18:17
  • That is rather inconvenient. In this case, though, Arduino is just not my strong suit. Apr 1, 2017 at 18:19

2 Answers 2

3

This is effectively not workable. USB is not a peer-to-peer standard, but a host/device one. Both your Arduino and the USB-serial converter are intended to be devices, so they cannot communicate. While it would be possible to use another microcontroller acting as a host to bridge to serial that would be pointless, as the actually central problem of RS232 vs. logic level serial would still need to be solved.

Instead, what you want is an inverting serial level shifter - essentially a board with an IC like a MAX232 or one its many successors. You would either connect this to arbitrary digital pins of the Arduino and use a Software Serial instance, or decide that it is okay to block usage of the USB port by a computer while this is being operated, in which case you could connect it to the D0 & D1 pins used by the on-board USB interface (there are typically resistors in between the chips on the board to support this overriding).

Ironically, in a way what you want is one of the original Arduino boards that had a serial level shifter and 9-pin connector in place of the USB chip and USB connector of modern boards. But then, you probably want something with an ATMega328p rather than the earlier, more primitive ATmega chips used on the original boards. If you can still find a board of the original design, upgrading the chip may be an option, or it may be that your task is simple enough not to require it.

There have been many other non-Arduino embedded controller boards released with native RS232 ports as well, especially those dating from around a decade ago might give a good combination of fairly modern capability with not yet having abandoned RS232 in favor of USB.

1

Any network of USB devices involves a single host talking to many slave devices. The typical connection to program an Arduino board is, on the USB side:

PC (USB Host) <-> USB Cable <-> Arduino (USB Device)

On the Arduino board you have the serial side of this communication:

USB Serial Adapter <-> TTL serial lines <-> Microcontroller (RX/TX on D0/D1 pins)

The microcontroller itself has no idea that any USB communication is involved. The USB serial adapter functions as a device only, not a host, so plugging it into another USB device (though a cable with device connectors on both ends, rather than the usual host connector on one end) will not do anything.

(There are some Arduino boards, such as the Leonardo and the Micro, that use an ATmega32U4 microcontroller with a USB device interface built in. These work in substantially the same way as above except with the without the serial adapter and TTL serial link. The built-in USB interface also cannot be used as a USB host.)

Arduino USB Host Shield

If you really want to use USB communication, SparkFun sells as USB Host Shield that you can add to a standard Arduino Uno or similar device. The library for it apparently supports USB serial, though you'd want to confirm that before buying the shield. This would leave the Arduino's USB/Serial interface used for programming free to remain hooked up when using the USB host shield, making development easier.

Direct Serial Connection

A better method (IMHO) is to drop the USB stuff altogether and, as Chris Stratton describes in his answer, have the Arduino talk TTL serial directly to a level shifter (e.g., this breakout board or this shield) that is connected to your RS-232 device. I would go with communications on non-programming pins (i.e., not digital pins 0 or 1) using the SoftwareSerial library or the AltSoftSerial library. (You don't mention the speed of the link, but software serial is generally ok up to 57,600 bps and, depending on the device and what else you're doing, even 115,2000 bps.) This will let you use the serial link to the computer for debugging while running your application.

If you need to work at higher speeds or you just prefer to use a UART (hardware serial), you have two options:

  1. Use the USART on digital pins 0 and 1, and be unable to talk to the computer while you're using it to communicate with your RS-232 device.

  2. Use an Arduino board with more UARTs or USARTs on it, such as the Mega.

Not the answer you're looking for? Browse other questions tagged or ask your own question.