Raspberry Pi USB Input Device Data Monitor (Part 2)

USB Mouse/Keyboard Data Monitoring Using Raspberry Pi


In the previous post here, I was using python evdev module to capture the USB data.
This time I used python pyusb module since I found a great post by Gourmet Web Design

Setup
Install pip:
$ sudo apt-get update$ sudo apt-get install python-pip
Install puusb module:
$ sudo pip install pyusb
Check input events:
$ ls /dev/input
If you do not know which event is mouse or keyboard, follow this.
Install input-utils:
$ sudo apt-get install input-utils
$ lsinput

If you want to use pyusb to check the input devices, you can refer to this post by Gourmet Web Design



                  



Python Code
This is the python example code.

Example:
import usb.coreimport usb.util
dev = usb.core.find(idVendor=0x093a, idProduct=0x2510)
# was it found?if dev is None:    print usb.core.find()    raise ValueError('Device not found')
# first endpointinterface = 0endpoint = dev[0][(0,0)][0]print(endpoint)
# tell the kernel to detachdev.detach_kernel_driver(interface)
while True:    try:        data = dev.read(endpoint.bEndpointAddress,endpoint.wMaxPacketSize)        print data    except usb.core.USBError as e:        data = None        if e.args == ('Operation timed out',):            continue
# release the deviceusb.util.release_interface(dev, interface)# reattach the device to the OS kerneldev.attach_kernel_driver(interface)

Crate a python script file as below and copy&paste the above code.
nano test.py
Run the python script.
python test.py
Press any buttons on the keyboard or mouse and you will see the outputs in the terminal.
Done!




[AKM Chip Booster] Audio ADC AK5704 PCB Design

Designing a PCB prototype with AK5704 is not so difficult and I show an example with my design. People who are not familiar with AK5704,...