UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 2

UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 2

3d airmouse

Click here to read Part 1 of this article >

3d airmouse

 

We left off last time in UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 1 having finished the hardware portion of the project.  The transmitter portion involved assembling a shield with the AirMouse’s buttons and the interface between the Uno’s GPIO pins and the RF module.  We chose to use the ROHM SensorShield with the accelerometer module because of its convenience in prototyping and DIY projects such as this.  As you’ll see in this tutorial, the ROHM shield packages the I2C communications between the Arduino and its peripherals nicely so that with some simple code, the user can receive accelerometer data without having to write any of the underlying I2C functions to send and receive data from device addresses.  The receiver portion of the project involved assembling similar breakout board for a Teensy microcontroller to interface it with an RF module as well.  

The code we’ll introduce and describe in this tutorial will help you complete the project by connecting the two modules to each other.  We’ll show you our basic code to send data between the two modules and process the accelerometer data to move a cursor on the computer monitor, and hopefully you’ll be able to come up with some cool additions and improvements of your own!

 

Quick AirMouse Overview

We’ve all used computer mice before, but they are limited to only working on top of flat surfaces like tables.  We’ve made 3D AirMouse, a computer mouse that functions in 3D space.  The user can tilt the mouse to move the cursor on the screen, allowing for a wide range of customizable motions. We’ve already covered the basics of building the AirMouse in Part 1. There are two main pieces that make up the AirMouse: the handheld mouse transmitter, and the receiver connected to the user’s computer.  The transmitter gathers information about the mouse’s orientation and the states of its buttons, while the receiver translates this information to perform corresponding actions on the computer screen. The AirMouse was built using Arduino Uno and nRF24L01 RF  modules, combined with an accelerometer on the ROHM sensor shield.

 

Hardware from Part 1:

Transmitter:

  • 1 x Arduino Uno microcontroller
  • 1 x ROHM Sensor Evaluation Kit
  • 1 x ROHM Accelerometer (KX022-1020)
  • 1 x nRF24L01+ RF module
  • Female header pins
  • Slide switch
  • 1 x Solderable perfboard large enough to fit the microcontroller and accompanying electronics
  • 2 x Push-buttons
  • 1 x 1s LiPo Battery
  • 1 x 1kΩ resistor
  • 1 x 3.3kΩ resistor

Receiver:

  • 1 x Teensy 3.2 microcontroller
  • 1 x NRF24L01+ RF module
  • Female header pins
  • 1 x Solderable perfboard large enough to fit the microcontroller and accompanying electronics
  • 1 x Red, Yellow, and Green LEDs
  • 1 x 150Ω resistor

Once you have the hardware wired up as specified in Part 1, you can use the following program to run the transmitter and receiver.

 

Transmitter:

Receiver:

 

The process for uploading code to a Teensy is slightly different from the process for uploading to an Arduino Uno.  For the Uno, you can simply follow the usual compile and upload steps:

  1. Select Tools > Board > Arduino/Genuino Uno
  2. Select the Port
  3. Click the “Upload” button in the Arduino IDE

 

For the Teensy, follow these steps to upload the receiver code:

  1. Select Tools > Board > Teensy 3.2 / 3.1
  2. Select Tools > USB Type > Keyboard + Mouse + Joystick (we’ll be using the Teensy as a USB device)
  3. Click the “Upload” button in the Arduino IDE

 

For the purposes of this tutorial, we won’t go into too much detail about the different communication protocols involved and how communication with the RF module works at the software level.  You can check out our communications protocols and nRF24L01+ module tutorials for more information on these topics!  Instead, we’ll briefly explain the workings of the main control loop in the software.

In the AirMouse, the transmitter collects data, but most of the data processing is handled by the receiver module.  We designed the system this way so that the Arduino, a weaker processor than the Teensy, could spend fewer resources on decision-making and computations and instead run faster cycles just collecting data.  With this implementation, the only data being sent between the two devices is the raw accelerometer and button data.  The Teensy receives this raw data and processes it to perform actions on the computer screen.

To detect the orientation of the AirMouse, the system must translate the raw accelerometer data.  To accomplish this, one must first identify the “zero-values” of each of the coordinates.  This value is defined as the accelerometer’s output for each axis when the AirMouse is held flat (parallel to the ground).  With knowledge of the zero-values, the software is then able to translate accelerometer data into a direction and amount to move the cursor on-screen by analyzing the acceleration (due to gravity) in each axis and comparing it to the zero-value for that axis.

Now we’ll take a look at the interaction between the receiver module and the computer.  The Teensy is specified to act as a USB Human Interface Device (specifically, a USB Mouse).  After translating orientation data, the software makes calculations on what speed and direction to move the cursor.  In addition, the software also interprets the left-button clicks as left-clicks and the right-button clicks as right-clicks, calling appropriate methods to show left or right-clicks on the computer screen.  Here’s the cool part: you can modify or add to the mouse’s on-screen functionality fully through software!  Currently, the abilities and performance of the mouse is rudimentary, but you can easily add features such as scrolling, moving the cursor to a certain point on the screen, etc. with some simple additions to the software!  (Here’s the Teensy USB Mouse guide for reference)  Here are some cool hardware and software ideas you can implement:

  • Have different patterns of button clicks act as different controls (for example, double-click right button to close the window)
  • Add scrolling! (change to a “scroll mode” when both buttons are clicked)
  • Add other buttons to the mouse to do things like scrolling or to get more button patterns for different functions

We hope you enjoy building the AirMouse, and definitely look forward to modifications and improvements on both its design and its functionality!    

The original version of AirMouse was developed by Rahul Iyer, Aaron and Andrew Wilhelm, as part of UCLA IEEE’s Advanced Projects program. Find out more at http://ieeebruins.org

Device Plus is looking to collaborate with active student engineering organizations and labs. For more information about our Hardware Sponsorship Program, please contact us at info@deviceplus.com

 

Click here to read Part 1 of this article >