View Single Post
  #1   Spotlight this post!  
Unread 03-02-2014, 07:59
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
I2C Arduino Port (Wii MotionPlus)

I'll start off by saying prior to this season our team has had no prior knowledge of I2C.

We successfully were able to talk to a LSM303D using the standard calls in the WPILib I2C class.

We are now trying to integrate with a Wii MotionPlus. We have a working setup with an Arduino. In hopes of eliminating the Arduino we tried to port the Arduino sketch to C++. Our limited knowledge of I2C has made this a little bit of a challenge.

Code:
/* Arduino */
void receiveData(){
  Wire.beginTransmission(0x52);    //now at address 0x52
  Wire.send(0x00);		     //send zero to signal we want info
  Wire.endTransmission();
  nunchuck)
  Wire.requestFrom(0x52,6);	  //request the six bytes from the WM+
  for (int i=0;i<6;i++){
    data[i]=Wire.receive();
  }
}
I realize there is additional initialization that needs to happen. But that is straight forward. The 2 new concepts that the LSM303D did not require but that the Wii MotionPlus does are:
1. Sending data over I2C with no register as a target.
2. Receiving data over I2C with out a particular register as a source.

Code:
/* WPILib */
        // _wmp is an instance of I2C
	uint8_t buffer[6];
	_wmp->Transaction(0x00, 1, buffer, sizeof(buffer);
Are these code snippets functionally equivalent? If not what are the equivalent of requestFrom() and read() in the WPILib?

Thanks in advance to anyone that can assist us.

Kyle
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote