Skip to content

Instantly share code, notes, and snippets.

@smittytone
Created February 9, 2022 09:13
Show Gist options
  • Save smittytone/a8ebda945a151b339b3258552bff7361 to your computer and use it in GitHub Desktop.
Save smittytone/a8ebda945a151b339b3258552bff7361 to your computer and use it in GitHub Desktop.
Python script to detect whether an FT232H or MCP2221 USB-to-serial adaptor is connected, for Adafruit Blinka
#!/usr/bin/env python3
# Requirements:
# pip install pyftdi
# pip install hid
# brew install hidapi
from os import environ
from pyftdi.usbtools import UsbTools
count = len(UsbTools.find_all([(0x0403, 0x6014)]))
if count != 0:
print("Setting BLINKA_FT232H")
environ.set("BLINKA_FT232H")
exit()
from hid import enumerate
for dev in enumerate():
if dev["vendor_id"] == 0x04D8 and dev["product_id"] == 0x00DD:
print("Setting BLINKA_MCP2221")
environ.set("BLINKA_MCP2221")
exit()
print("No device variable set")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment