Monitoring and Identifying USB Devices on Your Raspberry Pi
Learn how to check connected USB devices in Raspberry Pi using the command line interface, lsusb command, udevadm command, and Python libraries. …
Updated August 19, 2023
Learn how to check connected USB devices in Raspberry Pi using the command line interface, lsusb command, udevadm command, and Python libraries.
Using the Command Line Interface
The most basic method for checking connected USB devices is by using the lsusb
command in the terminal. This command lists all detected USB devices and their corresponding information, such as vendor ID (VID), product ID (PID), serial number, manufacturer, and device name.
To check connected USB devices using lsusb
, follow these steps:
- Open a terminal window by clicking on the Terminal icon in the menu bar or by pressing Ctrl+Alt+T.
- Type
lsusb
and press Enter to run the command. The output will display information about all connected USB devices.
Example output:
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
In this example, we can see three USB devices connected to the Raspberry Pi: an Ethernet adapter and two root hubs. Each line represents a device, with Bus number, Device number, Vendor ID (VID), Product ID (PID), and device name or manufacturer.
Using the lsusb Command
The lsusb
command provides detailed information about connected USB devices but lacks some advanced features for identifying specific devices or monitoring device events. To overcome these limitations, you can use the udevadm
command.
Using the udevadm Command
The udevadm
command is a more powerful tool for managing and monitoring USB devices on your Raspberry Pi. It allows you to monitor device events (plug/unplug, attach/detach) and identify specific devices using their properties like VID, PID, or serial number.
To check connected USB devices using udevadm
, follow these steps:
- Open a terminal window by clicking on the Terminal icon in the menu bar or by pressing Ctrl+Alt+T.
- Type
udevadm info -a -p $(udevadm info -q path -n /dev/sda)
and press Enter to run the command. Replace/dev/sda
with the device you want to check (e.g.,/dev/sdb
,/dev/sdc
). - The output will display detailed information about the specified USB device, including properties like VID, PID, serial number, and manufacturer name.
Example output:
looking at device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.4':
KERNEL=="1-1.4"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{authorized}=="1"
ATTR{avoid_reset_quirk}=="0"
ATTR{bConfigurationValue}=="1"
ATTR{bDeviceClass}=="00"
ATTR{bDeviceProtocol}=="00"
ATTR{bDeviceSubClass}=="00"
ATTR{bMaxPacketSize0}=="64"
ATTR{bMaxPower}=="500mA"
ATTR{bNumConfigurations}=="1"
ATTR{bNumInterfaces}==" 1"
ATTR{bcdDevice}=="9d3c"
ATTR{bmAttributes}=="a0"
ATTR{busnum}=="1"
ATTR{configuration}==""
ATTR{devnum}=="2"
ATTR{devpath}=="1.4"
ATTR{idProduct}=="ec00"
ATTR{idVendor}=="0424"
ATTR{ltm_capable}=="no"
ATTR{manufacturer}=="Standard Microsystems Corp."
ATTR{maxchild}=="0"
ATTR{product}=="SMSC9512/9514 Fast Ethernet Adapter"
ATTR{quirks}=="0x0"
ATTR{removable}=="unknown"
ATTR{speed}=="480"
ATTR{urbnum}=="36"
ATTR{version}==" 2.00"
In this example, we can see detailed information about an SMSC9512/9514 Fast Ethernet Adapter connected to the Raspberry Pi. We can use this command to monitor specific devices or identify them by their properties.
Using Python Libraries like PyUSB and python-libusb1
Python libraries like PyUSB and python-libusb1 provide a higher level of abstraction for managing USB devices on your Raspberry Pi. These libraries allow you to interact with USB devices programmatically, making it easier to build applications that rely on USB communication.
To check connected USB devices using Python libraries, follow these steps:
- Install the required library. For PyUSB, run
pip install pyusb
or for python-libusb1, runpip install libusb1
. - Create a new Python script (e.g.,
check_usb.py
) and import the necessary libraries:import usb.core import usb.util
- Iterate through all connected USB devices and print their information:
for device in usb.core.find(find_all=True): print("Device ID: {:04x}:{:04x}".format(device.idVendor, device.idProduct)) print("Manufacturer: {}".format(usb.util.get_string(device, device.iManufacturer))) print("Product: {}".format(usb.util.get_string(device, device.iProduct))) print("Serial Number: {}".format(usb.util.get_string(device, device.iSerialNumber)))
- Run the script by typing
python check_usb.py
in the terminal and press Enter. The output will display information about all connected USB devices, including VID, PID, manufacturer name, and serial number.
Example output:
Device ID: 0424:ec00
Manufacturer: Standard Microsystems Corp.
Product: SMSC9512/9514 Fast Ethernet Adapter
Serial Number: None
In this example, we can see information about the same SMSC9512/9514 Fast Ethernet Adapter as before but using a Python script. This method allows you to build more complex applications that interact with USB devices in your Raspberry Pi projects.
By following these methods, you can easily check connected USB devices in your Raspberry Pi and identify them based on their properties or monitor device events. Choose the one that best fits your needs and start building awesome projects!