dibner
Posts: 4
Joined: Mon Sep 23, 2019 2:07 pm

How to use the pi 4 usb data with an external power supply to the header pins?

Mon Sep 23, 2019 4:15 pm

I am having trouble with PC - pi4 communications via the USB C port, whilst using external power. Does anyone know the correct way of doing this?

I'm using the pi4 as a USB gadget:
https://dev.webonomic.nl/4-ways-to-conn ... e-internet

Communications are fine when power and data go to the pi through the usb port, but I need a more powerful supply as my pi powered machine takes 35 watts so I am using a 5V (10A max) PSU connected via a master switch to the pi4 header pins.

The first thing I tried was cutting the 5V wire of the usb cable so the machine has only 1 power supply as suggested here:
https://www.raspberrypi.org/forums/view ... p?t=223891

This worked fine on my laptop, but with my desktop PC the drivers would report a device malfunction or even blue screen of death crash "kernel-security-check-failure". So since I need this machine to work on a wide variety of computers I figure I can't use this approach.

So next I use it with the 5V usb wire still connected, data then works fine on laptop and desktop, but as soon as I switch off the master switch, the machine I presume, crudely tries to pull 35 watts from the PC, and only gets 1A, this is just enough to keep some electronics powered but not others, the end result is that the machine will not turn on again unless I disconnect the usb cable to remove all power and start afresh.

Does anybody know the correct way of doing usb data with external power? I'm afraid that this machine will malfunction or damage usb ports if I don't get this right.

FYI: my sd card is read only to protect against corruption from instant powerloss from the master switch.
https://k3a.me/how-to-make-raspberrypi- ... uble-free/

Thanks so much for any help. This is my first ever forum post.

Dibner.

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

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Tue Sep 24, 2019 1:42 pm

Sounds like a driver issue on the PC side.

Be aware that the USB spec is for only 500mA not 1A. Plus, if you're using a USB 3 host and a USB 3 to USB C cable you'll likely hit the known issue that occurs with smart PSUs and/or E marked cables.

You can get finer controller over how the ethernet gadget presents itself to the host by using the libcompsite approach rather than by using the g_ether module. Have a look at RPF's gio expander for one way to do this: https://github.com/raspberrypi/gpioexpander
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

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

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Tue Sep 24, 2019 7:26 pm

Definitely sounds like a PC-side issue.

Cutting the power wire in the PC-to-USB-C cable should be fine and would be the correct way to do it. That should work just as well on your PC as it does on your laptop.

Are your PC and laptop running the same OS ? How the Pi appears to the laptop, in Device Manger or wherever, may give some clue as to what's missing on the PC if it is a driver issue as thagrol suggests.

You could also try setting up your Pi as some other gadget to see if the PC recognises that, which could help narrow down the issue. Setting it up as an MSD g_mass_storage device is easy enough and all modern PC's should recognise that.

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

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Tue Sep 24, 2019 11:42 pm

hippy wrote:
Tue Sep 24, 2019 7:26 pm
You could also try setting up your Pi as some other gadget to see if the PC recognises that, which could help narrow down the issue. Setting it up as an MSD g_mass_storage device is easy enough and all modern PC's should recognise that.
That should give some indication on whether there is a hardware problem.

For what it's worth, I've had success runing a 4B as a USB ethernet gadget via the USB C port with a linux USB host (actually a Pi 1B running raspbian). That was with g_ether rather than the manual setup via libcomposite.

Now, and this is going to get somewhat technical...

I suspect that @dibner is using windows on his desktop PC as BSOD is, in my experience, not a linux thing. Natively, windows only has drivers for RNDIS USB ethernet dongles, linux has drivers for both RNDIS and CDC. g_ether may be presenting to the host as the wrong type. I've no idea how it decides which to use.

While I don't have the link to hand, I believe that by using libcomposite instead of g_ether it's possible to force which of RNDIS or CDC is presented to the USB host.

To establish whether it's an OS related issue, get hold of a live linux CD/USB stick, boot the desktop from that and connect the Pi. If that works it's a fair indication that the problem is in the installed OS on the desktop and not in the hardware. If so, try uninstalling any and all USB ethernet drivers present in that OS.

@dibner: It would likely help us help you if you told us what OS is running on your laptop and on your desktop as well as whether the host ports are USB2 or USB3.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

dibner
Posts: 4
Joined: Mon Sep 23, 2019 2:07 pm

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Wed Sep 25, 2019 6:52 am

Thanks so much for the new lines of investigation and advice.

I should add, that both laptop and desktop use Windows 10. Both pick the pi up using the "USB Ethernet /RNDIS Gadget driver v1.0.0.0. I'm also using a usb micro cable with an adapter to convert it usb C, (actually it goes cable, panel mount socket to usb C adapter to pi, and the 5V line is cut just after the panel mount socket). The laptop has usb 3, the pc has usb 2, I presume that both run in usb 2 mode because of the cable.

The laptop has never failed. The PC is annoyingly non deterministic, previously with the 5V line cut it would never work and sometimes cause crash, this morning it has been working most of the time. This usb cable is 2m long and thin feeling, given that you're saying that cutting the 5V wire should be legitimate, my attention focuses on this 2m thin cable, so I've switched it for a thicker feeling 1m cable. Maybe that could be the issue? For the moment it is working, but I'll have to keep testing because this problem seems to come and go.

I'll look into RNDIS or CDC too.

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

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Thu Sep 26, 2019 12:29 am

If it works sometimes on the PC I would guess there's nothing wrong with the software or drivers and it's more a hardware issue, that provoking the BSOD.

Could be thin cables or even location. I had a hardware set-up once where the two parts would not work side-by-side but would work on top of one another. Never did figure that out but put it down to cable orientation.

dibner
Posts: 4
Joined: Mon Sep 23, 2019 2:07 pm

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Thu Sep 26, 2019 8:55 am

Seems like the 1m cable provides a solution: The usb connection started playing up again and I was able to repeatedly fix the problem and recreate the problem by switching out the thin 2m cable with the 1m cable. Possibly the problem was worse when extra electronics was connected to the same PSU as the pi (despite a 4700uF smoothing capacitor), in any case I have never had any problems with the thicker 1m usb cable.

Not an exciting conclusion but I'm happy because its an easy fix to make.

Thanks so much for all your help.

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

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Thu Sep 26, 2019 5:18 pm

I have just successfully used a 3m USB flat cable with quite thin wires and the power wire cut so I guess it comes down to luck of the draw.

That cable has the wires separated by the outer sheath moulding injected between the signal wires so that may have helped.

dibner
Posts: 4
Joined: Mon Sep 23, 2019 2:07 pm

Re: How to use the pi 4 usb data with an external power supply to the header pins?

Sun Nov 10, 2019 9:56 pm

I discovered that the problem was caused by insufficient ground connection between the pc and the equipment. With the 2m USB cable that failed to connect, I could make it connect by adding a fat copper ground wire between the PC and the equipment. I realised this when even my shorter 1m cable started to be unreliable. (AWG 28 apparently). I am now using USB cables with a AWG 20 ground connection with good results. There was a panel mount female micro usb connection and micro to usb c adapter which would also have been adding resistance, and which I am no longer using, but it was the thin cable where most the problem lay.

... to the best of my knowledge.

Return to “General discussion”