Skip to content

Return acceleration as meter per second per second #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
caternuson opened this issue Nov 25, 2020 · 3 comments
Open

Return acceleration as meter per second per second #12

caternuson opened this issue Nov 25, 2020 · 3 comments

Comments

@caternuson
Copy link
Collaborator

Acceleration is currently returned as raw values. If a conversion can be found, use that to update returns to m^s to comply with CP Design Guide:
https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html#sensor-properties-and-units

@lesamouraipourpre
Copy link

https://web.archive.org/web/20090423001134/http://www.wiili.org/index.php/Wiimote/Extension_Controllers/Nunchuk

According to the page above, there is calibration data at 1g stored in the Nunchuk

@caternuson
Copy link
Collaborator Author

Interesting. Thanks! Gave that a quick test and it does seem to nominally work. Can use the 0g and 1g info to come up with a slope/offset to apply to the raw counts.

Copying info here in case information disappears into internet ether:

The Nunchuks calibration data is stored in a flash memory area at address 0x04A40020, and is repeated at 0x04A40030. Remember that the data needs to be decrypted using the algorithm above before it can be used. Sample data from the example above:

7D 7A 7E 0A B0 AF B1 12 E5 21 7C E7 23 7A FC 51
----------- ----------- -------- --------
0G values   1G values     Joy X    Joy Y
7D: Zero value of X-axis
7A: Zero value of Y-axis
7E: Zero value of Z-axis
0A: LSB of Zero value of X,Y,Z axes (in theory)
B0: 1G value of X-axis
AF: 1G value of Y-axis
B1: 1G value of Z-axis
12: LSB of 1G value of X,Y,Z axes (in theory)
E5: Joystick X-axis maximum
21: Joystick X-axis minimum
7C: Joystick X-axis center
E7: Joystick Y-axis maximum
23: Joystick Y-axis minimum
7A: Joystick Y-axis center

Bytes 0-3 store the zero values of the X, Y and Z axis, whereas bytes 4-7 store the values at 1G (earth gravitation). This is once again similar to the way the Wiimote stores it's calibration data.

Note, I have had trouble with the built-in calibration on the Nunchuk not always returning a total force of exactly 1g when the nunchuk is still in various orientations. The +1g seems to be correct, but the -1g values I calculate don't seem accurate enough. Perhaps the zero values of the built-in calibration aren't measured very well during manufacture, or I am misinterpretting the data somehow. CarlKenner 08:36, 1 March 2007 (EST)

Bytes 8-10 store the extremes and center position for the joystick's X axis, and bytes 11-13 store the values for the Y axis.

@caternuson
Copy link
Collaborator Author

Unfortunately, it looks like not all nunchuks have that information.

With an original nunchuk:

>>> nc._read_register(b"\x20")
bytearray(b'yyy \xad\xad\xad\x1b')

With a 3rd party clone:

>>> nc._read_register(b"\x20")
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')

Could easily check for this, but not sure what a good fall back behavior would be for nun's without cal info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants