2

I'm very new to Raspberry Pi/Linux/Python world and I'm trying to identify one of the ports on my RPi, so if someone for example, connects a USB Flash drive (or anything) to that specific port an action will occur like turning on a LED and if it's disconnected the LED will turn off. I want the program to run infinitely until interrupted. I've already downloaded PyUSB, and I tried coding but it doesn't work because the only way I figured out how to detect if something is connected to the port is by identifying the idVendor and idProduct of the thing I'm going to connect and then if the program sees that the product is connected then it turns on the LED.

Since I won't always connect the same device into the USB port, I don't think that :

dev = usb.core.find(idVendor=0x****, idProduct=0x****)

will work.

Thanks

4

lsusb will show the USB devices. This has a number of options e.g. lsusb -t will print a tree.

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
        |__ Port 3: Dev 4, If 0, Class=HID, Driver=usbhid, 1.5M
        |__ Port 4: Dev 5, If 0, Class=vend., Driver=rt2800usb, 480M
        |__ Port 5: Dev 6, If 0, Class=HID, Driver=usbhid, 1.5M
        |__ Port 5: Dev 6, If 1, Class=HID, Driver=usbhid, 1.5M
  • yeah, but if I already know the Port that I want to designate for the turn on/off of the LED when a device is plugged into it how can I command it to notify me when is being used? – Valeria A Sierra Oct 30 '14 at 13:36
  • Because for finding an specific device being used (one that I know its id) I can use usb.core.find(idVendor=0x****, idProduct=0x****), but I don't know what to use for a port... – Valeria A Sierra Oct 30 '14 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.