Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Wii Motion Plus


  • Please log in to reply
17 replies to this topic

#1 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 02 May 2011 - 11:18 PM

Hi all,

I'm trying to connect to a Wii Motion Plus via I2C.

I connected the Motion Plus to the Netduino:

White - Gnd
Red - 3V3
Green - Analog 4
Yellow - Analog 5

Followed the instructions at http://123a321.wordp...n-plus-via-i2c/ and tried the following:

var device = new I2CDevice(new I2CDevice.Configuration(0xa6, 400));
var transaction = I2CDevice.CreateWriteTransaction(new byte[] { 0xfe, 0x04 });
var transactions = new I2CDevice.I2CTransaction[] { transaction };
var sent = device.Execute(transactions, 100);

Unfortunately I'm getting an ArgumentException on the Execute. :huh:
Do you have any suspicion on what's wrong?
Is it possible to get more information on the exception? InnerException is null...

Thanks in advance,
aalmada <_<

#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 03 May 2011 - 06:27 AM

Unfortunately I'm getting an ArgumentException on the Execute

The slave address 0xA6 is out of range, the current implementation of I2C supports only 7-bit addressing and the address does not include read/write indicator bit. Try passing 0x52 instead.

#3 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 03 May 2011 - 09:16 AM

Hi,

The slave address 0xA6 is out of range, the current implementation of I2C supports only 7-bit addressing and the address does not include read/write indicator bit. Try passing 0x52 instead.


I'm trying to understand your suggestion.

0xA6 = 1010 0110
0x52 = 0101 0010

Setting just the left most bit of 0xA6 to zero:

0x26 = 0010 0110

Shouldn't it be 0x26?

I've been developing on C# since Beta 1 of .NET 1.0 but I'm new to .NET MF and I'm still learning what are the limitations. Are MF exceptions supposed to give so little information? :unsure:

Thanks,
aalmada

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 03 May 2011 - 09:47 AM

Setting just the left most bit of 0xA6 to zero:

No - you'd need to use only the left-most 7 bits for the slave address, it means removing 0. bit: 0xA6 >> 1 = 0x53 (101 0011). According to the article, Wii Motion Plus starts in 'repeater state' at that address, so 0x53 should be the correct value (0x52 should be used instead of 0xA4 in the 'motion sensing state', sorry).

#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 03 May 2011 - 10:02 AM

So, if I understand it correctly the code should be:

  // Initial address is 0x53
  var device = new I2CDevice(new I2CDevice.Configuration(0x53, 400));
  var transaction = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x04 });
  var transactions = new I2CDevice.I2CTransaction[] { transaction };
  var sent = device.Execute(transactions, 100);

  // Now the address is 0x52
  device.Config = new I2CDevice.Configuration(0x52, 400);

  //...

Edit: Removed Dispose() call, replaced with .Config assignment.

Edited by CW2, 03 May 2011 - 11:38 AM.


#6 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 03 May 2011 - 10:23 PM

Hi CW2, I found a better source of information and you were right. He uses the values you suggested. http://www.arduino.c...?num=1245723011 Unfortunately now I'm only receiving zeros... :( Thanks for taking the time to help me. aalmada

#7 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 05 May 2011 - 01:33 PM

Unfortunately now I'm only receiving zeros... :(


I'm new to the DIY electronics so I still have to learn a lot.

I researched a bit more on I2C and noticed the pull-up resistors at http://www.robot-ele...C_Tutorial.html

I added 1.5K resistors and now I get something. B)

aalmada

EDIT: The picture shows the pull-up resistors connected to 5V but since then I changed to 3V3 and it works fine. I read somewhere that this is the way it should be, as the analog pins are 3.3V on the Netduino. Unlike on the Arduino, where they are 5V.

Attached Files



#8 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 07 May 2011 - 05:10 PM

This is driving me mad!... :angry: It worked for a moment and now I can't make it work any more. I tried it without pull-up resistors, with pull-up resistors, several resistance values, at 3.3V, at 5V, and nothing... When I try on Arduino Duemilanove, it works in any configuration... :angry: Looking around this forum, I'm not the only have problems with I2C on Netduino. aalmada

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 May 2011 - 09:29 PM

You will need to use a pull-up resistor between 3.3V and the I2C data lines (both of them--clock and data) unless the slave device has appropriately selected I2C pull-ups already. Also...are you sure that the device supports 400KHz I2C? Have you tried 100KHz instead? I2C should work consistently...we just need to figure out what's not right. Do you have a logic analyzer by any chance? Chris

#10 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 09 May 2011 - 05:35 PM

Looking around this forum, I'm not the only have problems with I2C on Netduino.

Just a thought but what is the environment like for noise.

Not sure if this is relevant but I spent all weekend developing with no problems and came back to my kit tonight and nothing would work. This is identical setup to the previous day except for one thing. I had stopped using the trackball and started to use a radio mouse. Switched the radio mouse off and started to use a USB mouse and the kit sprang back to life.

