Reading Nunchuck and MotionPlus at the same time

7 02 2010

The Trick Read both the nunchuck and the MotionPlus is very similar to reading the MotionPlus alone.
The only disadvantage to the method described here is that the lowest bit of the ten bit accelerometer data is lost.

The only I2C communication part that really differs in comparison tho the communication with the MotionPlus is the initialisation. Instead of initializing it by writing 0x4 to 0xFE on I2C device 0xA6, the initialisation is done by writing 0x5 to the same address and device. The nunchuck does not need to be initialized.

After the initialisation the MotionPlus and the Nunchuck can be read, by reading six Bytes from the same Register 0x00. When Nunchuck and MotionPlus are connected the data can be read alternating each time the data is read. To distinguish each data package between MotionPlus and the Nunchuck the two lowest bit of the sixth bit (data[5] & 3) can be used. Those bits are equal to two when the MotionPlus was read and zero when the Nunchuck was Read.

When no nunchuck is Connected the last bit of the fourth byte from the MotionPlus (data[4] & 1) is equal to zero (else equal to one). Also only MotionPlus data will be read when the Nunckuck is not connected.

The data can be transformed using the following code:
MotionPlus:
gyr_roll = data[1] | ((data[4] & 0xFC) <<6); //14 bit Value
gyr_pitch = data[2] | ((data[5] & 0xFC) <<6);
gyr_yaw = data[0] | ((data[3] & 0xFC) <<6);
if(!(data[3]|2))//when the gyroscope is moving slower the data is approximately five times more accurate.
gyr_yaw *= 5;
if(!(data[3]|1))
gyr_pitch *= 5;
if(!(data[4]|2))
gyr_roll *=5;

Nunchuck:accx = (data[2]<<2)|((data[5]&0x10)>>3);
accy = (data[3]<<2)|((data[5]&0x20)>>4);
accz = ((data[4]&0xFC)<<2)|((data[5]&0xC0)>>5);

Visualisation of the data via Python and QWT

further information about wii extension controllers see this wiki


Aktionen

Information

Hinterlasse einen Kommentar