Controlling USB devices
The Universal Serial Bus (USB) is used extensively by computers to provide additional peripherals and expansion through a common standard connection. We will use the Python library PyUSB to send custom commands to connected devices over USB.
The following example controls a USB toy missile launcher, which in turn allows it to be controlled by our Python control panel. We see that the same principle can be applied to other USB devices, such as a robotic arm, using similar techniques, and the controls can be activated using a sensor connected to the Raspberry Pi GPIO.
Getting ready
We will need to install PyUSB for Python 3 using pip-3.2
as follows:
sudo pip-3.2 install pyusb
You can test whether PyUSB has installed correctly by running the following:
python3 > import usb > help (usb) > exit()
This should allow you to view the package information if it was installed correctly.
How to do it...
We will create the following...