2

I would like to send data from a RPI3 to another device through a standard USB cable.

Is it possible to use one of the RPI3 USB ports as a serial port to that end?

FYI I am already using /dev/ttyS0 on pins 14 and 15 of the GPIO as a serial port for a sensor.

Graphically, here is what I want to achieve

              GPIO serial                  USB serial
Sensor <-----------------------> RPI3 <----------------> Another device
         (already implemented)

I don't care about Bluetooth, I can disable it to somehow "redirect" its UART to a USB port. I'm just not sure how to do that.

1
  • thanks, this reminded me on how to solve, how to reach my headless Raspberry Pi Zero W when the WiFi is down without having to find a HDMI display.
    – MatsK
    Aug 30, 2017 at 9:59

2 Answers 2

4

You need to connect a USB-UART dongle to the USB port (search for usb rs232 dongle), it will have RS-232 connector that you can use for serial connection to "Another device".

Run dmesg -w in a terminal before you attach the USB dongle and it will display the port that will be created for that device, the output will look similar to:

[ 1755.423293] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
[ 1755.556242] usb 1-1.2: New USB device found, idVendor=6547, idProduct=0232
[ 1755.563308] usb 1-1.2: New USB device strings: Mfr=1, Product=3, SerialNumber=0
[ 1755.570666] usb 1-1.2: Product: USB-UART Controller
[ 1755.575679] usb 1-1.2: Manufacturer: ArkMicroChips
[ 1756.907633] usbcore: registered new interface driver usbserial
[ 1756.945573] usbcore: registered new interface driver usbserial_generic
[ 1756.963615] usbserial: USB Serial support registered for generic
[ 1757.013663] usbcore: registered new interface driver ark3116
[ 1757.044072] usbserial: USB Serial support registered for ark3116
[ 1757.069578] ark3116 1-1.2:1.0: ark3116 converter detected
[ 1757.097247] usb 1-1.2: ark3116 using RS232 mode
[ 1757.124270] usb 1-1.2: ark3116 converter now attached to ttyUSB0

Then you can use /dev/ttyUSB0 as your new serial port.

(edit) The UART to USB dongle should have TTL voltage levels on UART side (either 3.3V or 5V, depending on the "Another device").

4
  • The thing is, I don't want to use an RS-232 connector. I just want to have a regular USB cable between the RPI3 and "Another device".
    – Buddyshot
    Aug 30, 2017 at 8:19
  • 1
    Does the other device have USB connection? If not you have to use the dongle. USB protocol is very complex and it is typically not implemented by simple devices. What you need is the dongle (it does not have to be RS-232 compatible, it does not have to use DB-9 connector and does not use voltage range over 20 volts).
    – midlis
    Aug 30, 2017 at 9:30
  • 1
    You need a dongle that converts complex USB protocol to simple RS-232 signals and that uses your device compatible voltages (either 3.3V or 5V depending on SENSOR spec). They are typically marked TTL levels but be careful about voltage. This one is 3.3V compatible uk.rs-online.com/web/p/products/7676200/…-google--PLA_UK_EN_Semiconductors--Semiconductor_Development_Kits--PRODUCT+GROUP&matchtype=&gclid=CjwKCAjwxJnNBRAMEiwA8X_-QQxgbdgMZeneW5YTSMTJcrkdJqoqKdPiUVbh7WRrL73GN-gBXHbmjBoCGfgQAvD_BwE&gclsrc=aw.ds
    – midlis
    Aug 30, 2017 at 9:30
  • 1
    I was assuming "Another device" was another sensor. If it is a full blown computer (e.g. another Raspberry Pi) @MatsK answer is better as you do not need any extra HW.
    – midlis
    Aug 30, 2017 at 12:35
2

There is a way of using USB in the drawing

          USB serial
 RPI3 <----------------> Another device
 USB Master              USB Client

When changing from master to client is usually refereed to as OTG. Since Raspberry Pi 3 have a built in USB hub it cant be a USB client.

If you use a Raspberry Pi Zero (W) it supports "USB OTG" with the "USB Gadget", it will show it self as a Serial USB device, see ref. 2 and 3 below.

          USB serial
 RPIZ <----------------> Another device
 USB Slave               USB Master

Ref.:

  1. https://en.wikipedia.org/wiki/USB_On-The-Go

  2. https://gist.github.com/gbaman/50b6cca61dd1c3f88f41

  3. https://cdn-learn.adafruit.com/downloads/pdf/turning-your-raspberry-pi-zero-into-a-usb-gadget.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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