Giter Site home page Giter Site logo

todbot / wiichuck_adapter Goto Github PK

View Code? Open in Web Editor NEW
73.0 6.0 33.0 151 KB

Very simple adpater for hooking a Wii Nunchuck to your Arduino or other microcontroller

Home Page: http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/

Objective-C 84.23% Arduino 15.77%

wiichuck_adapter's Introduction

wiichuck_adapter's People

Contributors

todbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wiichuck_adapter's Issues

Inversion of LSB data read from the nunchuck

As I was working through your code for this, I noticed the way the LSBs for the accelerometer data were being decoded looked strange (This bug applies to the decoding of all three axes, X being used as an example here.)

Let's say nunchuck_buf[5] contains binary ----10-- (where '-' = don't care). If we shift off the first two bits and mask the rest we get binary 00000010, which should be the correct LSB for x. However, in your code:

    if ((nunchuck_buf[5] >> 2) & 1)        accel_x_axis += 2;
    if ((nunchuck_buf[5] >> 3) & 1)        accel_x_axis += 1;

This swaps the bits in the LSB, decoding it as 00000001.

To accomplish this without reversing the LSB bits:

Bit_Offset_x = 2;
LSB_x = (nunchuck_buf[5] >> Bit_Offset_x) & 3;

If we use uint16_t for the nunchuck_buf entries you can decode this more concisely:

Bit_Offset_x = 2;
accel_x_axis = ((nunchuck_buf[5] >> Bit_Offset_x) & 3) |
                        (nunchuck_buf[2] << 2);

(Bit_Offset_x is broken out for illustration in these examples)

Given how widespread your code is (and it's appreciated!) you'll find variations of this almost everywhere in the Arduino community. However, other platforms that use the Wii nunchuck decode the LSB normally, so I strongly suspect this is simply a longstanding bug.

Receiving from nunchuck only 255,255,0,0 values

I have a non-original nunchuck purchased off ebay, and when I am running the example sketch WiichuckDemo the values below are returned all the time. I woder if anyone managed to solve this problem?

accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0
accx: 255   accy: 255   zbut: 0 cbut: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.