For the Professional Maker: I?C for Arduino joystick control
November 02, 2017
Instead of buttons, potentiometers, and the like being fed directly into your microprocessor, you can take care of this with a few wires, and the near-ubiquitous I?C protocol.
As discussed previously, I²C provides an excellent and freely usable standard for short range interfaces between integrated circuits. This can make a great platform for human-machine interface (HMI) setups. Instead of buttons, potentiometers, and the like being fed directly into your microprocessor—increasing wiring complexity and processor overhead—you can take care of this with a few wires, and the near-ubiquitous I²C protocol.
One such interface device is the Wii Nunchuck, clones of which are available online for under $5. For wired robotics control, or perhaps even an animated costume as seen here, it’s hard to beat these little devices. In order to see just how easily (or hard) it is to implement this protocol, I followed along with these instructions on Arduino’s site. While I found it fairly easy to get things communicating, there were a few small things that I had to watch out for along the way.
Library installation
Installing libraries in the Arduino IDE is generally extremely easy, as most can be searched and installed with the click of a button. In this case, however, I had to download the directory found here as a .ZIP file, unpacked it, then placed the Wii-Nunchuck folder into my Arduino/libraries folder. After a restart, this library showed up without issue. While not extremely challenging, it may cause some confusion for those used to installing libraries the other way. Another potential source of confusion is that, as of this writing, if you try to search for “nunchuck” under the library manager, you’ll find a different one than used here.
Wiring
If you’re going to purchase a Wii Nunchuck for microcontroller use, adapters that will break out its connector without damage can be had for around $1.00. While a good option, if you need to interface your controller without waiting for an extra board, or if you don’t care about reusing your Nunchuck, you can also just cut the plug off and connect the wires as I did. You’ll want to keep the plug around, however, in order to tell which wire goes where.
Looking at the connector, there are six pins, the middle two of which are not used. The upper left is the data (SDA) line, which goes to Arduino pin A4, the lower left is the ground, the upper right is 3.3VDC, and the lower right goes to A5 as the clock (SCL) line. I soldered jumper pins to each of the wires I was going to use, then plugged them in as required.
Program
With it hooked up, I then input the program found on the Arduino project page. However, I had to change one line to read
Feedback on a screen is great, but in order to show that I could control the Arduino itself with it, I modified the code found there to include lighting up the built in LED on my Arduino Uno Clone depending on if on if the “Z” button was pushed. This gave me the feedback I was expecting, and from there this kind of control could be extended to many other uses, from robotics control to alternate computer interface devices. It’s a great tool to have at your disposal, and working with this controller could be a nice, hands-on intro to using I²C.