May be a coincidence but would be interested to know if the bus is susceptable to RF noise. Let's face it, I'm prototpying so have plenty of flying leads connecting components and modern life leads to plenty of RF noise - WiFi, Bluetooth, mobile phone....

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#11 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 09 May 2011 - 10:36 PM

After many attempts on the Arduino and on the Netduino, I figured the problem had to be in the code.
Nunchuck has a simpler communication protocol so I decided to write a simple sample for both the Arduino and the Netduino. It kept working on the Arduino but failed in the Netduino... :unsure:

But when I replaced

device.Execute(new I2CDevice.I2CTransaction[] {
    I2CDevice.CreateWriteTransaction(new byte[] { 0x00 }),
    I2CDevice.CreateReadTransaction(buffer),
}, 100);
by
device.Execute(new I2CDevice.I2CTransaction[] {
    I2CDevice.CreateWriteTransaction(new byte[] { 0x00 }),
}, 100);
device.Execute(new I2CDevice.I2CTransaction[] {
    I2CDevice.CreateReadTransaction(buffer),
}, 100);

it started working... :o

Also...are you sure that the device supports 400KHz I2C? Have you tried 100KHz instead?


Yes, I'm sure it supports "fast" I2C.

Thanks for the help,
aalmada

#12 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 10 May 2011 - 04:28 AM

it started working... :o


I'm seeing the same thing, see this post here.

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#13 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 10 May 2011 - 05:42 AM

Quick question: is this I2C transaction one where the target device is expecting a "repeated start bit" condition? If so, that may be the (fluke) reason why the second method works. Also, some devices may require a bit of delay between the two calls...another reason why the second calling method works better. Do you have any quick documentation on the target device? If it's another issue, we'd like to make sure we get one in the lab to dig into this issue deeper. Chris

#14 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 10 May 2011 - 08:19 AM

I'm seeing the same thing, see this post here.


My didn't freeze, just got zero values. That's why I didn't relate the two issues.

Also, some devices may require a bit of delay between the two calls...


I suspect that's the reason...

Do you have any quick documentation on the target device? If it's another issue, we'd like to make sure we get one in the lab to dig into this issue deeper.


The device is easy to find, it's a Nintendo Nunchuck. The documentation I've been using is at the WiiBrew wiki (http://wiibrew.org/w...ion_Controllers) and used as a reference the code in the Boarduino/Nunchuck/Servo example (http://todbot.com/bl...nunchuck-servo/)

I plan to open-source the code, once I have everything sorted out.

Thanks for all the help,
aalmada

#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 10 May 2011 - 08:29 AM

Hi aalmada,

The device is easy to find, it's a Nintendo Nunchuck. The documentation I've been using is at the WiiBrew wiki (http://wiibrew.org/w...ion_Controllers) and used as a reference the code in the Boarduino/Nunchuck/Servo example (http://todbot.com/bl...nunchuck-servo/)

I understand now. It appears that there is no official documentation for the device (i.e. it was meant to be used for the Nintendo Wii...and us makers have figured out how to use it for other purposes).

Based on the Arduino sketch, it looks like the messages are sent separately...so it may be that the device isn't ready to respond right away. The strategy of executing the Read request separately seems to be consistent with the Arduino sketch. So I think you're probably good to go with your new code.

Chris

#16 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 09 June 2011 - 09:59 AM

I created a public repository at Bitbucket. You can now get my code at https://bitbucket.org/aalmada/hydramf

I'm still having problems with the Motion Plus but the Nunchuck and the Classic Controller are working.

Looking forward for feedback and contributions...

aalmada

#17 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 12 June 2011 - 10:07 AM

Uploaded my first NuGet package, HydraMF.Math, an algebra library for NETMF: http://nuget.org/Lis...es/HydraMF.Math

You can add HydraMF.Math to your project directly in Visual Studio with the NuGet Package Manager.

aalmada

#18 aalmada

aalmada

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 15 September 2012 - 11:36 PM

Hi,

I was never able to consistently connect to the Wiimote extensions. Now that I upgraded to 4.2 firmware, I'm now trying to use the "repeated start bit" feature.

I tried the following code with the Nunchuck but I'm always getting a buffer full of 0xff values (instead of the expected 0x00, 0x00, 0xa4, 0x20, 0x00, 0x00).


var device = new I2CDevice(new I2CDevice.Configuration(0x52, 400));

device.Execute(new I2CDevice.I2CTransaction[] { 
    CreateWriteTransaction(new byte[] { 0x55, }, 0xf0, 1),
    CreateWriteTransaction(new byte[] { 0x00, }, 0xfb, 1),
}, 1000);
Thread.Sleep(1000);
var buffer = new byte[6];
device.Execute(new I2CDevice.I2CTransaction[] { 
    CreateReadTransaction(buffer, 0xfa, 1),
}, 1000);


This is based on the info from http://wiibrew.org/w...ion_Controllers and using the "repeated start bit" methods from http://forums.netdui...rt-bit-support/

Am I doing it right?

EDIT: I'm using 3.3V for the VCC and 2.2K for pullup resistors.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.