WII Controller

I am testing out a Wii Nunchuck with the FEZ_Components_Wii.cs library and am getting some unexpected results.

My wires are connected to the Domino like so:
Ground to Ground
Power to 5V
SDA to Di2
SCL to Di3

I placed some Debug statements in the Reset() method of class FEZ_Components_Wii like so:
Debug.Print(“Failed to connect”);
Debug.Print(“Connection to Wii Controller Established”);

Here is some sample the output. Notice that the XY values never change and the “Failed to Connect” repeats excessively even though I see the connect message happening. I also don’t understand the other output regarding the Type and Bytes.

I am hoping someone can tell me something about this. Thanks

Failed to connect
Failed to connect
Failed to connect
Failed to connect
Connection to Wii Controller Established
GC: 3msec 28320 bytes used, 36060 bytes available
Type 0F (STRING ): 144 bytes
Type 11 (CLASS ): 1884 bytes
Type 12 (VALUETYPE ): 204 bytes
Type 13 (SZARRAY ): 1884 bytes
Type 15 (FREEBLOCK ): 36060 bytes
Type 17 (ASSEMBLY ): 19116 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 768 bytes
Type 20 (SUBTHREAD ): 96 bytes
Type 21 (STACK_FRAME ): 636 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 144 bytes
Type 31 (IO_PORT ): 108 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 2460 bytes
Analog X: 129 Analog Y: 132 Accel X: 523 Accel Y: 523
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Failed to connect
Analog X: 129 Analog Y: 132 Accel X: 523 Accel Y: 523
Failed to connect

The “Type and Bytes” output is produced by garbage collector. You can disable it. As far as nunchuck, please show the code.

Is this a wired or wireless nunchuck?

Thank you for looking at my post. Below are some code snippets. Can the Architect please describe the disabling of the GC messages? I am using a wired Nunchuck. Thanks

// From Program.cs

public static void Main()
{

while (true)
{
Debug.Print(" Analog X: " + FEZ_Components.Wii.Nunchuk.AnalogStickX + " Analog Y: " +
FEZ_Components.Wii.Nunchuk.AnalogStickY +
" Accel X: " + FEZ_Components.Wii.Nunchuk.AccelerateX + " Accel Y: " + FEZ_Components.Wii.Nunchuk.AccelerateY);

Thread.Sleep(500);

}
}

//From FEZ_Components_Wii.cs
// The only thing I edited from the download are the debug statements
// that indicate connection is made or not.

public static bool Reset()
{
// Initialize NumChuck by sending 0x40, 0x00
I2CDevice.I2CTransaction[] NumChuckInitializeTrans = new I2CDevice.I2CTransaction[1];
NumChuckInitializeTrans[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x40, 0x00 });
if (NumChuckDevice.Execute(NumChuckInitializeTrans, 100) == 0)
{
Debug.Print(“Failed to connect”);
Connected = false;
return false;
}
else
{
Debug.Print(“Connection to Wii Controller Established”);
Connected = true;
return true;
}
}

Let us “code tag” the code so it is easy to read :slight_smile: please do that on future posts
Are you using the wiii connector component from this website?

// From Program.cs

public static void Main()
{
	
  while (true)
  {
  	Debug.Print(" Analog X: " + FEZ_Components.Wii.Nunchuk.AnalogStickX + " Analog Y: " +
		FEZ_Components.Wii.Nunchuk.AnalogStickY +
		" Accel X: " + FEZ_Components.Wii.Nunchuk.AccelerateX + " Accel Y: " + FEZ_Components.Wii.Nunchuk.AccelerateY);

	Thread.Sleep(500);
  }
}

//From FEZ_Components_Wii.cs
// The only thing I edited from the download are the debug statements
// that indicate connection is made or not.

public static bool Reset()
{
  // Initialize NumChuck by sending 0x40, 0x00
  I2CDevice.I2CTransaction[] NumChuckInitializeTrans = new I2CDevice.I2CTransaction[1];
  NumChuckInitializeTrans[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x40, 0x00 });
  if (NumChuckDevice.Execute(NumChuckInitializeTrans, 100) == 0)
  {
	Debug.Print("Failed to connect");
	Connected = false;
	return false;
  }
  else
  {
	Debug.Print("Connection to Wii Controller Established");
	Connected = true;
	return true;
  }
}

Looks like you didn’t initialize the driver

Just copy paste the code from the brochure http://www.tinyclr.com/downloads/Component/Broch_Wii.pdf

Looked on fezzer and the code is there too :wink:
http://www.fezzer.com/project/17/wii-controller-interface/

Gus is right!

Add this line before the while(true) loop in the Main()

FEZ_Components.Wii.Nunchuk.Initialize();

To disable the GC message, you can add this line in your code.

Debug.EnableGCMessages(false);

The initialize is above the while loop which I omitted for brevity.


// This demo is for the Nunchuk controller. If you are using Classic controller then
// replace FEZ_Components.Wii.Nunchuk with FEZ_Components.Wii.ClassicController
FEZ_Components.Wii.Nunchuk.Initialize();
// blink LED with speed according to Nunchuk analog stick Y position
// Remember to add the LED component driver
FEZ_Components.LED OnboardLED = new FEZ_Components.LED(FEZ_Pin.Digital.LED);

The Initialize code uses and Addres of 0x52 and a clock of 100khz. Can someone tell me where those values come from and why they are hard-coded?


public static void Initialize()
	{
		// Create I2C Device for NumChuck
		// Address: 0x52
		// Clock: 100Khz
		NumChuckDevice = new I2CDevice(new I2CDevice.Configuration(0x52, 10));
	
                // Start thread that monitors NumChuck
		ReadNumChuck = new Thread(new ThreadStart(ReadNumChuckDataThread));
		ReadNumChuck.Priority = ThreadPriority.BelowNormal;
		ReadNumChuck.Start();
	}

They are what the wii controller use

All I2C devices have manufacturer assign address, Wii has 0x52,
real time clock DS1307 has address = 0x68, etc.
It is some kind of ID so the master and slave could communicate since all the I2C devices use the same SCL and SDA pins.
You can find out more about the I2C in the Beginner e-Book, page 83

http://www.tinyclr.com/downloads/Beginners%20guide%20to%20NETMF.pdf

Thanks for the info on the ID’s. I was wondering if they were preassigned by the Mfg or assigned by the software running the bus.

I am still having trouble keeping and maintaining connections. When I do have connection I always have the same values.

Are Di2 and Di3 the only pins that can be used for I2C? What else should I be looking for? All ideas welcome. Thank you.

Are you using the component shield? Can you take a picture of your setup?

No component shield. I am just plugging the wires directly to the pin holes on the domino. I’ll take a photo later tonight thanks.

Here is how I am wiring the Domino.

This is the circuit board for the Wii.

Looking at this today I noticed some charing around the chip.
I think what happened is that because this is an after market Wii controller from MonoPrice.com it may not like the higher voltage like the official Nintendo controller tolerates. As such mine if fried. :frowning:

I ordered another one but will need to add a resistor to the power pin to reduce the voltage.

All thoughts are appreciated. Thank you.

Chiloyago:

Oh, No!
If I knew before hand, that you gonna do some mod. inside the Wii, I would recommend this:

[url]http://www.sparkfun.com/products/9281[/url]

A lot easier and no hacking!!! :frowning:

I ordered one yesterday but the problem of the voltage remains. I need to add a resistor to the 5.5V out pin so I don’t blow the Nunchuck again.