Skip to content

Instantly share code, notes, and snippets.

@mpkuse
Last active August 10, 2018 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpkuse/4c06d3066b2f0efe8c1eb9d25bb6db47 to your computer and use it in GitHub Desktop.
Save mpkuse/4c06d3066b2f0efe8c1eb9d25bb6db47 to your computer and use it in GitHub Desktop.
USB Devices Communication and Writing Custom Drivers

Tools and Utilities for USB-TTL Communication

On Linux, USB devices comeup as files under /dev/ttyUSB0 and so on. One can create custom USB devices (with little bit of hardware tinkering). These devices can be based on USB-TTL converters. These are available with USB-A, mini-USB, micro-USB. These devices are almost invariably uses FTDI chips. Can use the program FT_Prog to flash the ftdi chip to set your own custom device names. It is also possible to use libftdi for more hardcore stuff. Documentation is sparse though. Need to look at examples. For power users, one can build a custom board (PCB) with ftdi chips. There are several FTDI chips available which is able to carry out highspeed USB-3 communication.

These converters can be used with any microcontroller. If using Arduino based controller, check this out to write/read data to serial devices: https://www.arduino.cc/en/Tutorial/SoftwareSerialExample.

#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done
# Sample Output
# /dev/bsg/6:0:0:0 - VT_SSD_USB_3.0_000000000002-0:0
# /dev/sda - VT_SSD_USB_3.0_000000000002-0:0
# /dev/sda1 - VT_SSD_USB_3.0_000000000002-0:0
# /dev/sg0 - VT_SSD_USB_3.0_000000000002-0:0
# /dev/input/event2 - LiteON_HP_Basic_USB_Keyboard
# /dev/hidraw0 - LiteON_HP_Basic_USB_Keyboard
# /dev/input/event3 - PixArt_USB_Optical_Mouse
# /dev/input/mouse0 - PixArt_USB_Optical_Mouse
# /dev/hidraw1 - PixArt_USB_Optical_Mouse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment