Example Code

Reading From a Wii Nunchuck Via an Arduino

Code and Documents

Attachment

Overview

This example includes functions to initialize and read data from a Wii Nunchuck using an Arduino as an I2C interface. A sample VI is provided that shows how to implement these lower level functions.

Data available includes a three axis accelerometer, two axis joystick and two pushbuttons.

Description

The Wii Nunchuck is an increasingly popular input device that communicates via the I2C protocol. In this example we use the LabVIEW Interface for Arduino (LIFA) Toolkit to take I2C data from an Arduino and and then use Labview to convert the Nunchuck data in to usable values.

Of particular interest are the accelerometer readings; in order to represent the 10 bit resolution, the device uses 1 byte (8 bits) for each channel and then has an "aggregate" byte which contains the remaining two bits from each accelerometer reading in addition to the button press bytes.

The joystick uses one byte per axis and provides 8-bit resolution.

Steps to Implement or Execute Code

  1. Connect the Nunchuck to your Arduino board. There are mutliple connector boards commercially available, or you can cut the connector off and wire directly. If you choose to do this, the yellow wire represents SCL, green is SDA, white is ground, and red is +3.3v.

  2. Download and extract the .zip file and open the GenericReadChuck project. In this project you will find the GenericRead vi which demonstrates the lower level init and read functions.

  3. Select the appropriate COM port and board type from the front panel controls.

  4. Run th GenericRead vi to observe the inputs.

  5. To use the lower level functions directly, initiate an Arduino resource using the LIFA toolkit, use the NunchuckInit vi to establish communication with the Nunchuck and then use the NunchuckRead vi to acquire values. Finally close the reference out using the close resource vi from the LIFA toolkit.


Requirements

Software

LabVIEW 2011, LabVIEW Interface for Arduino (LIFA) Toolkit

Hardware

Wii Nunchuck, Arduino board compatible with the LIFA toolkit

Additional Images or Video

FrontPanel.JPG

Main.png




--------------------------------------

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors