dchapma1
Posts: 16
Joined: Sun Aug 05, 2012 12:54 am
Location: Upstate New York

Control USB port Enable / Disable

Thu Apr 16, 2015 4:49 pm

All,

I am wondering if I can enable / disable the USB ports programmatically using Python, or a script I can call from Python on the Pi?

I have a DSLR camera attached via USB. Typically when the camera sees it is attached via USB it goes into "PC" mode. I want to be able to enabled the USB - then copy the camera photos from the camera, then disable the USB to allow more photos to be taken.

I found the following:
# disable external wake-up; do this only once
echo disabled > /sys/bus/usb/devices/usbX/power/wakeup

echo on > /sys/bus/usb/devices/usbX/power/level # turn on
echo suspend > /sys/bus/usb/devices/usbX/power/level # turn off
where usbX is the appropriately numbered port, i.e. usb1, usb2, etc.

Anyone think this will work on a Pi? I haven't had lab time to try this yet.

Thanks,

Don

TheMiddle36
Posts: 21
Joined: Sun Apr 23, 2017 2:25 pm

Re: Control USB port Enable / Disable

Wed Jun 14, 2017 5:10 pm

I think this is a very good question - I have a use for it myself but so far unable to find any other answers

User avatar
rpdom
Posts: 14722
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Control USB port Enable / Disable

Wed Jun 14, 2017 5:41 pm

There is a way to control the power to the USB ports on most Pis (B+, 2B and 3B), but it is an "all or nothing" situation. You can't switch on and off individual ports.

If the camera presents itself to the Pi as a Mass Storage Device you may be able to use the "eject" command to tell the camera to logically disconnect itself from the port. That may work.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Control USB port Enable / Disable

Wed Jun 14, 2017 5:51 pm

You could get into the true spirit of the Raspberry Pi and stick a couple of transistors on the GPIO to switch the USBs VCC and DATA+ lines.
Would that work?

Dave.
Apple say... Monkey do !!

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Control USB port Enable / Disable

Mon Apr 09, 2018 11:08 am

Hi,
Have you figured this out.. I am trying to do the same thing. I want to disable the usb ports, clic photos through the camera and then enable the usb port to access the sd card.. I want to do it through python programming on my raspberry pi. Can you help me with this
Hoping for a quick response

Thanks & Regards
Sameena Shaikh

User avatar
B.Goode
Posts: 8045
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Control USB port Enable / Disable

Mon Apr 09, 2018 11:16 am

Hoping for a quick response


The person who originally asked this question in 2015 did not apparently receive a straightforward reply and has not logged on to the forums for 24 months. A quick response is unlikely.

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Control USB port Enable / Disable

Mon Apr 09, 2018 11:44 am

Anyone else on the forum who has resolved this issue or who has worked on this might be able to help me

pcmanbob
Posts: 6410
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Control USB port Enable / Disable

Mon Apr 09, 2018 2:38 pm

Well the quickest way to find out how to do this is to do a search of the forum to see how people have done it.

https://www.google.co.uk/search?client= ... 04&bih=986

assuming you are using a pi3B and raspbian as you have not provided that information, then this thread has the commands you need to do it from the command line.

viewtopic.php?t=172313

But as has already been said will disable all USB ports and the Ethernet port.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”