Welcome! Log In Create A New Profile


Motion Sensing help

Posted by blutderengel 
Motion Sensing help
February 23, 2009 12:23AM
I've just begun programming with devkitpro and the wiiuse library. I started off with the template that comes with devkitpro and expanded on that. So far I have all the buttons on the wiimote working for pressed, released, and held, as well as the nunchuck buttons and the analog stick. Also, I've gotten then IR to work properly.

I'm now interested in using the accelerometer in the wiimote and I've been trying to gather the data from it, but I only get 0's out of it. I can't figure out what I've done wrong, but I feel like I need to initialize the accelerometer or something.

I have the code set to display the roll, pitch, and yaw only when you hold the B button, and the acceleration is displayed when holding the Minus button.

Any help would be very much appreciated.

Here is my code:


static u32 *xfb;
static GXRModeObj *rmode;

void Initialise() {


	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

int main() {

	printf("Hello World!\n");
	struct expansion_t exp;
	struct orient_t orient;
	struct vec3w_t accel;

	while(1) {

		u16 buttonsDown = WPAD_ButtonsDown(0);
                u16 buttonsHeld = WPAD_ButtonsHeld(0);

		WPAD_Expansion(WPAD_CHAN_0, &exp);
		WPAD_Orientation(WPAD_CHAN_0, &orient);
		WPAD_Accel(WPAD_CHAN_0, &accel);
		if( buttonsDown & WPAD_BUTTON_A ) {
			printf("Button A pressed.\n");
//.... a bunch of similar code checking the buttons presses and holdings.

if (buttonsHeld & WPAD_BUTTON_B ) {
			printf("Wiimote yaw  : %f\n"
					"Wiimote pitch: %f\n"
					"Wiimote roll : %f\n", orient.yaw, orient.pitch, orient.roll);
		if (buttonsHeld & WPAD_BUTTON_MINUS ) {
			printf("Wiimote acceleration:\n"
					"X:  %f\n"
					"Y:  %f\n"
					"Z:  %f\n", accel.x, accel.y, accel.z);

		if (buttonsDown & WPAD_BUTTON_HOME) {

	return 0;

Re: Motion Sensing help
February 23, 2009 12:42AM
You're missing the init to get that data, put this after WPAD_Init()

WPAD_SetVRes(WPAD_CHAN_ALL,screenwidth, screenheight);

where screenwidth/height are whatever width/height you want (eg: 640x480)
Re: Motion Sensing help
February 23, 2009 12:49AM
Also, I see this a lot - using all those WPAD functions to get data. You can use one function to get all your WPAD data, do something like so:

WPADData wpad;

memcpy(&wpad, WPAD_Data(0), sizeof(WPADData));

// use the data
if (wpad.btns_d & WPAD_BUTTON_B ) {

printf("Wiimote acceleration:\n"
"X: %f\n"
"Y: %f\n"
"Z: %f\n", wpad.accel.x, wpad.accel.y, wpad.accel.z);
Re: Motion Sensing help
February 23, 2009 01:03PM
Thanks for the reply Tantric.

I took your suggested code and the orientation works great now, but the acceleration still displays 0's. Any ideas why that might be?
Sorry, only registered users may post in this forum.

Click here to login