Mouse rumble mod

My first teensy experience was pretty unsuccessful. I failed miserably at my first project with a microcontroller. So, I’m aiming for something a little bit easier.

You know the light underneath the mouse? It powers down and when there is action, it suddenly lights up again. What if, every time it lights up, the mouse rumbles? That would be pretty cool. This is my adventure so far.

So, I took apart my el’cheapo mouse and discovered the LED gets ~1.6v when idle and ~1.9v when fully powered. The ADC on the Teensy should pick it up easily.

So, it’s time to solder. Solder two wires to the legs of the LED and connect them to the Teensy. Unfortunately, I stupidly forgot to disconnect the mouse from the computer before soldering and busted the LED 😦 so disconnect before soldering.

Also, solder a wire to the 5v and GND rail and connect it to a Mini-USB plug to act as a power supply to the Teensy.

Rip a little vibrator thingy off an old mobile phone and solder it to the Teensy as well.

Edit: Okay, it wasn’t as successful as I hoped it would be. I spent the whole of yesterday’s afternoon wondering why the ADC on the Teensy wasn’t picking anything up. It turned out that it was current that was varying, not the voltage, which meant the Teensy couldn’t pick it up.

So, I spent the afternoon and today’s morning rolling my own shunt resistor and even opto-isolator. No dice. I’m just too noob at physics.

After a bit, I decided to scrap the original plan and go for rumble on mouse click.

If you haven’t found a source of power yet, wire up a Mini-USB plug that steals power from the mouse.

For this, you’ll need to intercept the signals from the clicky button thing. The easiest way is to cut off and reroute the point on the circuit board to the Teensy. Here’s a picture

Then connect a pin from the Teensy to where the path ends on the +5v signal line. Usually, just follow the pin that isn’t ground to the mouse IC. In the picture, it’s yellow though it’s covered. Connect the other pin (white in this picture) to GND on the Teensy. And connect the middle pin to a pin on the Teensy (red).

The logic is that a 5v signal is given to the IC when the circuit completes (i.e a click). We are simply checking the state of the push button and sending the signal to the mouse as appropriate. Since the Teensy and the mouse share the same ground, it will work fine.

Hook up the vibrator to Pin 3 of the teensy.

Here’s a crappy schematic.

Once everything is wired up, it’s time to program the AVR. Download Arduino and the Teensyduino add-on. Write up your own software. I whacked a simple one up in 5 minutes.

/*Copyright (C) 2010 Daniel Tang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/

#define INPUT_PIN 0
#define OUTPUT_PIN 1
#define RUMBLE_PIN 2

void setup ()
{
  pinMode(INPUT_PIN, INPUT_PULLUP);
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(RUMBLE_PIN, OUTPUT);
  Serial.begin(9600);
  digitalWrite(11, HIGH);
}

void loop()
{
  if (digitalRead(INPUT_PIN)) /*High state*/
  {
        digitalWrite(OUTPUT_PIN, HIGH);
        digitalWrite(RUMBLE_PIN, HIGH);
  }
  else
  {
    digitalWrite(OUTPUT_PIN, LOW);
    digitalWrite(RUMBLE_PIN, LOW);
  }
}

Load it onto the Teensy and try out your new mouse mod.

Conclusion: It’s lame, it wastes battery power, it gets really annoying after a while (I’m working on a new firmware to fix it though), has high-ish latency and is totally pointless. But hey, it’s something to do after the exams (and it’s awesome for gaming too).

Pics (yeah, my soldering skills are so un-uber):

Edit2: New and improved code. Uses interrupts to control the vibrator so it comes out as short bursts rather than annoying long bursts.

/*Copyright (C) 2010 Daniel Tang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/

#define INPUT_PIN 0
#define OUTPUT_PIN 1
#define RUMBLE_PIN 2
#include "TimerOne.h"
volatile bool already_rumbling = 0;
bool clicked = false;

void rumble()
{
  if (!already_rumbling)
  {
    digitalWrite(RUMBLE_PIN, HIGH);
    already_rumbling = 1;
    Timer1.start();
  }
}

void setup ()
{
  pinMode(INPUT_PIN, INPUT_PULLUP);
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(RUMBLE_PIN, OUTPUT);
  digitalWrite(11, HIGH);
  
  Timer1.initialize(100000);
  Timer1.attachInterrupt(off, 100000);
  
}

void off()
{
  digitalWrite(RUMBLE_PIN, LOW);
  already_rumbling = 0;
  Timer1.stop();
}

void loop()
{
  if (!digitalRead(INPUT_PIN)) /*High state*/
  {
        digitalWrite(OUTPUT_PIN, HIGH);
        if (!clicked)
        {
          rumble();
          clicked = 1;
        }
  }
  else
  {
    digitalWrite(OUTPUT_PIN, LOW);
    clicked = 0;
  }
}

One thought on “Mouse rumble mod

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s