python :Read from a USB HID device
12,478
By default evdev.list_devices() look only to /dev/input
And you need permissions to work with your device. You can add your user to group which own your device (see $ ls -l /dev/hidraw0 )
Then you need to listen your device in loop
#!/usr/bin/python3
import evdev
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
print(device.fn, device.name, device.phys)
device = evdev.InputDevice("/dev/input/event4")
print(device)
for event in device.read_loop():
print(event)
Author by
Safwen Daghsen
Digital nomad & Full-stack Javascript Developer
Updated on June 28, 2022Comments
-
Safwen Daghsen almost 2 years
I have a USB RFID device that appears on /dev/hidraw for my serial devices they appear on /dev/ttyUSB* i used pyserial and it works like charm but for this one i couldn't read from it using
cat /dev/hidraw0
need root privileges plus i need to read one line and not keep on listeningI used evdev library but my device doesn't appear at all :
import evdev devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()] for device in devices: print(device.fn, device.name, device.phys)
So is there a proper way to read from the device programmatically ?
-
Kiran almost 7 yearsI have connected my Beurere BC 58 to raspberry pi 3 and saw the device is detected as /dev/hidraw3. But unfortunately I'm unable to locate the input events in the "dev". I have list of 3 events /dev/input/event0, event1, event2. In which event 1 and 2 are displayed as keyboards and one mouse. But my Blood pressure monitors is not part of any event. Is there any other of locating it?