Raspberry Pi Zero W USB power

Hi All!

I have a quick question.

Using the following code, I am able to successfully cut power to a USB device:

echo 0 > /sys/devices/platform/soc/20980000.usb/buspower
sleep 5
echo 1 > /sys/devices/platform/soc/20980000.usb/buspower

However, no matter how long the sleep time, it still only cuts power for a second.
Anyone know how to cut power for say, 5 seconds?

I have a USB device that sometimes freezes, and would like to automate unplugging/replugging to save me the tedious exercise of doing so manually each day

Hi Dylan,

Straight off the bat, I’m not sure why that doesn’t work. How are you running it? Are you making it executable and then running it?

Hi Sam,

Made a script: dem
Placed snippet in dem
chmod +x ./dem
then running sudo ./dem

Hmm, what about if you run it from the full extension? ie. sudo /home/pi/bin/script_emphasized text_

Yeah it doesnt change.

It’s almost like something changes it right back to 1 the moment i do it

Hmm, what about if you make it something like 20 seconds? It could also be something in the kernal or hardware implementation which prevents it from being turned off for too long. I’ll have a look and let you know

yeah the duration of the sleep doesn’t make a difference :confused:

Oh thanks!

Well, I can’t seem to find a concrete answer on that. There does seem to be have been changes on how USB power management is handled and what you can do in software. I’m not sure if that has something to do with it though. The easiest way to test that would be to control an LED as well (or some other indicator) before and after the sleep duration so you can see if the script is running correctly and it’s just a hardware management issue.

HI Sam,

I know - it’s infuriating.

The device I’m using does have an LED, so you can see when it turns off & when it turns back on.


Hmm, what I’d try, is get a multimeter out (or even better, a scope), and monitor the 5V line to see if it’s truly disconnecting bus power, or just sending a shutdown message to your USB device.

Haha, bugger, I would but I’m overseas for the next two weeks

No worries, well, perhaps we can get back to it then

No stress,

In the meantime, I may be able to solve my problem using this API:

but I’m struggling with the HTTP post format. Do you know how it’s meant to be written?

curl -d “request=!!omap&Action=1” -X POST

You’re stepping into unknown waters for me too I’m afraid. Someone else from the community might be able to shed some more insight though.

Hi Sam,

No stress found the answer.

In case anybody else is wondering:

download and unzip (on pi) the API from: https://github.com/Schroedingers-Hat/

then install “python-yaml” to run that (sudo apt-get install python-yaml)​

then run “python huaweisms.py connect”, or “disconnect”, or any other action

1 Like

Nice! Glad to hear it all worked out Dylan, definitely some valuable info to have on the forum.