{"id":17624857,"url":"https://github.com/anseljh/raspi-nunchuck","last_synced_at":"2025-08-22T12:32:30.261Z","repository":{"id":69009657,"uuid":"326397174","full_name":"anseljh/raspi-nunchuck","owner":"anseljh","description":"A Python class for using a Wii Nunchuck from a Raspberry Pi","archived":false,"fork":false,"pushed_at":"2021-01-05T10:33:35.000Z","size":7,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-02T04:23:23.074Z","etag":null,"topics":["raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anseljh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-03T12:02:31.000Z","updated_at":"2024-06-02T15:07:58.000Z","dependencies_parsed_at":"2023-05-14T16:15:47.998Z","dependency_job_id":null,"html_url":"https://github.com/anseljh/raspi-nunchuck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseljh%2Fraspi-nunchuck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseljh%2Fraspi-nunchuck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseljh%2Fraspi-nunchuck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseljh%2Fraspi-nunchuck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anseljh","download_url":"https://codeload.github.com/anseljh/raspi-nunchuck/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230593264,"owners_count":18250384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raspberry-pi"],"created_at":"2024-10-22T22:06:05.057Z","updated_at":"2024-12-20T13:40:25.766Z","avatar_url":"https://github.com/anseljh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raspi-nunchuck\n\nA Python 3 class for using a Wii nunchuck controller with a Raspberry Pi\n\n## What's this?\n\n**Who *wouldn't* want to remotely control a robot with a [Wii Nunchuk™ controller](https://store.nintendo.com/nunchuk-wii-u-wii-wii-mini.html)?**\n\nThere are lots of examples out there of working with these nunchucks with Arduino microcontrollers, but what are we, animals? Dear reader, you and I are more civilized than that. We program our robots in Python!\n\n## How does it work?\n\n### Prepare your Pi\n\nBefore anything else, you need to activate the I\u003csup\u003e2\u003c/sup\u003eC bus on your Raspberry Pi. Run the `raspi-config` tool:\n\n```shell\nsudo raspi-config\n```\n\nSelect `Interface Options`, and then `I2C`.\n\nNext, install the `smbus` module for Python, on which this code depends:\n\n```shell\nsudo apt install python3-smbus\n```\n\n### Using the code\n\nIn your Python code, create an instance of the `Nunchuck` class. Pass it three callback functions: one each for changes in the state of the C and Z buttons, and another to be called continuously.\n\nWhen you're ready, call the `start()` method. This launches a thread that polls your nunchuck and calls your callbacks.\n\n```python\nnunchuck = Nunchuck(cb_c, cb_z, cb)\nnunchuck.start()\n```\n\nCallback functions accept an instance of `NunchuckState`, which simply holds the following properties:\n\n* `stick`: 2-tuple of integers for position of the joystick\n* `accel`: 3-tuple of integers for position of the accelerometer\n* `button_c`: Boolean for whether the C button is pressed\n* `button_z`: Boolean for whether the Z button is pressed\n\nHere's what a simple Z-button callback could look like:\n\n```python\ndef cb_z(state: NunchuckState):\n    if state.button_z:\n        print(\"** ZOT **\")\n```\n\nOnce you do that, you can get output like this:\n\n```\nNunchuckThread.run(): Reading nunchuck...\n\u003cNunchuck 0x52 \u003cstick (193, 193) accel (118, 124, 174) B False C True\u003e\u003e\n** ZOT **\nRIGHT\nFORWARD\n```\n\n## Can I install this with `pip`?\n\nNot yet. Maybe later.\n\n## What hardware and software does this work on?\n\nThis was developed and tested on a [Raspberry Pi Zero W](https://www.raspberrypi.org/pi-zero-w/) running [Rasperry Pi OS Lite](https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit) (Debian Buster). It *should* work on any Raspberry Pi model as long as you activate the I\u003csup\u003e2\u003c/sup\u003eC bus.\n\nIf you test this on other hardware and it works, please submit an issue or PR to let me know, and I'll update this documentation.\n\n## Can I use this with Legacy Python, also known as Python 2?\n\nNo. You should really use modern Python 3.\n\nThis code was developed and tested on Python 3.7, which ships with the current version of Raspberry Pi OS.\n\n## Is this code stable?\n\nNo. Maybe later. Maybe not! Your mileage may vary.\n\n## How's this code licensed?\n\nThank you for asking! This code is under the MIT License.\n\n## Who wrote this?\n\nThis code is by Ansel Halliburton, who is a lawyer and software developer. You can find him on [GitHub](https://github.com/anseljh) or [Twitter](https://twitter.com/anseljh).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanseljh%2Fraspi-nunchuck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanseljh%2Fraspi-nunchuck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanseljh%2Fraspi-nunchuck/lists"}