Control your mouse cursor by WIIMOTE

Since the Wii Remote uses bluetooth to communicate with the console, it’s relatively straightforward to use it to control a computer. The most obvious way is similar to the main menu on the Wii console – point the remote where you want the cursor to go, and press A and B to left and right click. There are also options for tilting the Wiimote to move the cursor around, which is useful if you don’t have a sensor bar available.

You can Do all this stuff by using a tool WMGUI which is a utility of CWiiD.

To install and make this work follow the instructions :-

sudo apt-get install libcwiid1

sudo apt-get install lswm


sudo apt-get install wmgui

sudo apt-get install wminput

Now load wmgui in terminal

Now click on Connect button in FILE

Select “connect” from the file menu, press 1+2 when prompted then OK. Lights and rumble can be turned on and off from the controls menu, and which inputs are displayed from the settings menu. Using this, you can test the IR camera, the accelerometers and check the inputs from the Nunchuck or Classic Controller.

Next up is the mouse “emulator” which allows you to control the mouse with the Wiimote. At this point, it can be run with default settings (tilting the Wiimote moves the pointer, A and B work as left and right click).

The uinput module needs to be loaded into the kernal first. This can either be done manually after every reboot:

lswm

This should return the address of the Wiimote (something like 00:1F:32:95:EF:B0). This will be different for each Wiimote. If it doesn’t work, try again, ensuring the lights on the Wiimote are still flashing when you run lswm.

Moving the mouse by tilting the Wiimote

Press the 1+2 buttons on the Wiimote and run:

sudo wminput 00:1F:32:95:EF:B0

replacing 00:1F:32:95:EF:B0 with the address of your Wiimote. This can be run without the address, but will take longer to connect.

Press 1+2 on the Wiimote and from a terminal run this:

wminput -c ir_ptr 00:1F:32:95:EF:B0

Running wminput as user (not root)

Normally wminput has to be run as root as the uinput device requires root priviliges. To allow any user to access it add a rule to /etc/udev/rules.d to change the mode of the device to “0600”, e.g

 sudo sh -c 'echo KERNEL\=\=\"uinput\", MODE\=\"0666\" > /etc/udev/rules.d/71-wiiremote.rules'

 

then reboot or restart the udev service

 

sudo service udev restart 

 

WMGUI as daemon

wminput -d 00:1F:32:95:EF:B0

Will run wminput in daemon mode – quiet output, waits indefinitely and continually retries to reconnect. Press 1+2 on the remote to connect, the remote powerbutton to disconnect.

nohup wminput -d 00:1F:32:95:EF:B0&

Will launch it quietly in the background.

 

By this you can easily Control your mouse cursor using WiiMote. Plus you can find accelerometer’s X-, Y- & Z- axes

Advertisements

LED’s blinking according to coordinates of mouse

This is the experimental set-up I tried using Processing inheriting Arduino Libraries. Objective I wanted to do was to make red and blue coloured LED’s to blink according to the location of mouse’s X- coordinate is whether even or odd when clicked. i.e. When Mouse’s X-coordinate is even Red coloured LED blinks and when it is odd Blue Coloured LED will blink while clicking it including making different sized ellipse on the screen according to clicks.
hardware setting was nothing that hard, just two LEDs connected to pin 13 and pin 12 of arduino. Thats it.

Rest programming in Processing was as following:-

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin1 = 13;
int ledPin2 = 12;
void setup(){
arduino = new Arduino(this, Arduino.list()[0],57600);
arduino.pinMode(ledPin1, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
size(400,400);
background(0);
frameRate(15);
}
void draw(){
color c = color(200,0,0);
if(mousePressed == true){
fill(c, 150);
if(mouseX % 2 == 0){
fill(255,255,0);
ellipse(mouseX,mouseY,25,25);
arduino.digitalWrite(ledPin1, Arduino.HIGH);
delay(20000);}
arduino.digitalWrite(ledPin1,Arduino.LOW);
if(mouseX % 2 == 1){
ellipse(mouseX,mouseY,40,40);
arduino.digitalWrite(ledPin2, Arduino.HIGH);
delay(10000);}
arduino.digitalWrite(ledPin2, Arduino.LOW);
}
else{
fill(0);}
}