NXT wii NunChuck interface with NXC
Posted: 27 Mar 2011, 08:58
I bought two non-OEM nunchucks to try to interface with the NXT. However, so for no go. I removed the pullups, and have 47k pullups (on the NXT end of the cable). I also have diodes to drop the voltage (Xander, I measured before connecting this one ). I am trying to get this program to work:The code is based off of one that I have seen floating around on the web for a while. However, I have almost completely rewritten it.
It always displays (returns) 255 (0xFF) for all six bytes.
It doesn't work at all if I do either of the following:
I am sure the nunchuck is sending some sort of data, but it sure doesn't seem to be anything other than 0xFF.
Any ideas?
Any code you know works that you want to share?
Could someone with a working NXTified nunchuck please try my code, and tell my what happens?
Code: Select all
byte CMDNunchukInit[] = {0xA4, 0x40, 0x00};
byte CMDNunchukWrite[] = {0xA4, 0x00};
byte CMDNunchukRead[] = {0xA4};
byte outbuf[];
byte count = 6;
byte nByteReady;
task main()
{
SetSensorLowspeed(S1);
while (true)
{
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CWrite(S1, 0, CMDNunchukInit); //When the I2C bus is ready, send message
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CWrite(S1, 0, CMDNunchukWrite); //When the I2C bus is ready, send message
while (I2CStatus(S1, nByteReady) == STAT_COMM_PENDING); //Wait until bus is free
I2CBytes(S1, CMDNunchukRead, count, outbuf) //Read the registers
if (ArrayLen(outbuf)==count) {
ClearScreen();
for(int i=0; i<ArrayLen(outbuf); i++ ) {
NumOut(0, LCD_LINE2-(i*8), outbuf[i]);
}
}
Wait(100);
}
}
It always displays (returns) 255 (0xFF) for all six bytes.
It doesn't work at all if I do either of the following:
- switch the serial lines (I don't have them mixed up).
Remove either or both of the pullups.
I am sure the nunchuck is sending some sort of data, but it sure doesn't seem to be anything other than 0xFF.
Any ideas?
Any code you know works that you want to share?
Could someone with a working NXTified nunchuck please try my code, and tell my what happens?