Go Down

Topic: Wii Guitar Hero World Tour Drums - Bits Not Right (Read 2084 times) previous topic - next topic

jhaip

I am trying to make a wii guitar hero world tour drum set into a midi instrument.  I am using the setup shown at http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/ with a nunchuck pinout board connected to the wiimote connector from the drum set and to the arduino's analog pins 2-5.  I using a modified version of the code from todbot.com (http://todbot.com/arduino/sketches/WiichuckDemo/nunchuck_funcs.h).  I currently am just printing out all 6 incoming bytes that the drum set sends.  I assumed I could trust the chart on the wiibrew website (http://wiibrew.org/wiki/Wiimote/Extension_Controllers#Guitar_Hero_World_Tour_.28Wii.29_Drums) that told was each bit did, although the positions of the data generally match, the exact values do not match. 

For example:
Pressing down on the bass pedal gives
00000011
for the 5th byte when the chart says the bits should be
O R Y G B Bass 1 1
A 0 is supposed to correspond to a hit so it didn't make sense, nor was it mentioned in the documentation, that a bass pedal hit would also mean a hit for all the other pads.

Also when hitting the green pad I get 00001111, which again is saying the orange red and yellow pads are also being hit when they aren't.  This would be okay, but strangely hitting any of the other pads only turns on their correct bit.  And when a chord is played using the messed up green or bass pad then I get a 0 for all the pads except the one that is being played. 

I am having a lot of other troubles with the bits matching so before I start writing a whole bunch of exceptions in the code for it to work, I want to make sure that I am making the connection right through I2C and the Wire library and that they aren't causing these weird things to happen.

drumchuck_funcs.h:
Code: [Select]
/*
* Nunchuck functions  -- Talk to a Wii Nunchuck
*
* This library is from the Bionic Arduino course :
*                          http://todbot.com/blog/bionicarduino/
*
* 2007 Tod E. Kurt, http://todbot.com/blog/
*
* The Wii Nunchuck reading code originally from Windmeadow Labs
*   http://www.windmeadow.com/node/42
*/

#include <WProgram.h>

static uint8_t nunchuck_buf[6];   // array to store nunchuck data,

// Uses port C (analog in) pins as power & ground for Nunchuck
static void nunchuck_setpowerpins()
{
#define pwrpin PORTC3
#define gndpin PORTC2
    DDRC |= _BV(pwrpin) | _BV(gndpin);
    PORTC &=~ _BV(gndpin);
    PORTC |=  _BV(pwrpin);
    delay(100);  // wait for things to stabilize       
}

// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
static void nunchuck_init()
{
    Wire.begin();                // join i2c bus as master
    Wire.beginTransmission(0x52);// transmit to device 0x52
    Wire.send(0xf0);// sends memory address //WAS 40
    Wire.send(0x55);// sends sent a zero. 
    Wire.send(0xfb);
    Wire.send(0x00);
    Wire.endTransmission();// stop transmitting
}

// Send a request for data to the nunchuck
// was "send_zero()"
static void nunchuck_send_request()
{
    Wire.beginTransmission(0x52);// transmit to device 0x52
    Wire.send(0x00);// sends one byte
    Wire.endTransmission();// stop transmitting
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
static char nunchuk_decode_byte (char x)
{
    x = (x ^ 0x17) + 0x17;
    return x;
}

// Receive data back from the nunchuck,
// returns 1 on successful read. returns 0 on failure
static int nunchuck_get_data()
{
    int cnt=0;
    Wire.requestFrom (0x52, 6);// request data from nunchuck
    while (Wire.available ()) {
        // receive byte as an integer
        nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.receive());
        cnt++;
    }
    nunchuck_send_request();  // send request for next data payload
    // If we recieved the 6 bytes, then go print them
    if (cnt >= 5) {
        return 1;   // success
    }
    return 0; //failure
}

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits.  That is why I
// multiply them by 2 * 2
static void nunchuck_print_data()
{
    Serial.print(nunchuck_buf[0],BIN);
    Serial.print("  ");
    Serial.print(nunchuck_buf[1],BIN);
    Serial.print("  ");
    Serial.print(nunchuck_buf[2],BIN);
    Serial.print("  ");
    Serial.print(nunchuck_buf[3],BIN);
    Serial.print("  ");
    Serial.print(nunchuck_buf[4],BIN);
    Serial.print("  ");
    Serial.print(nunchuck_buf[5],BIN);
    Serial.print("\r\n");  // newline
   
    static int i=0;
    i++;
}


drumchuckDemo
Code: [Select]
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
*/

#include <Wire.h>
#include "drumchuck_funcs.h"

int loop_cnt=0;
int ledPin = 13;

void setup()
{
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
   
    Serial.print("WiiChuckDemo ready\n");
}

void loop()
{
    if( loop_cnt > 100 ) { // every 100 msecs get new data
        loop_cnt = 0;

        if ( nunchuck_get_data() == 1 ) {
          nunchuck_print_data();
        }
        else {
          Serial.println("COULDN'T GET DATA");
        }
    }
    loop_cnt++;
    delay(1);
}


Thanks,
jhaip

mattcf

are you sure the BAUD is correct, if not you will get a bunch of random/missmatched data.

Go Up