6

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.

GuySoft
  • 935
  • 2
  • 10
  • 25
intensified
  • 61
  • 1
  • 2
  • 2

2 Answers2

6

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.

GuySoft
  • 935
  • 2
  • 10
  • 25
0

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.

Butters
  • 1,597
  • 8
  • 23