![]() |
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 */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 */Thanks in advance to anyone that can assist us. Kyle |
Re: I2C Arduino Port (Wii MotionPlus)
Kyle,
I'll take a shot at this. My experience is with I2C in Java and an Arduino, but most of that should apply here. First, if you are using an address of 0x52 on an Arduino to communicate with the Wii MotionPlus, then you will most likely need to use an address of 0xA4 on the cRio. Your code doesn't show how you are setting up the I2C object. For the "receiveing data" portion, you should be able to use the following code to just receive data. Code:
_wmp->Transaction(0x00, 0, buffer, sizeof(buffer));Mike |
Re: I2C Arduino Port (Wii MotionPlus)
Quote:
Thanks Kyle |
Re: I2C Arduino Port (Wii MotionPlus)
Kyle,
The I2C specification calls out for a 7 bit device address (there is also a 10 bit address, but that doesn't apply here), along with a single bit to indicate read/write. This information is combined where the address is the high 7 bits and the read/write is the LSB as shown below, where 'A' indicates an address bit and R indicates the read/write bit (write is 0, read is 1) Code:
Bit (MSB) 76543210 (LSB)Hopefully this makes sense. Mike For reference, I found the I2C bus specification here : http://www.nxp.com/documents/user_manual/UM10204.pdf |
Re: I2C Arduino Port (Wii MotionPlus)
Your explanation of the addresses makes sense and clears things up.
I realized I misread your first post and didn't catch the difference between your snippet and mine. Quote:
Quote:
Thanks Kyle |
Re: I2C Arduino Port (Wii MotionPlus)
Kyle,
Quote:
Mike - You may also want to verify if the transmit data (buffer) needs to be passed as an address to a byte array. I know in Java this is true. |
Re: I2C Arduino Port (Wii MotionPlus)
Thanks for all the help. We had moderate success tonight.
The biggest thing that we never would have figured out was the addressing. On the Arduino you have to initialize the Wii MotionPlus on 0x53. Then communicate with it on 0x52. When switching to the cRio we initially were trying to initialize it at 0xa5 and then communicate with it on 0xa4. Thanks to your advice we figured out it needed to be 0xa6 and 0xa4. We were having a load of problems with execution hanging at the Transaction call. After separating it out into 7 separate transactions. 1 write and 6 reads things smoothed out. Some additional searching on chief delphi leads us to believe that WPILib only supports reading or writing 4 bytes at a time. The comments in the source indicate 7 so that was mildly frustrating. At this point I think we have it working. Provided we end up going this route once we get the code cleaned up and all the bugs worked out we hope to share our seemingly robust wrapper for the Wii MotionPlus with the rest of the first community. Thanks Again!!! Kyle |
Re: I2C Arduino Port (Wii MotionPlus)
Kyle,
Glad to hear you are making progress. If you could post what you are (or are not seeing) when you try transactions > 4 bytes, perhaps I could help. The cRio should be able to communicate in up to 7 byte transactions (at least it was able to last year). One thing you could try is to call "setCompatibilityMode(true)" on the I2C object. This will probably not do anything as I read that it was set to TRUE by default this year (unlike last year), but it won't hurt to try. I also had some initial issues last year with Java and the bytes > 4 (wrong data), but that was specific to Java and should be corrected this year. Mike |
Re: I2C Arduino Port (Wii MotionPlus)
When trying to troubleshoot the lockups we slowly broke the following line into multiple calls.
Code:
_wmp->Transaction(0x00, 1, &buffer[0], sizeof(buffer));Code:
printf("I2C Write\n");Code:
...We ended the night with the following code and had successfully run 5 minutes with no lockups. That may just be a coincidence Code:
_wmp->Transaction(0x00, 1, 0, 0);Kyle |
Re: I2C Arduino Port (Wii MotionPlus)
Kyle,
It's interesting that it hangs on the read transaction. The actual I2C communication is handled by the FPGA so it's a little difficult to know exactly what is happening. Normally, I would expect the transaction to return an error if it couldn't complete. My only thought is that the Wii MotionPlus is holding the clock signal low preventing the transaction from completing. Removing power from the Wii would allow the clock to resume. There are two things I can suggest you try. First, the transaction routine expects a pointer to a byte array for the "dataToSend" argument. So I think your 0x00 in the send transmission is getting converted to a pointer to memory address 0x00 rather than a value of zero. Try changing to the following: Code:
uint8_t sendBuffer[1]={0};Code:
_wmp->setCompatibilityMode(TRUE);Mike |
Re: I2C Arduino Port (Wii MotionPlus)
Quote:
|
| All times are GMT -5. The time now is 12:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi