-1

Im sorry to make a post like this but i have tried everything and i cant get this working!

I have two arduinos hooked up with xbee's.

One is connected to my computer recieving data and the other is bettery powered and has a Wii nunchuck attached. I know im getting good data from the nunchcuck cause i tested it without the xbee. But i want to send the data over serial and recieve on the other to use for something else but doesnt seem to be working. Here is the code:

Arduino with wii:

#include <Wire.h>
#include <Servo.h>
const int vccPin = A3;
const int gndPin = A2;

Servo servo;

const int dataLength = 6; // Number of bytes to request 

static byte rawData[dataLength];

enum nunchuckItems { 
  JoyX, JoyY, accelX, accelY, accelZ, btnZ, btnC};

void setup()
{
  pinMode(gndPin, OUTPUT);
  pinMode(vccPin, OUTPUT);
  digitalWrite(gndPin, LOW);
  digitalWrite(vccPin, HIGH);
  servo.attach(9);

  delay(1000);
  Serial.begin(9600);

  nunchuckInit();
}

void loop()
{
  nunchuckRead();



  int joyX = getValue(JoyX);
  int joyY = getValue(JoyY);


  Serial.print(joyX);
  Serial.print(",");
  Serial.print(joyY);
  Serial.println();



  }

  void nunchuckInit(){

    Wire.begin();
    Wire.beginTransmission(0x52);
    Wire.write((byte)0x40);
    Wire.write((byte)0x00);
    Wire.endTransmission();

  }

static void nunchuckRequest(){
  Wire.beginTransmission(0x52);
  Wire.write((byte)0x00);
  Wire.endTransmission(); 
}

boolean nunchuckRead(){

  int cnt = 0;
  Wire.requestFrom(0x52, dataLength);

  while (Wire.available()){

    rawData[cnt] = nunchuckDecode(Wire.read());
    cnt++;
  } 

  nunchuckRequest();
  if (cnt >= dataLength)
    return true;
  else 
    return false;

}


static char nunchuckDecode(byte x){
  return (x ^ 0x17) + 0x17;

}

int getValue(int item){

  if (item <= accelZ)
    return (int)rawData[item];
  else if (item == btnZ)
    return bitRead(rawData[5], 0) ? 0: 1;
  else if (item == btnC)
    return bitRead(rawData[5], 1) ? 0: 1;

}

How could i recieve this data on the recieving arduino?

Please help its for my school project!

Thank you!!

dsolimano
  • 8,870
  • 3
  • 48
  • 63

1 Answers1

0

When you read the terminal (without the Xbee) do you see line with X,Y appear ? Because if your arduino terminal see it, the problem comes from the Xbee.

If your terminal see the line, look at your Xbee with Xctu. You must set the panID on both Xbee to see them communicate. you must also make the SL address of the sender equal to the DL address of the receiver (and same for the SH/DH).

Can you say us which Arduino, Xbee, shield you use. It can help us to have more details

Thanatheos
  • 76
  • 8