From Pinguino
Jump to: navigation, search
Language: English

Pinguino and Wii Motion Plus

This example shows how to connect a Pinguino board to the Wii Motion Plus.

The Wii Motion Plus is a 3-axis electronic gyroscope; it uses a IDG600 chip from Invensense.

It can be used for robotic applications or movement tracking.

The code uses the LibI2C module in Pinguino. We adapted the I2C initialisation to work with a clock frequency of 100 kHz. The output sends value to the serial port.

The beta 9-05 version is used to compile the code.


How to connect it ?

A piece of double-sided PCB has been used to make a male connector.


Pinguino is connected to the Wii Motion Plus via the I2C bus.

SCL is PIN 0 and SDA is PIN 1.

The Wii Motion Plus is powered from the 5vcc Pinguino power supply.

Pinguino Breadboard


Two 22k resistors are used as pull-ups on the SDA and SCL lines.

Test is on a 18F2550 Pinguino but it can also be wired on a 18F4550.

The code

// test program for I2C communication with wii motion plus

// Jean-Pierre MANDON 2011

#include <libI2C.c>

byte wmp_address_S=0x53;					// i2c address for wii motion plus at startup
byte wmp_address_R=0x52;					// i2c address for wii motion plus after startup
unsigned char I2C_OK;						// acknowledge when calling I2C function
byte I2C_setParameters[2]={0xFE,0x04};		                // wii motion plus initialisation
byte I2C_readRegister[1]={0x00};			        // read instruction for nunchuck

void setup()
// Serial is used to monitor data
// special initialisation to set I2C to 100khz
i2c_open(I2C_MASTER, I2C_SLEW_OFF, 119);
// end of I2C initialisation

void wiimotionplus_init()
	I2C_OK=I2C_write(wmp_address_S,I2C_setParameters,2);		// set memory address for future read

void send_zero()
	I2C_OK=I2C_write(wmp_address_R,I2C_readRegister,1);		// set request to read

// prepare a new request to memory
void new_request()
unsigned char cpt;

	while ((cpt++<10)&&(!I2C_OK)) send_zero();

void loop()
unsigned char i;

wiimotionplus_init();		// initiase wii motion plus
if (!I2C_OK)
	Serial.printf("Init Error\n\r");
else Serial.printf("Init OK\n\r");
while ((i++<10)&&(!I2C_OK)) send_zero();		// prepare new request
if (!I2C_OK) 
	Serial.printf("Wii motion plus Error\n\r");
else Serial.printf("Request OK\n\r");	
	I2C_OK = I2C_read(wmp_address_R,6);			// read wii motion plus value
	if (I2C_OK)
		for (i=0;i<6;i++) Serial.printf("%d ",i2c_buffer[i]);
		new_request();							// prepare a new request

6 bytes are read from the Wii Motion Plus. Each byte is the value of a sensor.

byte 0 is the yaw down speed (bit 7-0),
byte 1 is the roll left speed (bit 7-0), byte 2 is the pitch left speed (bit 7-0),

byte 3
bit 7-2 is bit 13-8 of the yaw down speed,
bit 1 is the yaw slow mode,
bit 0 is the pitch slow mode,
byte 4
bit 7-2 is bit 13-8 of the roll left speed,
bit 1 is the row slow mode,
bit 0 is the extension connected bit,
byte 5
bit 7-2 is bit 13-8 of the pitch left speed,
bit 1 is always 1,
bit 0 is always 0.

More about the Wii Motion Plus

WiiBrew website

Invensense website