Maverick Mouse

NOTE: Better to watch the video on youtube and viewed full screen.

In this project I take a Nerf Maverick and use it as my mouse for my laptop. This was easier than I thought it would be. It took about two days to do, and I use python for the computer interface. This is much like the Nerf gun for the Wii. You could do the same thing with the gun for the Wii and connect your Wiimote to the PC via bluetooth. That way uses PyGlove as the emulator.

The first step was to find a way to “click” with the trigger of the gun. After opening the Maverick I found the trigger when pulled touches another part inside the gun. This made it easy to wrap some wires around the two parts so it would act as a button. (Figure 1-1; Figure 1-2)

Figure 1-1

Figure 1-1

Figure 1-2

Figure 1-2

Next was to find a spot for the 9v so I could power the ArduinoBT and the circuits. I used a soldering knife to cut out a spot. It is in the handle of the gun kind of like a clip. (Figure 1-3; Figure 1-4)

Figure 1-3

Figure 1-3

Figure 1-4

Figure 1-4

After I got the circuits working it was time for the code. I used Python2.6 and an infrared tracking library I wrote to map the mouse movements, and when the trigger is pulled, it sends a message to the COM port to tell python to click the left mouse button.

//nerf.pde
int trigPin = 13;
int pulled = 0;

void setup() {
    Serial.begin(115200);
    pinMode(trigPin, INPUT);
}

void loop() {
    pulled = digitalRead(trigPin);
    if (pulled == HIGH) {
        Serial.println("d");
    }

    else {
        Serial.println("u");
    }
}

This is the script to read the arduino and map the mouse. IRClass is found in my blog. It is my first post. The variable “c” is used to make sure there aren’t any accidental double clicks and it allows the “drag-n-drop” feature.

import serial
import win32api
import win32con
from ctypes import *
import IRClass

ir = IRClass.IR()
s = serial.Serial('COM9',baudrate=115200)
user = windll.user32

#These functions control the mouse clicks.
def lUP():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
def lDOWN():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)

c = 0
while 1:
    x,y = ir.xySinglePos(scale=(1440,900))
    ir.user.SetCursorPos(x,y)
    s.flushInput()
    buff = s.readline()
    if "d" in buff and c == 0:
        lDOWN()
        c += 1
    elif "u" in buff:
        lUP()
        c = 0

These are pictures of the completed gun.

side1

side1

side2

side2

top

top

bottem

bottem

angle

angle

Advertisements

About Tech B.

I am currently employed as a tech support rep for Frontier DSL internet and Dail-Up service. If you live on the East Coast and have Frontier or the old Verizon, you may have spoken with me at one point. I do side jobs programming and building things for people. I know Python better than any language in my toolbox. I can also develop Android Apps, which are Java based. Other languages include C , VB/VB.NET, some C#, PBASIC, Batch, Javascript, and some PHP. I love microcontrollers and interfacing with the outside world. I am currently working with Arduinos, which are amazing. Also I can work with the Basic Stamp family of microcontrollers; future development includes FPGA and embedded Linux. I was going to school, but have financial issues at the moment that are keeping me from the books. I plan on going back in the next couple semesters and finishing up my Associates in IT, then perusing a BS in computer science.
This entry was posted in Programming Python and tagged , , , , , , . Bookmark the permalink.

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