Raspberry Pi USB Device Reset

I have to reset an USB device on my Pi and found this extremely helpful little program. It is a bit ugly to find the relation between the device and the bus/device number. There are some hints on the internet like this one:

udevadm info --name=/dev/ttyUSB0 --attribute-walk

I found an easier solution and as I run a cron job to reset the device I wrote a little script that gets the bus/device number and calls usbreset:


result=`lsusb | grep "Prolific Technology, Inc. PL2303 Serial Port"`
#echo $result
tokens=( $result )
command="sudo /home/pi/usbreset /dev/bus/usb/$busnum/$devnum"
eval $command

2 thoughts on “Raspberry Pi USB Device Reset

  1. Unfortunately, this script doesn’t work with my raspberry (raspbian). I had to change line 5 and 8, because the split of $result in tokens won’t work that way and cutting away the „:“ didn’t work either. So, here the new script (added a few echos for buxfixing). To get the name of the usb device try -lsusb. This script simply cuts the -lsusb return in the pieces to run the reset.

    result=`lsusb | grep „your usb device“`
    #echo $result
    IFS=‘ ‚ read -r -a tokens <<< "$result"
    #echo $busnum
    #echo $devnum
    command="sudo usbreset /dev/bus/usb/$busnum/$devnum"
    #echo $command
    eval $command

  2. Thanks for the heads up and your version. I’m also using Raspbian but the script highly depends on the „lsusb“ output (your version doesn’t work on my system). Your version above lacks a single quote at the end of line 5 and the leading comma brings up an error for me so here is a potential fix for that:

    < IFS=‘ ‚ read -r -a tokens <<< "$result"
    > IFS=`read -r -a tokens <<< "$result"`

Schreibe einen Kommentar zu backpenther Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.