dinsdag 11 februari 2014

Arduino Pan & Tilt with Wii Nunchuk - software

The Arduino sketch can be found here:

HTML version

INO file

Mancave article
You need to download the library wiinunchuck.h :

* File : wiinunchuk.h V0.9
* Author: Tim Teatro
* Date : Feb 2012
* find the download page here
* download the wiinunchuk.h file in your libraries folder of the Arduino environment
(something like C:\arduino-1.0.4\libraries\wii , where you first create a folder 'wii' yourself)

The sketch also uses the servo.h and wire.h libraries. The wire library supplies the I2C connection protocol which you don't have to worry about other than connecting the right pins (A4 and A5) to the datapin and clockpin of the NunChuk.

The sketch uses two possible control methods: using the joystick of the Nunchuk or using the movement sensors. The sketch as downloaded in the above link has method two commented out because it's not that practical. It's a lot of fun though, so feel free to try method one and two as described in the code.

As mentioned, the joystick mode is the way to go if you really want to use the pan & tilt servos.
These are important variables to keep in mind:

int pinPan = 3; --> pin number of the panservo
int pinTilt = 5; --> pin number of the tiltservo

int panPos = 70; --> initial panposition
int tiltPos = 80; --> initial tiltposition

Feel free to change the initial positions or pin numbers to more convenient values.

I added some lines to make the tilt movement a bit less sensitive than the pan movement:

    if ((speedTilt <= 2) & (speedTilt >= -2)) {speedTilt = 0;};
    if (speedTilt > 2){speedTilt -= 2;};
    if (speedTilt < -2){speedTilt += 2;};

Actually, all it does is ignore the values of the tilt joystick from 110 to 150 (130 is the center position, actual values may vary in your controller). The reason is simple: tilt movement is not that important and should only be activated if you move the joystick more firmly up or down. I tried it without this extra code, and it was annoying to see tilt movement when you actually only want to pan left or right most of the time.

Back: the hardware page

Geen opmerkingen:

Een reactie plaatsen