2

Can someone describe how it might be possible to connect a raspberry pi to a PC running mac os or windows 10 via a USB cable which would allow for the computer to send commands to the raspberry pi?

I am being intentionally vague about the "commands" that the raspi would receive, just curious about the options here. Could the PC/Mac send a bash command as in an SSH session? Could it hit an HTTP endpoint / webhook running in a webserver on the PI?

What sort of software would be needed on the non-pi end of the equation. What sort of hardware peripherals or hats could facilitate this on the pi end.

Assuming this is possible, would it also be possible to send large amounts of data along the same cable? Such as delivering a video file from the PI to the PC/Mac?

3
  • Just curious: What advantage do you expect from that (even if it works) over using a network cable?
    – PMF
    May 9, 2020 at 20:11
  • I was looking for a solution that could accommodate the largest number of non pi computers and at least in the Apple sphere the trend has been to have laptops without Ethernet ports.
    – WillD
    May 9, 2020 at 20:19
  • Ok, yea. That's unfortunately true. They apparently believe wifi is better than Ethernet... The Pi does have built-in Wifi as well, though.
    – PMF
    May 10, 2020 at 5:52

1 Answer 1

2

Simplest way I can think of it to set the Pi to have a network connection via USB - note this is only available on some Pi computers such as the Zero, A, CM and Pi 4B via the USB C socket.

Add

dtoverlay=dwc2

to /boot/config.txt

Add

modules-load=dwc2,g_ether

with one space between it and rootwait in /boot/cmdline.txt

The Pi will then connect to the Mac (or a PC) as a network device via USB.

At this point you can then run Python on both the Mac and the Pi using sockets to communicate. A sample of client server programming is to be found here Though others are available.

Remember though the Mac is behind on Python by default, you should really download Python 3.x from python.org - I match the Pi version on my Mac.

As the Pi and computer is networked you can set up netatalk or samba on the Pi to share directories or transfer files via ftp, sftp, WebDAV etc just as any network link. You can just about run Apache At reasonable speed on a zero and do api / json transfers (note I said JUST).

There are USB dongles still out in the internet that where designed for setting up networks over USB for file transfer - never used one but they had them at work many years ago for PC to PC upgrades...

You could also cheat and put two USB/Ethernet adapters in-line. As long as they supported crossover you could then use a normal cable and still 'technically' use USB...

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.