# CircuitPython USB VID/PID Reporter

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/140/402/medium800/feather_edited_P1480347.jpg?1760455646 )

Each USB device has a vendor ID (VID) and product ID (PID). These codes identify the manufacturer and product. The only problem is that it can be really annoying to find the VID and PID for a device. You usually have to go through a forest of clicks and menus on your operating system. With this project, you'll use a Feather RP2040 USB Host running CircuitPython that shows the VID and PID on a mounted device for a simple plug and play way to learn the mysteries of your devices.

You can press any of the three buttons on the FeatherWing to toggle what information from the mounted USB device is shown. In one group is the VID and PID and in the other is the Manufacturer and Product name.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/140/412/medium640thumb/feather_logiToggle.jpg?1760458717)

## Parts
### Adafruit Feather RP2040 with USB Type A Host

[Adafruit Feather RP2040 with USB Type A Host](https://www.adafruit.com/product/5723)
You're probably really used to microcontroller boards with USB, but what about a dev board with two? Two is more than one, so that makes it twice as good! And the&nbsp; **Adafruit Feather RP2040 with USB Host** is **&nbsp;** definitely double-the-fun of our other Feather...

In Stock
[Buy Now](https://www.adafruit.com/product/5723)
[Related Guides to the Product](https://learn.adafruit.com/products/5723/guides)
![Angled shot of black rectangular microcontroller with USB C and USB A connectors at both ends.](https://cdn-shop.adafruit.com/640x480/5723-00.jpg)

### Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather](https://www.adafruit.com/product/4650)
A Feather board without ambition is a Feather board without FeatherWings! This is the&nbsp; **FeatherWing 128x64 OLED** : it adds a gorgeous 128x64 monochrome OLED plus 3 user buttons to&nbsp;_any_&nbsp;Feather main board. Using our&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4650)
[Related Guides to the Product](https://learn.adafruit.com/products/4650/guides)
![Video of a Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather - STEMMA QT / Qwiic connected to a temp and humidity sensor. Display reads "Adafruit" and various Temp and Humidity measures.  ](https://cdn-shop.adafruit.com/product-videos/640x480/4650-08.jpg)

### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
![Double prototyping feather wing PCB with socket headers installed](https://cdn-shop.adafruit.com/640x480/2890-01.jpg)

### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

# CircuitPython USB VID/PID Reporter

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_rp2040_usb_host/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/120/454/medium800/hacks_resetBoot.jpg?1682366749)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/101/659/original/flash_nuke.uf2?1618945856)
# CircuitPython USB VID/PID Reporter

## Code the Reporter

Once you've finished setting up your Feather RP2040 USB Host with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **Download Project Bundle** button in the window below. It will download to your computer as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_USB_VID_PID_Reporter/code.py

## Upload the Code and Libraries to the Feather RP2040 USB Host

After downloading the Project Bundle, plug your Feather RP2040 USB Host into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called **CIRCUITPY**. Unzip the folder and copy the following items to the Feather RP2040 USB Host's **CIRCUITPY** drive.

- **lib** folder
- **code.py**

Your Feather RP2040 USB Host **CIRCUITPY** drive should look like this after copying the **lib** folder and&nbsp; **code.py** file:

![CIRCUITPY drive](https://adafruit.github.io/Adafruit_Learning_System_Guides/CircuitPython_USB_VID_PID_Reporter.png )

## How the Code Works

The code begins by initializing the OLED display over I2C.

```python
displayio.release_displays()

# init display
i2c = board.I2C()
display_bus = I2CDisplayBus(i2c, device_address=0x3C)
display = adafruit_displayio_sh1107.SH1107(display_bus, width=128, height=64)
```

Two display groups are used. The `main` group has the title text and VID/PID text. The `extra_info` group has the manufacturer text and product name text. Each of these text objects are initialized as `Label`s.

```python
# text groups
main = displayio.Group()
extra_info = displayio.Group()
groups = [main, extra_info]
display.root_group = main

# text objects for title, VID and PID
title_text = label.Label(terminalio.FONT, text="USB VID/PID Reporter", color=0xFFFFFF, x=5, y=15)
main.append(title_text)
vid_text = label.Label(terminalio.FONT, text="VID:", color=0xFFFFFF, x=5, y=35)
main.append(vid_text)
pid_text = label.Label(terminalio.FONT, text="PID:", color=0xFFFFFF, x=5, y=50)
main.append(pid_text)

# text objects for manufacturer and product info
# added to secondary group
man_header = label.Label(terminalio.FONT, text="Manufacturer:", color=0xFFFFFF, x=5, y=10)
extra_info.append(man_header)
man_text = label.Label(terminalio.FONT, text=" ", color=0xFFFFFF, x=5, y=25)
extra_info.append(man_text)
prod_header = label.Label(terminalio.FONT, text="Product:", color=0xFFFFFF, x=5, y=40)
extra_info.append(prod_header)
prod_text = label.Label(terminalio.FONT, text=" ", color=0xFFFFFF, x=5, y=55)
extra_info.append(prod_text)
```

### Keypad

The three buttons on the OLED FeatherWing are passed to a `keypad` object.

```python
# init A, B and C buttons on FeatherWing as keypad keys
keys = keypad.Keys((board.D5,board.D6,board.D9,), value_when_pressed=False, pull=True)
```

### Variables

There are a few variables that are used in the loop. `last_pid` and `last_vid` hold the previously read VID and PID info. `usb_dev` checks if a USB device is plugged into the Feather. `first_run` lets the loop know that its the first time the loop is running. `group_index` is the display group into that lets you toggle between the `main` group or the `extra_info` group.

```python
# variables
last_pid = 0x0000 # store last PID
last_vid = 0x0000 # store last VID
usb_dev = False # is there a USB device?
first_run = True # first run through loop
group_index = 0 # display group index
```

### The Loop

All three of the FeatherWing buttons are monitored for keypad events. If any of the three buttons are pressed, then the display group is toggled.

```python
while True:
    event = keys.events.get()
    if event:
        # if any button is pressed, toggle graphics group
        if event.pressed:
            group_index = (group_index + 1) % 2
            display.root_group = groups[group_index]
```

### Find the Devices

`devices` holds a list of connected and mounted USB devices to the USB host peripheral. If no device is found, then the OLED will only show the project title text and clear any previous USB info that was being displayed.

```python
# find connected devices
    devices = list(usb.core.find(find_all=True))
    # if no device, reset states and text objects
    if not devices and usb_dev or first_run:
        print("no device")
        pid_text.text = "PID:"
        vid_text.text = "VID:"
        man_text.text = " "
        prod_text.text = " "
        usb_dev = False
        first_run = False
```

If there is a connected USB device, the text objects are updated to show the VID, PID, manufacturer and product information. Sometimes USB devices do not have manufacturer or product information, so there is error handling to prevent exceptions if that information isn't present to update the text objects. Additionally, if there are any `USBError` exceptions, the loop will continue.

```python
else:
        if not usb_dev:
            first_run = False
            for device in devices:
                try:
                    # if its the same device, don't scan again
                    if (last_pid == hex(device.idProduct) and
                        last_vid == hex(device.idVendor) and usb_dev):
                        break
                    # new device!
                    usb_dev = True
                    # get PID, VID, manufacturer and product
                    # update text elements
                    print("pid", hex(device.idProduct))
                    last_pid = hex(device.idProduct)
                    pid_text.text = f"PID: {last_pid}"
                    print("vid", hex(device.idVendor))
                    last_vid = hex(device.idVendor)
                    vid_text.text = f"VID: {last_vid}"
                    print("man", device.manufacturer)
                    # only update manufacturer and product if info is known
                    if device.manufacturer is not None:
                        man_text.text = device.manufacturer
                    print("product", device.product)
                    if device.product is not None:
                        prod_text.text = device.product
                    print()
                # if there's any error reading info from a USB device, continue
                except usb.core.USBError:
                    print("got an error, continuing..")
                    continue
```

# CircuitPython USB VID/PID Reporter

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/140/394/medium800/feather_edited_P1480313.jpg?1760453166 )

For this project, you'll just need to solder some headers and then plug the Feather and FeatherWing into the FeatherWing Doubler. If you're new to soldering, check out the [How to Solder Headers Learn Guide](https://learn.adafruit.com/how-to-solder-headers).

### How To Solder Headers - Overview

[How To Solder Headers](https://learn.adafruit.com/how-to-solder-headers)
[Overview](https://learn.adafruit.com/how-to-solder-headers/overview)
Solder socket headers to the FeatherWing Doubler.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/395/medium640/feather_edited_P1480317.jpg?1760453188)

Solder plug headers to the Feather RP2040 USB Host and the OLED FeatherWing.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/396/medium640/feather_edited_P1480320.jpg?1760453206)

Plug the Feather and FeatherWing into the Doubler.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/397/medium640/feather_edited_P1480322.jpg?1760453231)

# CircuitPython USB VID/PID Reporter

## Use

![](https://cdn-learn.adafruit.com/assets/assets/000/140/421/medium800thumb/feather_demoHero.jpg?1760466664 )

Power up the Feather with a USB C cable plugged into a USB power source. On power-up, you'll see the display show the text areas for the device information.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/417/medium640thumb/feather_toggleNoDevice.jpg?1760466244)

Insert a USB device into the Feather RP2040 USB Host port. You'll see the connected device's VID and PID show up on the OLED.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/418/medium640/feather_edited_P1480340.jpg?1760466263)

Press any of the three buttons on the left side of the OLED FeatherWing to toggle the display to show the manufacturer and product name information. Press any of the buttons again to go back to the VID and PID display.

![](https://cdn-learn.adafruit.com/assets/assets/000/140/419/medium640/feather_edited_P1480339.jpg?1760466307)


## Featured Products

### Adafruit Feather RP2040 with USB Type A Host

[Adafruit Feather RP2040 with USB Type A Host](https://www.adafruit.com/product/5723)
You're probably really used to microcontroller boards with USB, but what about a dev board with two? Two is more than one, so that makes it twice as good! And the&nbsp; **Adafruit Feather RP2040 with USB Host** is **&nbsp;** definitely double-the-fun of our other Feather...

In Stock
[Buy Now](https://www.adafruit.com/product/5723)
[Related Guides to the Product](https://learn.adafruit.com/products/5723/guides)
### Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather](https://www.adafruit.com/product/4650)
A Feather board without ambition is a Feather board without FeatherWings! This is the&nbsp; **FeatherWing 128x64 OLED** : it adds a gorgeous 128x64 monochrome OLED plus 3 user buttons to&nbsp;_any_&nbsp;Feather main board. Using our&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4650)
[Related Guides to the Product](https://learn.adafruit.com/products/4650/guides)
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)

## Related Guides

- [Adafruit 128x64 OLED FeatherWing ](https://learn.adafruit.com/adafruit-128x64-oled-featherwing.md)
- [Adafruit Feather RP2040 with USB Type A Host](https://learn.adafruit.com/adafruit-feather-rp2040-with-usb-type-a-host.md)
- [Color Sensing Music Player](https://learn.adafruit.com/color-sensing-music-player.md)
- [Homefruit FeatherWing Tester](https://learn.adafruit.com/homefruit-featherwing-tester.md)
- [Daily Cheer Automaton](https://learn.adafruit.com/daily-cheer-automaton.md)
- [Desk Calculator with CircuitPython](https://learn.adafruit.com/desk-calculator-with-circuitpython.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [MAC Address Finder](https://learn.adafruit.com/mac-address-finder.md)
- [Walkmp3rson: Personal MP3 'Tape' Player](https://learn.adafruit.com/walkmp3rson-personal-mp3-tape-player.md)
- [Discord and Slack Connected Smart Plant with Adafruit IO Actions](https://learn.adafruit.com/discord-and-slack-connected-smart-plant-with-adafruit-io-triggers.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
- [CircuitPython Text Editor On The Go](https://learn.adafruit.com/circuitpython-text-editor-on-the-go.md)
- [Air Quality Sensor 3D Printed Enclosure](https://learn.adafruit.com/air-quality-sensor-silo-house.md)
- [STEMMA Lego base plates](https://learn.adafruit.com/stemma-lego-base-plates.md)
- [Feather Guitar Hero Adapter](https://learn.adafruit.com/feather-guitar-hero-adapter.md)
- [HID Reporter](https://learn.adafruit.com/hid-reporter.md)
