Blackberry Trackball as USB Mouse
This demo uses a Sparkfun Blackberry Trackball to control the mouse cursor on a PC. The trackball is interfaced to the PC through the use of a mbed-m0 device. The mbed device is running firmware which takes advantage of the USBMouse C++ class provided by the latest mbed libraries, allowing the user to move the mouse cursor around on the screen and generate mouse clicks using the trackball. The LEDs beneath the trackball are used to change the colour of the trackball according to what the user is doing on the device (red for no motion, green when trackball is in motion, and blue when the trackball is being pressed down.)
The Blackberry trackball is a very ingenious design. There are four rollers arranged around the trackball (in the up, down, left, and right locations). When you rotate the ball towards the right, the ball actually shifts a bit to the right in the housing so that it can engage and rotate the right roller. Rotating the ball to the left would cause the ball to shift away from the right roller so that it would engage and rotate the left roller instead. These rollers are actually magnetic so that a hall effect sensor placed beneath them can detect when they rotate. The breakout board from Sparkfun provides 4 of these hall effect sensors (one placed beneath each roller) and the outputs from these sensors are connected to the mbed device so that it can count the amount of rotation in each of the 4 directions. The trackball can also travel down within its housing so that pressing it will cause a microswitch placed beneath it to be depressed. The fact that the ball is translucent also means that it can be illuminated with 4 LEDs of different colours (red, green, blue, and white) from below.
I wrote a BBTrackball library to interface with the device. Features of this library include:
- Uses InterruptIn on rising and falling edges of motion inputs (UP, DWN, LFT, RHT) to count trackball generated roller rotations in the background.
- Uses PwmOut to control the brightness of each LED (BLU, RED, GRN, WHT) based colour channel.
- Uses Ticker to sample the button every 100 usec in the background and includes code to filter out button bounce.
A structure used to represent the colour of the illumination for the trackball.
A structure in which the current state of the trackball is returned from the
|CBBTrackball (PinName BluePin, PinName RedPin, PinName GreenPin, PinName WhitePin, PinName UpPin, PinName DownPin, PinName LeftPin, PinName RightPin, PinName ButtonPin)|
object, binds it to the specified input/output pins, and initializes the required interrupt handling.
|void||GetState ( SState *pState)|
Gets current state of the trackball.
|void||SetColour (const SColour *pColour)|
Sets the colour of the trackball illumination.
The raw output from this trackball object is too fine for use as a mouse on the PC. To solve this problem I have added some classes in the acceleration.h/acceleration.cpp source files of the sample project to provide some gain to the trackball motion as the user rotates the trackball more quickly.
Sparkfun Blackberry Trackball Breakout
|BLU||pin 20 - p20|
|RED||pin 25 - p25|
|GRN||pin 26 - p26|
|WHT||pin 10 - p10|
|UP||pin 5 - p5|
|DWN||pin 6 - p6|
|LFT||pin 7 - p7|
|RHT||pin 8 - p8|
|BTN||pin 9 - p9|
|GND||pin 1 - GND|
|VCC||pin 40 - VOUT|
This program was created on a mbed-M0 device which has support for PwmOut on different pins than the other mbed devices. If you are porting this program to one of the other mbed devices then you will need to move the LED signals (BLU, RED, GRN, WHT) to pins which support PwmOut (p21 - p26).
In the photo of my breadboard setup, there is a green wire on the left side of the breakout board. This wire passes underneath the board and through the two mounting holes. It is just there to shim up that side of the board so that it matches the pin header on the other side. It provides no electrical connection.
Romilly Cocking has a notebook page which shows how to connect a Sparkfun USB breakout board to the mbed.
You don't need to connect the VCC pin of this breakout board if you are going to get power from the other USB cable over which the device is programmed.
- Connect a USB cable to the mbed as usual so that it can be programmed.
- Import my BBTrackball_Sample into your mbed compiler workspace.
- Build the sample for the LPC11U24 target type.
- Deploy resulting binary to your mbed-m0 as usual.
- Connect another USB cable between the USB breakout board discussed above and your PC.
- Press the reset button on the mbed device.
- The mbed device should be enumerated by the PC as a HID mouse.
- Moving the trackball around should cause the mouse cursor to move on the screen.
- Pushing down on the trackball should send a left button click.
Please log in to post comments.