Wii Nunchuck

Posted on
  • I have now tested my Wii Nunchuck on my Pico and esp8266, and now I have it running on both.
    I had to set the freq to 80 on esp8266 and put in a few delay's.

    // nunchuk_03 -     pico - esp8266-01
    //White:	Gnd  -  Gnd
    //Red:		3V3  -  Vdd
    //Yellow:	SCL  -  B6  -  D0
    //Green:	SDA  -  B7  -  D2
    function Wait(ms) {
      var a = Date().getTime() + ms;
      while(Date().getTime() < a) {}
    var d;
    var a;
    (function() {
      var tg = 0x2F; // 0x2F ^ 0x73 = 0x5C
      var esp8266 = true;
      if(esp8266) {
        // esp8266
        var ESP8266 = require('ESP8266');
        pinMode(D0, 'opendrain'); // scl
        pinMode(D2, 'opendrain'); // sda
      else {
        // pico
      // pico and esp8266-01
      var i2c = I2C1;
      i2c.writeTo(0x52, [0xF0, 0x55]);
      i2c.writeTo(0x52, [0xFB, 0x00]);
      setInterval(function() {
        i2c.writeTo(0x52, [0x00]);
        d = i2c.readFrom(0x52, 6);
        tg ^= 0x73;
        console.log(d, ' ', String.fromCharCode(tg));
          joy : {x:d[0],y:d[1]},
          acc : {x:(d[2]<<2)+((d[5]>>2)&3),
          btn : {z:!(d[5]&1),c:!(d[5]&2) }

    1 Attachment

    • picb.png
  • Another pic.

    1 Attachment

    • pica.png
  • ...I see your cycle consuming wait(n /*ms*/) function invocations... did ou think of an alternatives?... because this is kind of blocking the JS thread completely when the 500ms interval'd code runs.

    I know, it is not easy to inverse a function... and make it with multiple entry/resume points... but it should be possible... May be for this case it is not worth the effort.

  • No, my first goal, was to prove to get it working on esp8266-01.

  • by default PICO does 100KHz and ESP8266 does about 100KHz (80MHz) and 250kHz (160MHZ)

    @Frida please try again on PICO and use setup option bitrate:50000 and without Wait()

    Do not use bitrate option on ESP, I will reboot ......

  • @allObjects

    The code above has the wait for the setup part - there are no waits in the 500 interval?

  • Yes there are 1ms

  • The timings are OK, but you can't communicate with the device that is attached via I2C, right? Then you should check the circuit. Did you connect 4.7K pull-up resistors to both I2C lines?

  • Got a Wii Nunchuck

    Could not not find a adapter to hook up that thing

    How do you connect that little nice I2C device ?

  • I cut the wire, but there is:

  • thanks @Frida and @luwar

    I cut the wire :-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Wii Nunchuck

Posted by Avatar for Frida @Frida