MadCatz Nunchuk solution

Are there any features that you would like to add to the VESC?
barney
Posts: 22
Joined: 23 Dec 2015, 08:21

MadCatz Nunchuk solution

Postby barney » 27 Dec 2015, 17:55

Today i have tested the MadCatz Nunchuk with VESC. The receiver will hang for many seconds and brings no valid signal. I have the same problem with my controller. I found these solution:

@Benjamin

please add this line for MadCatz Nunchuks.

Code: Select all

// crypto key data address
 Nunchuk::_sendByte(0x40, 0x00);



Code: Select all

#define ADDRESS 0x52

void Nunchuk::init()
{     
  Wire.begin();
  // Initialize
  Nunchuk::_sendByte(0x55, 0xF0);
  Nunchuk::_sendByte(0x00, 0xFB);
}
   
void Nunchuk::update()
{
  byte count = 0;     
  unsigned int values[6];
  // crypto key data address
  Nunchuk::_sendByte(0x40, 0x00);
 
  Wire.requestFrom (ADDRESS, 6);
 
  while(Wire.available())
  {
    values[count] = Wire.read();
    count++;
  }
  Nunchuk::analogX = values[0];
  Nunchuk::analogY = values[1];     
  Nunchuk::accelX = values[2] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::accelY = values[3] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::accelZ = values[4] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::zButton = !((values[5] >> 0) & 1);
  Nunchuk::cButton = !((values[5] >> 1) & 1);
 
  Nunchuk::_sendByte(0x00, 0x00);
}

benjamin
Site Admin
Posts: 280
Joined: 15 Dec 2015, 08:38
Location: Sweden
Contact:

Re: MadCatz Nunchuk solution

Postby benjamin » 28 Dec 2015, 03:14

Thanks, I will have a look at adding that. Will this cause any trouble with the kama?

barney
Posts: 22
Joined: 23 Dec 2015, 08:21

Re: MadCatz Nunchuk solution

Postby barney » 28 Dec 2015, 07:47

benjamin wrote:Thanks, I will have a look at adding that. Will this cause any trouble with the kama?


I have no kama, but i have tested with:
* Hard wired Nunchuk (original)
* Logi3
* MadCatz

With no trouble.

barney
Posts: 22
Joined: 23 Dec 2015, 08:21

Re: MadCatz Nunchuk solution

Postby barney » 28 Dec 2015, 09:57

http://www.arduinoforum.de/arduino-Thre ... k-auslesen

To communicate with the Nunchuk, we must send a handshake signal.
If you are using a black Wii Nunchuk, send 2 bytes
0xF0, 0x55
to initialize the first register and
0xFB, 0x00
to initialize the second register of the Nunchuk.

On a white Wii Nunchuk, send
0x40, 0x00
followed by
0x00

The I2C address of both Wii Nunchuks is
0x52
The frequency used to communicate with the Wii Nunchuk is 100K


Byte 0x00 : X-axis data of the joystick
Byte 0x01 : Y-axis data of the joystick
Byte 0x02 : X-axis data of the accellerometer sensor
Byte 0x03 : Y-axis data of the accellerometer sensor
Byte 0x04 : Z-axis data of the accellerometer sensor
Byte 0x05 :
bit 0 as Z button status - 0 = pressed and 1 = release
bit 1 as C button status - 0 = pressed and 1 = release
bit 2 and 3 as 2 lower bit of X-axis data of the accellerometer sensor
bit 4 and 5 as 2 lower bit of Y-axis data of the accellerometer sensor
bit 6 and 7 as 2 lower bit of Z-axis data of the accellerometer sensor

barney
Posts: 22
Joined: 23 Dec 2015, 08:21

Re: MadCatz Nunchuk solution

Postby barney » 02 Jan 2016, 16:54

Hi Benjamin,

