Home

About

Me

Project List

Mail me

Last update: 2012-09-07

mega8nunchuk

Abstract

Acceleration sensors are not available to hobbyists everywhere. And they are quite expensive when bought in small quantities. Nintendo's Nunchuk controller for Wii contains such an sensor. For heavens sake the Nunchuk has a standard I2C (TWI) interface. Cheap clones (under 6 EUR) are available.

Overview

Many articles are available on the internet on how to interface an Arduino board and a Nunchuk controller. This project is about interfacing a bare ATmega8 and using avr-gcc. This article will not explain neither Nunchuk nor TWI details since these are well documented already. This article will deliver an example wiring and a short test program compilable with avr-gcc/avrlibc.

Dismantling the Nunchuk Controller

For my application I only need the acceleration data. I do not need to read the buttons nor the analog joystick. Furthermore the plug is non-standard and I want to get rid of it.

Therefore I opened the case, removed buttons, stick and cable. I soldered a ribbon cable to the board. At the other end the cable is equipped with a standard IDC socket. I am using a ten pin socket since I want to use two such sensors in my application. For the sake of simplicity this example will only demonstrate use of one sensor.

The cheap clones seem to use cables that differ in color compared to the original one. The following table explains the meaning of the original wires as well as the cheap one I am using.

Original colorClone colorDescription
 white  red GND
 green  yellow SDA - serial data
 yellow  white SCL - serial clock
 red  green VDD - +3.3V
Color scheme for original and clone controller

The controller is to be supplied by a 3.3V source. Many articles on the internet just use the already given 5V supply while at the same time saying that this may decrease lifetime of the sensor. Therefore my wiring diagram contains a 3.3V source.

Hardware

The following circuit allows reading the sensor and printing results on screen via RS-232. I am using PuTTY as a terminal program.

Wiring diagram

Software

Included is a small test program that shows how to read the sensor in an asynchronous fashion. For the TWI protocol it uses my TWI driver from my AVR utilities collection.

According to Arduino Forum there are two ways of initializing the Nunchuk controller:

  1. Send the byte sequence [0x40, 0x00]. This is the way to initialize an original Nintendo Nunchuk.
  2. Send two byte sequence [0xF0, 0x55] and [0xFB, 0x00]. This also works for Nunchuks other than the original Nintendo ones. It furthermore frees us from the need to decode the encrypted data sent by the Nunchuk.
This example code uses the latter approach, since I am experimenting with a cheap clone.

Prerequisites

Screenshots/Pictures

Nunchuk board before dismantling
Nunchuk board after dismantling
Dismantled Nunchuk board with new ribbon cable and IDC socket
Prototype

Version History

VersionDateChange
1.0.02012-08-28Initial version.
1.1.02012-09-07Now using libAvrUtils 1.2.0.

Copyright Statement

mega8nunchuk Copyright (C) 2012 Holger Zahnleiter

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. The program and its source code are published under the GNU General Public License (GPL). See http://www.gnu.org/licenses/gpl-3.0.txt for details.

Credits

Creating this library would not have been possible without the achievements of the following persons/organisations:

References/Links

Windmeadow Labs Article on how to read an Wii Nunchuk controller.
Physical Computing Another - even more detailed - article on how to read an Wii Nunchuk controller.
Arduino Playground A Nunchuk class for Arduino.
Arduino Forum A discussion about the proper initialization sequence for the Nunchuk controller.
http://www.mikrocontroller.net/ A great (german) resource of Atmel AVR tutorials and general microcontroller know how.
RoboterNETZ Another great (german) resource of microcontroller know how.
AVR freaks English speakers should visit this website.
CrossPack CrossPack for AVR Development for Mac OS X.
AVR-GCC-Tutorial German avr-gcc tutorial from mikrocontroller.net.
http://www.nongnu.org/avr-libc/ The AVR C library (for use with avr-gcc).
http://www.nongnu.org/avrdude/ AVRDUDE, a tool for flashing AVRs.
http://www.cadsoft.de/ EAGLE a CAD software for designing circuits. Free version available for Mac OS X, Linux and Windows.
RS-232 product site MAXIM's website featuring their line of RS-232 transceivers. The most current datasheet can be downloaded from there.
ATmega8 product site Atmel's website featuring ATmega8. The most current datasheet can be downloaded from there.

Downloads

Source code for ATmega8 (mega8nunchuk-1.1.0-src.zip)
ATmega8 test program (testAsync.hex)
ATmega8 test program (testSync.hex)
ATmega8 test program (testMixed.hex)
Wiring diagram/Eagle 6.2.0 (mega8nunchuk.sch)
Atmel ATmega8 Datasheet
LM317 Adjustable Regulator Dataheet
MAXIM RS-232 Transceivers Datasheet

Disclaimer

The information on this web site and the documents downloadable from here have been carefully reviewed and is believed to be reliable, but I do not assume any liability arising out of the application or use of any documents, programs or circuit described herein.
Furthermore I want to declare that I'm not responsible in any way for the content of other web pages, books and other sources I'm refering to.