moefh / esp32-wii-nunchuk

Wii Nunchuk Controller I2C library for the ESP32
MIT License
7 stars 2 forks source link

Nunchuk XY analog joystick not work #2

Open marshalab opened 2 years ago

marshalab commented 2 years ago

Hello. I tried your library and found that reading the joystick does not work. Data is always 0. For some reason, after reading wii_i2c_decode_nunchuk, data[0] data[1] is always 128. At the same time, the accelerometer and C Z buttons work well.

state->x = data[0] - (1<<7); state->y = data[1] - (1<<7); ?

pure data: data: 80 80 7e 6a a7 c2 data: 80 80 7e 6a b1 c7 data: 80 80 7e b8 9b 47 data: 80 80 7e 72 cd 47 data: 80 80 7e 60 99 47 data: 80 80 7e 76 b5 c7 data: 80 80 7e 84 93 87 data: 80 80 7e 86 93 47 data: 80 80 7e 86 93 47

Physically, the joystick works. I used it with M5stick-C, but now I'm redoing the project and looking for another library.

moefh commented 2 years ago

Can you give more information? Are you using the example code from the README, or a custom program? Are those 0x80 in the pure data printed even while you're moving the analog stick of the nunchuk left and right?

About that code you quoted: the first byte returned by the nunchuck via i2c (data[0]) is the X value of the stick: 0 means full left and 255 means full right, so 128 (0x80) is center (stick not being moved). The same principle applies to the Y axis with data[1].

So the decode code does this:

state->x = data[0] - (1<<7);

to put a signed value in state->x, so:

So it seems everything is working right, except that your nunchuk is always returning "centered" for the analog stick position. Without knowing more details, it's hard to guess why that would be (especially since the I2C communication seems to be working well and the other bytes look like proper values).

marshalab commented 2 years ago

I using esp32-wii-nunchuk.ino with little mod for view pure data

    switch (controller_type) {
//    case WII_I2C_IDENT_NUNCHUK: show_nunchuk(data); break;
//    case WII_I2C_IDENT_CLASSIC: show_classic(data); break;
    default:
      Serial.printf("data: %02x %02x %02x %02x %02x %02x\n",
                    data[0], data[1], data[2], data[3], data[4], data[5]);
      break;

My nunchuk is chines clone. But it worked with a different ArduinoNano firmware. As soon as I find another I will check the probability of breakage. During the tests, of course, I turned the stick, but the data does not change.

Result i2c sniffer:

0.492944000000000,I2C,Setup Read to [0xA5] + ACK 0.493044000000000,I2C,0x80 + ACK 0.493140000000000,I2C,0x80 + ACK 0.493236500000000,I2C,0x7E + ACK 0.493332500000000,I2C,0x8C + ACK 0.493428500000000,I2C,0x9D + ACK 0.493526000000000,I2C,0xC3 + NAK 0.493716000000000,I2C,Setup Write to [0xA4] + ACK 0.493811000000000,I2C,0x00 + ACK

You may see more meyans in these results. Analysis of the messages shows that the joystick data is 0x80. But the joystick itself changes position. It is possible that it is broken, and perhaps the Chinese clone is initialized differently. I think to check it by connecting it to Arduino Nano. I haven't really figured it out yet, but I immediately decided to share the result. I will continue searching tomorrow.

marshalab commented 2 years ago

My nunchuk always work ! Tested on Arduino nano with level shifter and NintendoExtensionCtrl library. Nunchuk - Joy:( 14, 127) | Accel XYZ:( 512, 544, 790) | Buttons: -Z Nunchuk - Joy:( 14, 127) | Accel XYZ:( 513, 544, 790) | Buttons: -Z Nunchuk - Joy:( 14, 127) | Accel XYZ:( 513, 544, 782) | Buttons: -Z

But it turns out that not everything is simple with nunchuk libraries. They are all tied to a specific platform, be it atmega stm32 esp...