i have added 0x40, 0x00 in your source code but with no luck.
Normally, the Nunchuk is initialized only once and then only read.
But you seem at each query to do this and this seems to bring the MadCatz out of step. I must do some test with the Teensy 3.1 Board to look for the right Timing.

Barney

benjamin
Site Admin
Posts: 280
Joined: 15 Dec 2015, 08:38
Location: Sweden
Contact:

Re: MadCatz Nunchuk solution

Postby benjamin » 12 Jan 2016, 09:36

Hi Barney,

I ordered a used madcatz wireless nunchuk from ebay and experimented a bit with it based on the code you posted, but I could not get it running. It looks like the nunchuk does not even connect to the receiver and switches itself off after a minute or so. Maybe the one that I got is broken...

barney
Posts: 22
Joined: 23 Dec 2015, 08:21

Re: MadCatz Nunchuk solution

Postby barney » 12 Jan 2016, 10:30

The batteries last five MadCatz were defective. There are no LiPos.

http://www.elektro-skateboard.de/wiki/bambam/nunchuk-auf-lipo-umruesten

DeathCookies
Posts: 4
Joined: 06 Feb 2016, 18:25
Location: germany

Re: MadCatz Nunchuk solution

Postby DeathCookies » 06 Feb 2016, 18:30

Hey Barney,
can you tell me where to add this line? Is it the correct command because the source code on github seems really different from yours!

I do not think that vedder has completly reengineered the nunchuk code. Would be nice if you can explain me the big difference and where to add the code.

Thanks in advance!

barney
Posts: 22
Joined: 23 Dec 2015, 08:21

Re: MadCatz Nunchuk solution

Postby barney » 06 Feb 2016, 20:29

Code: Select all

/*
 * Based on ArduinoNunchuk.h changed wrong types removed unused Axes
 * 2014 Barney
 * ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
 *
 * Copyright 2011-2012 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following projects/websites:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 *
 */

#if (ARDUINO >= 100)
  #include <Arduino.h>
#else
  #include <WProgram.h>
#endif

#include <i2c_t3.h>
#include "NunchukTeensy.h"

#define ADDRESS 0x52

void Nunchuk::init()
{     
  // Setup for Master mode, pins 18/19, Internal pullups, 200kHz
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_200);
  // Initialize
  Nunchuk::_sendByte(0x55, 0xF0);
  Nunchuk::_sendByte(0x00, 0xFB);
}
   
void Nunchuk::update()
{
  byte count = 0;     
  unsigned int values[6];
  // crypto key data address
  Nunchuk::_sendByte(0x40, 0x00);
 
  Wire.requestFrom (ADDRESS, 6);
 
  while(Wire.available())
  {
    values[count] = Wire.readByte();
    count++;
  }
  Nunchuk::analogX = values[0];
  Nunchuk::analogY = values[1];     
  Nunchuk::accelX = values[2] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::accelY = values[3] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::accelZ = values[4] * 2 * 2 + ((values[5] >> 2) & 1) * 2 + ((values[5] >> 3) & 1);
  Nunchuk::zButton = !((values[5] >> 0) & 1);
  Nunchuk::cButton = !((values[5] >> 1) & 1);
 
  Nunchuk::_sendByte(0x00, 0x00);
}
 
void Nunchuk::_sendByte(byte data, byte location)

  Wire.beginTransmission(ADDRESS);
 
  #if (ARDUINO >= 100)
    Wire.write(location);
    Wire.write(data); 
  #else
    Wire.send(location);
    Wire.send(data);
  #endif
 
  Wire.endTransmission();
 
  delay(10);
}

DeathCookies
Posts: 4
Joined: 06 Feb 2016, 18:25
Location: germany

Re: MadCatz Nunchuk solution

Postby DeathCookies » 07 Feb 2016, 00:19

I am sorry, is this code a complete file or do i need to add it in any specific file?
Does it work with the MadCatz Nunchuk?


Return to “Feature Requests”

Who is online

Users browsing this forum: No registered users and 2 guests