Atomic2000
Posts: 1
Joined: Thu Oct 18, 2018 6:03 pm

Pi zero with connected to two PCs via USB hub

Thu Oct 18, 2018 6:08 pm

Hi all

I want to connect a pi zero (configured as USB multigadget, ethernet and storage) to two PCs simultaneously. The idea is to get a file from PC 1 via file transfer (mass storage device) to the pi, and then have PC 2 get it from the pi via ethernet. Can I connect the pi to a USB hub and have both PCs connected to that as well?

thanks a lot

User avatar
HawaiianPi
Posts: 2918
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pi zero with connected to two PCs via USB hub

Thu Oct 18, 2018 7:07 pm

No, hubs don't work that way.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

hippy
Posts: 3924
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Pi zero with connected to two PCs via USB hub

Thu Oct 18, 2018 7:26 pm

One can buy USB 'hubs' which allow two PC's to share a USB printer, which might handle what you want.

You can probably knock-up some hardware to allow the Pi to cycle between the two PC's rather than have to push its button. The PC's can run software which can tell when it's connected to a Pi and do it's thing. The Pi can hold of cycling while it's doing its thing.

fruitoftheloom
Posts: 17676
Joined: Tue Mar 25, 2014 12:40 pm

Re: Pi zero with connected to two PCs via USB hub

Thu Oct 18, 2018 7:27 pm

Atomic2000 wrote:
Thu Oct 18, 2018 6:08 pm
Hi all

I want to connect a pi zero (configured as USB multigadget, ethernet and storage) to two PCs simultaneously. The idea is to get a file from PC 1 via file transfer (mass storage device) to the pi, and then have PC 2 get it from the pi via ethernet. Can I connect the pi to a USB hub and have both PCs connected to that as well?

thanks a lot

As you have put the Zero in Gadget Mode (USB Slave)

https://blog.gbaman.info/?p=791

https://blog.gbaman.info/?p=699


You may be able to utilise a USB Sharing Switch ???

https://www.iogear.com/usb-switch.htm
Adieu

hippy
Posts: 3924
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Pi zero with connected to two PCs via USB hub

Thu Oct 18, 2018 7:37 pm

For simultaneous access from both PC's you can use two Pi Zeroes, connect them each to their respective PC, create a PPP/SLIP UART interface between the two to transfer from one Pi to the other.

I was also thinking, rather than buying USB printer sharing hardware; you could perhaps find or create a 4-pole change-over relay and switch the Pi's USB cable between the two. You might be able to get away with 2-pole and just switching data lines, common 0V, Pi on own PSU so no Vusb from PC to Pi.

To be honest; a second Pi is probably the cheapest option and offers more at the same time.

User avatar
thagrol
Posts: 881
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi zero with connected to two PCs via USB hub

Fri Oct 19, 2018 7:01 pm

hippy wrote:
Thu Oct 18, 2018 7:37 pm
For simultaneous access from both PC's you can use two Pi Zeroes
No you can't. The mass storage gadget will corrupt your data if both device(Pi) and host (PC) have write access.

Why?

Neither side is aware of what the other is doing. Read only on one side coupled with read/write on the other can also be problematic.

If both sides read the sames file at the same time you'll be fine, but if one, or worse, both write to it (or make any changes that affect the contents of the disk) the reading side won't get the data it's expecting. If both sides try to write all bets are off.

There is a hack but it's dangerous. Essentially you force a periodic unmount and mount of the storage on both the Pi and the host PC. The problem is that you have no way to programmatically determine when it's safe to do this. There are ways to do this by hand when required but get it wrong and you'll still corrupt your files.
Last edited by thagrol on Fri Oct 19, 2018 7:08 pm, edited 1 time in total.
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

User avatar
thagrol
Posts: 881
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi zero with connected to two PCs via USB hub

Fri Oct 19, 2018 7:06 pm

hippy wrote:
Thu Oct 18, 2018 7:37 pm
For simultaneous access from both PC's you can use two Pi Zeroes, connect them each to their respective PC, create a PPP/SLIP UART interface between the two to transfer from one Pi to the other.
If yoiu can get around the points I made above, or are happy with the risks (and you understand them) I'd either uise zeroW and a wifi link or add ethernet via spi. Both wil be faster than a serial link.
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

Return to “General discussion”