Introduction: Arduino Esplora Mouse

The Arduino Esplora is one of the newest Arduino Boards. It is shaped like a game controller, and has built in inputs and outputs. You can read more about it here. I won one on Adafruit's Ask an Engineer, and I decided to build a mouse

Step 1: Get the Code

For some reason Instructables wont let me upload the code today. So you can get it here. UPDATE: Link is updated
Here is how the code works:


Esplora.writeRGB(0, 0, 10);                  
int start = Esplora.readButton(SWITCH_3);    
while(start == HIGH) {                       
  start = Esplora.readButton(SWITCH_3);
}

The Esplora turns sets the light blue to signal it is ready to go. It then sets an infinite loop until the top button is pressed.

JoyX = Esplora.readJoystickX();
JoyY = Esplora.readJoystickY();
Esplora.writeRGB(10, 0, 0);


The Esplora then sets the drift on the X and Y axis on the Joystick and sets the led to red to signal that is done.

int xValue = Esplora.readJoystickX();
int yValue = Esplora.readJoystickY();       
xValue = xValue - JoyX;                     
yValue = yValue - JoyY;                     

The Esplora reads the joystick values and removes the drift.

int JoyButton = Esplora.readJoystickButton();
int button1 = Esplora.readButton(SWITCH_1);  
int button2 = Esplora.readButton(SWITCH_2);  
int button3 = Esplora.readButton(SWITCH_3);  
int button4 = Esplora.readButton(SWITCH_4);  
int slide = Esplora.readSlider();            

The Esplora then reads the buttons

int mousespeed = map(slide, 0, 1023, 10, 0);
int mouseX = map( xValue,-512, 512, mousespeed, -mousespeed); 
int mouseY = map( yValue,-512, 512, -mousespeed, mousespeed); 

The Esplora now maps out the max speed of the mouse, and maps out the value of the mouse movement

if(button3 == LOW){                       
    if(activate == 1) activate = 0;
    else activate = 1;
    delay(500);
  }

If the top button is pressed, the Esplora swaps the value of the variable

if(activate == 1){
If the previously set variable is equal to one, the Esplora runs the loop

Esplora.writeRGB(0 , 10, 0 );                
Mouse.begin();                               

The light is set to green and the Mouse is run

if(JoyButton == LOW || button2 == LOW) Mouse.press(MOUSE_LEFT);
    else Mouse.release(MOUSE_LEFT);


if(button1 == LOW) Mouse.press(MOUSE_MIDDLE);               
else Mouse.release(MOUSE_MIDDLE);

if(button4 == LOW)  Mouse.press(MOUSE_RIGHT);  
else Mouse.release(MOUSE_RIGHT);

Mouse.move(mouseX, mouseY, 0);

The Esplora presses and releases the buttons and moves the mouse using the previously set variables

else {
    Mouse.end();
    Esplora.writeRGB(255, 0, 0 ); 
  }

If the mouse is disabled, the Mouse connection is closed, and the led is set to red.

Step 2: How to Use the Mouse

Using the mouse is simple. I uploaded some pictures I modified from the Arduino Guides to explain how to use the mouse. So when you plug in the mouse, the light will turn blue. This means that it is waiting to calibrate the joystick and get rid of any drift. don't move the joystick and press the top button once. The light will turn red or green depending on how long you hold the button. A red light means the mouse is disabled. To enable the mouse, press the top button, and the light will turn green. When the mouse is enabled, the Joystick moves the mouse, the slider controls the speed of the mouse, and the bottom buttons match up with the buttons on the mouse.

Comments

author
rminkoff (author)2017-03-29

Hey just wanted to let you know that the github link isn't working. Any chance you could update it?

author
ajadam3105 (author)2015-07-12

I tried this and just got this list of errors:

EPQ_Mouse.ino: In function 'void loop()':

EPQ_Mouse:67: error: 'Mouse' only supported on the Arduino LeonardoEPQ_Mouse:69: error: 'MOUSE_LEFT' was not declared in this scope

EPQ_Mouse:70: error: 'MOUSE_LEFT' was not declared in this scope

EPQ_Mouse:73: error: 'MOUSE_MIDDLE' was not declared in this scope

EPQ_Mouse:74: error: 'MOUSE_MIDDLE' was not declared in this scope

EPQ_Mouse:76: error: 'MOUSE_RIGHT' was not declared in this scope

EPQ_Mouse:77: error: 'MOUSE_RIGHT' was not declared in this scope

EPQ_Mouse:84: error: 'Mouse' only supported on the Arduino Leonardo'Mouse' only supported on the Arduino Leonard

author
KNEXnCoding (author)ajadam31052016-05-23

Did you add

#include <Esplora.h>

in the beginning of your code?

author
sculptur made it! (author)2015-04-12

This code is awesome; excellent work man!

Thanks, Sculptr

IMG_7930.JPG
author
ualbuquerque (author)2014-09-20

cool

author
nerd7473 (author)2013-06-07

cool

author
digipup1 (author)2013-05-27

Very cool! Can you include the code as a whole?

author
andrea biffi (author)2013-05-22

this is REALLY useful! thanks!
Is it connected through USB? Does it work alone in Windows, with Arduino program closed?
That new Arduino board is a great improvement for diy gadgets!

author

Hi! Thanks for the comment, The Esplora is based off of the same chip as the Leonardo, so it has native USB. The Mouse library lets the Arduino board pretend to be a HID Mouse, so it should work with any modern computer with a USB port. You don't even need the Arduino IDE installed. To setup the Esplora on a Mac, see this page.

author

great! thanks for the explanation! :-)

About This Instructable

6,740views

28favorites

License:

More by Michael_Bell:Arduino Esplora MouseOur DroneSuperb Lemon Loaf Recipie
Add instructable to: