Arduino Lens Controller - Synchronized Zoom/Focus with Wii Classic Controller

 by grp19
Featured

Step 4: Program your Board: Get the Libraries and My Code and Start Playing

Before you load the code that I wrote for my lens controller, you need to get the Arduino IDE set up on your computer and load the libraries that you need. The Servo control library is included with the Arduino IDE, so you don't need to do anything for that. However, my code also uses a user-contributed Wii Classic Controller library that is available on the Arduino playground. http://arduino.cc/playground/Main/WiiClassicController10
You can follow the steps on the page to add this to your library, or just download the zip file that I've attached and unzip it into your Arduino libraries folder. Mine is in this path:
..\Documents\Arduino\arduino-1.0\libraries\

I created a folder called MiconoWiiClassic in the \libararies folder, and saved the "WiiClassic.h" file in that folder. You can just unzip the MiconoWiiClassic.zip file that I've included here to your Arduino-1.9\libraries folder.

UPDATES:
1) Since first posting this Instructable, I've figured out how to double the resolution of the servos, which makes them smoother and more accurate. I did this by tweaking the Servos library that is installed by Arduino. You can either tweak the library yourself, or you can download the Servo.zip file and extract the Servo.cpp file into your ..\Arduino\arduino-1.0\libraries\Servo folder and overwrite the Servo.cpp file that's there. If you want to tweak the file yourself, you can just open the file from your library in Notepad, and replace all instances of "180" with "360".  If you downloaded my sketch before I made this update, you should re-download FocusController_gp.zip and extract it to your sketch folder. It will add focus_zoom_controller_servo_final_2xresolution.ino to that folder.

2) After you unzip the files you need to change one thing in the WiiClassic.h file in order to make the library work as expected with my code.The WiiClassic.h library contains a DEFINE_ON_HOLD feature that must be uncommented in order to ensure that the button presses are reported just once. To uncomment this, you have to open the ..\arduino-1.0\libraries\MiconoWiiClassic\WiiClassic.h file in Notepad and change the following line:
//#define REPORT_ON_HOLD
to
#define REPORT_ON_HOLD
If you don't do this, you will notice that the D-pad button presses will keep moving the servos as you hold the button, whereas it should only move the servo one step per press. This error may also cause strange behavior from other button presses.

3) If you're plugging the WiiChuck adapter in to Analog pins 2,3,4 and 5, you need to configure 2 and 3 as ground and power, by adding the following to the setup section of your code (thanks to Phillip James for catching this ommision)

"pinMode(16, OUTPUT);" Sets digital 16 pin (aka Analog 2) as ground pin
"digitalWrite(16, LOW);"
"pinMode(17, OUTPUT);" Sets digital 17 pin (aka Analog 3) as +5V pin
"digitalWrite(17, HIGH);"

Once you have that library in place, you can also download my project code and unzip it to your main Arduino folder, and the next time you launch the Arduino IDE, my projects will show up in your Sketchbook folder. My Arduino folder is in my documents folder, like this:
..\Documents\Arduino\
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!