raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Turning on/off USB Power

Mon Jan 22, 2018 7:43 am

Hi All!

I have a quick question.

Using the following code I found in another topic on this forum, I am able to successfully cut power to a USB device on my Raspberry Pi Zero W:

Code: Select all

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 1 second.
I was under the impression it should stay off until the echo 1 command is sent.
Am I doing something wrong?

Does anyone know how to cut power for 5 seconds?

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

drgeoff
Posts: 10096
Joined: Wed Jan 25, 2012 6:39 pm

Re: Turning on/off USB Power

Mon Jan 22, 2018 9:40 am

raspz1 wrote:
Mon Jan 22, 2018 7:43 am
Using the following code I found in another topic on this forum, I am able to successfully cut power to a USB device on my Raspberry Pi Zero W:
I don't know what you are smoking but you are under a delusion! It is impossible for software to cut power to a USB device on a RPi Zero(W). The power pins on its micro-USB data socket are directly connected to the power pins on the micro-USB power socket, the 5 volt and ground holes of the GPIO header area and the inputs to the DC-DC converters on the board.

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: Turning on/off USB Power

Mon Jan 22, 2018 9:59 am

Heya drgeoff,

Haha yeah that’s what I read when I first started looking into the issue, but it actually does work.

I was as surprised as everyone else haha

I read an explanation somewhere that said it uses a work around, telling the Pi there was a power surge or something so it cuts power - but don’t quote me on that.

I can post a video of the device turning off when I issue the command if that helps :)

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: Turning on/off USB Power

Mon Jan 22, 2018 10:07 am

Here ya go.

Excuse the video, I’m currently overseas and friend was holding the dongle for me and filming the results (to see if it would turn off).

It does and can no longer be found by lsusb, and when it reloads has a new IP address and everything:

http://sendvid.com/fukj9xmq

mattmiller
Posts: 2166
Joined: Thu Feb 05, 2015 11:25 pm

Re: Turning on/off USB Power

Mon Jan 22, 2018 10:38 am

#TopTip

When repeating a question you've already asked somewhere else - copy and paste your whole post - don't give a cut down version

We are not psychics :)

https://stackoverflow.com/questions/483 ... -4g-dongle

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: Turning on/off USB Power

Mon Jan 22, 2018 10:44 am

Hi Matt,

Yeah I wasn't sure if I should copy it all or not?

I figured this question was much more specific and as someone else was likely to search this topic at some point too using this title, it might be better in the long run?

Thanks for your input though :)

User avatar
topguy
Posts: 6073
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Turning on/off USB Power

Mon Jan 22, 2018 11:42 am

My guess is that the power is not removed but a "reset" (or shutdown) command is sent to the device, and that causes what you see in the video.

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: Turning on/off USB Power

Mon Jan 22, 2018 2:00 pm

Hey topguy,

Thanks for your message!

Out of curiosity, have you seen this thread?

viewtopic.php?t=93463

Although it’s for another Pi model, there seems to be some conflicting/interesting discussion about what’s happening to cause this functionality.

Also, if it’s sending a reset command, would it reason to assume there’s a shutdown/start command too?

drgeoff
Posts: 10096
Joined: Wed Jan 25, 2012 6:39 pm

Re: Turning on/off USB Power

Mon Jan 22, 2018 2:37 pm

A already stated, while the Zero(W) is powered up there is ALWAYS power to the micro-USB data socket.. Therefore any reaction to a software command is a function of the USB device that is plugged in. And not all will behave in the same way.

PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

Re: Turning on/off USB Power

Tue Jan 23, 2018 7:19 am

I've given up on the Pi zero for low power apps because you can only put USB modems to sleep not switch them off. I can get lower current drain with a full sized board pi2 B+ using os.system("echo '1-1' > /sys/bus/usb/drivers/usb/unbind") in Jessie to physically switch the ports off. It's a difficult topic to research online, so much irrelevant guff from earlier hardware & software that is simply no longer applicable.

Return to “Advanced users”