Hi everyone,
i have a problem with original nintendo nunchuck. I’m trying to connect on Arduino DUE, i used the same code of Arduino UNO and in my Arduino UNO everything is OK. Now When I try on Arduino DUE no data seems incoming. I searched on internet and i tried several exemple code but nothing to do…
thi is the code that i succesfull used on Arduino UNO but not work in Arduino DUE :
#define CPU_FREQ 16000000L
#define TWI_FREQ 100000L
#include <Wire.h>
int diode = HIGH;
void blink() {
digitalWrite(13, diode);
diode = (diode == HIGH) ? LOW : HIGH;
}
void setup() {
Serial.begin(19200);
pinMode(13, OUTPUT);
Wire.begin();
Wire.beginTransmission(0x52);
Wire.write(0x40);
Wire.write(0x00);
Wire.endTransmission();
}
void send_zero() {
Wire.beginTransmission(0x52);
Wire.write(0x00);
Wire.endTransmission();
}
void loop() {
int cnt = 0;
uint8_t outbuf[6];
Wire.requestFrom(0x52, 6);
while(Wire.available()) {
if(cnt < 6) {
outbuf[cnt] = (0x17 ^ Wire.read()) + 0x17;
}
cnt++;
}
int b = ~outbuf[5] & 3;
int joy_x = outbuf[0]-125;
int joy_y = outbuf[1]-128;
int accel_x = (outbuf[2] << 2 | ((outbuf[5] >> 2) & 0x03)) - 500;
int accel_y = (outbuf[3] << 2 | ((outbuf[5] >> 4) & 0x03)) - 488;
int accel_z = (outbuf[4] << 2 | ((outbuf[5] >> 6) & 0x03)) - 504;
Serial.print(“B=”);
Serial.print(b);
Serial.print(" XY=");
Serial.print(joy_x);
Serial.print(",");
Serial.print(joy_y);
Serial.print(" XYZ=");
Serial.print(accel_x);
Serial.print(",");
Serial.print(accel_y);
Serial.print(",");
Serial.print(accel_z);
Serial.print("\n");
send_zero();
blink();
delay(50);
}
Any Ideas ?
Thanks