Xbee and WM+

Hey everyone

So I have this project that works when I send serial over USB. I read a gyro (the Wii Motion Plus gyro with the Wire library) and send the data to processing.

When we try to send the data over the XBee to Processing, the gyro readings are all negative. Something must be conflicting when we add the XBee.

Does anyone have an answer to why this is happening? Is it a problem with I2C and XBee?

The XBee reads the TX pin, and broadcasts whatever it reads from that pin. Whatever it receives over-the-air is written to the RX pin of the Arduino.

I don't see any way for it to interfere with the other pins. A picture of your setup and seeing your code (Arduino and Processing) (and output) would help us troubleshoot your problem.

Thanks. This is the code I use to read the gyro values:

/* Activate Wii Motion +
______________________________________________________________________*/

void enableWii()
{
   Wire.beginTransmission(0x53);    //WM+ starts out deactivated at address 0x53
   Wire.send(0xfe);                 //send 0x04 to address 0xFE to activate WM+
   Wire.send(0x04);
   Wire.endTransmission();          //WM+ jumps to address 0x52 and is now active
}

/* Calibrate Wii
______________________________________________________________________*/

void calibrateWii()
{
  for (int i=0; i < 10; i++)
  {
    sendZeroWii();
    
    Wire.requestFrom(0x52,6);
    
    for (int i=0;i<6;i++)
    {
      data[i] = Wire.receive();
    }
    
    yaw0   += (((data[3]>>2)<<8)+data[0]) / 10;        //average 10 readings for each zero
    pitch0 += (((data[4]>>2)<<8)+data[1]) / 10;
    roll0  += (((data[5]>>2)<<8)+data[2]) / 10;
  }
}

/* Get data from Wii
______________________________________________________________________*/

void receiveData()
{
  sendZeroWii();                   //send zero before each request (same as nunchuck)
  Wire.requestFrom(0x52,6);        //request the six bytes from the WM+
  
  for(int i=0; i<6; i++)
  {
    data[i] = Wire.receive();
  }
  
  yaw   = ((data[3]>>2)<<8) + data[0] - yaw0;        //see http://wiibrew.org/wiki/Wiimote/Extension_Controllers#Wii_Motion_Plus
  pitch = ((data[4]>>2)<<8) + data[1] - pitch0;    //for info on what each byte represents
  roll  = ((data[5]>>2)<<8) + data[2] - roll0;      
}

/* Send 0 to communicate with wii
______________________________________________________________________*/

void sendZeroWii()
{
  Wire.beginTransmission(0x52);    //now at address 0x52
  Wire.send(0x00);                 //send zero to signal we want info
  Wire.endTransmission();
}

After that I just Serial.print the values.

I guess it must have something to do with the power consumption. Because if I keep the USB plugged in but transfer the data over XBee, I get the right values.

So it must be when I disconnect the USB and use a 12v power adapter that the problem appears?

I have a similar problem:

-Xbee shield works fine

-Arduino communicates through I2C with ultrasonic sensors, works fine. Arduino prints measurements to serial port, all fine.

--> put in Xbee shield to make forementioned arduino wireless... Ultrasonic sensors stop working, only intermittent I2C communication.

Did you find a solution?

regarinding, Lieven

Solved it.

The problem wasn't power. It was the Xbee configuration.

If you connect the Xbees with their 'DL' adress set to 'FFFF' (meaning, talk to absolutely any Xbee ) they are very slow. It seems the Wire buffer clogs up, as the serial message doesn't get through fast enough.

When I configured my Xbees to only talk to each other it solved the problem.(set 'DL' to the 'SL' of the other XBee, do the same with the 'DH' to 'SH' adress.)

Funny thing is; you can actually see the difference, as you can see the differience in speed of the RX/TX-leds blinking on the arduino.