I am currently doing a project with the Raspberry Pi as a controller connected to a PC via USB and using the Pi to send commands to other devices connected via GPIO pins.

Simplified version: communication from PC to Pi to rest of system.

I'm wondering if it is possible to write a script on the Pi to control its USB ports on boot, so that data can be sent from the PC and received on the Pi without having to run anything manually by ssh/vnc.

I'm also planning to write up a PC app so that commands can be issued from the PC to the Pi in the future, once I am able to get the USB comms. working.

I hope someone could assist/point me in the right direction for going about this. I've looked at usbnet and pyusb for information on this.

2 Answers 2


The short answer is - you cant. Or really, there is no point.
A connection between two computers using a cable is called a "direct cable connection". Or in your case "USB direct cable connection". The problem is that USB also supplies power, and you can't connect two USB hosts together. If you do that, you need some spacial cable which is in fact two USB network adapters bridged together (on deal extreme).
There is no point really.

You could use a USB to UART connector, and connect that to the GPIO (which I tried here). That would be a serial communication. Then do the following:

  1. connect TX and RX pins from the serial port to the PI
  2. Connect the ground pins of the serial connector and the PI
    Diagaram is as follows:
    Pin Diagram

  3. run this in the PC terminal: screen /dev/ttyUSB0 115200

  4. Turn the PI on (you need to turn it on when the serial port is connected and minicom is running, otherwise you wont see any output).

  5. You should now see the boot sequence in your terminal, followed by a login screen.

Or you could communicate using the /dev/ttyAMA0 device on the PI, and (usually) the /dev/ttyUSB0 device on the PC.

  • Thanks for the guide you posted, I was wondering could you elaborate more on what do you mean by 'there is no point" to communicate via host-to-host configuration from the pc to pi. It is possible to communicate between them by using a special host-to-host cable right? I was thinking of running all the sending/receiving of data headless on the pi, meaning the ports are sent to "listen" for any incoming data after it has booted. As I'm new with writing scripts, I was wondering if there are tutorials available to perform the above said methods of communication without accessing the terminal? Commented Jun 3, 2013 at 21:32
  • A USB connection is the same as connecting Ethernet ports between two computers. If you are trying to avoid networking, then USB would not help you, because a USB direct cable connection would imply a network connection. Its not a "host-to-host", its a "host-network-adapter-network-adapter-host". If you want to communicate without accessing the terminal, you can either use the serial port as I said above, using /dev/ttyAMA0 and pySerial. Or the network with something like socket.
    – GuySoft
    Commented Jun 3, 2013 at 22:03

Why not use a serial connection through the RX/TX GPIO pins, or SSH with a network connection? You should be able to accomplish what you are after, as long as there is not a reason you are not using these methods. Both can be done in a headless fashion, as long as you have the correct poller or listener script running on the pi.

the code to support this would be different depending on the desired task and language used, but should be pretty simple to write.

Your Answer

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

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