Blackberry Trackball as USB Mouse

Import programBBTrackball_Sample

Use a Sparkfun Blackberry Trackball Breakout Board as a mouse.

Import libraryBBTrackball

Class to interface with Sparkfun's Blackberry Trackball Breakout Board.

Overview

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.

BBTrackball Library

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.

Import library

Data Structures

struct   SColour
  A structure used to represent the colour of the illumination for the trackball. More...
struct   SState
  A structure in which the current state of the trackball is returned from the GetState() method. More...

Public Member Functions

  CBBTrackball (PinName BluePin, PinName RedPin, PinName GreenPin, PinName WhitePin, PinName UpPin, PinName DownPin, PinName LeftPin, PinName RightPin, PinName ButtonPin)
  Create a CBBTrackball 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.

Wiring

Sparkfun Blackberry Trackball Breakout

Trackball Breakoutmbed
BLUpin 20 - p20
REDpin 25 - p25
GRNpin 26 - p26
WHTpin 10 - p10
UPpin 5 - p5
DWNpin 6 - p6
LFTpin 7 - p7
RHTpin 8 - p8
BTNpin 9 - p9
GNDpin 1 - GND
VCCpin 40 - VOUT

Information

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).

Information

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.

USB Breakout

/media/uploads/romilly/_scaled_usb-mini-breakout.jpg

Romilly Cocking has a notebook page which shows how to connect a Sparkfun USB breakout board to the mbed.

Warning

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.

Running Demo

  • 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.