Onion Omega2 Wii classic controller library
This library enables the Omega2(+) to communicate with a WiiClassic controller via I2C.
You will need:
- an Onion Omega2 or Omega2+, preferably with the extension dock
- a Wii classic controller
- an adapter board for the controller's connector (e.g., Adafruit's nunchucky)
- breadboard and wires
From the adapter board, connect GND to Omega's GND, VCC to 3.3V, Data to SDA and Clock to SCL. Do not insert the adapter the wrong way up, or else GND and 3.3V will be exchanged and your controller will be damaged through reverse polarity.
First, you need to initialize the controller by calling
WiiClassic_Init(). The functions returns a
bool which indicates the presence of the controller. For reading data, allocate a
wiiclassic_status_t object and give a pointer to it to
WiiClassic_ReadStatus(). Optionally printing the controler values by calling
WiiClassic_PrintStatus() or access the members of the
wiiclassic_status_t object directly.
/* Initializes the WiiClassic controller */ bool WiiClassic_Init(); /* reads the status of the WiiClass controller into the structure */ bool WiiClassic_ReadStatus(wiiclassic_status_t* status); /* prints the status to stdout */ void WiiClassic_PrintStatus(wiiclassic_status_t* status);
For an example, see the
main.c in this repository.
Buttons: A B Shoulder: L DPAD: UP Analog stick left/right: (1.000000, 0.500000), (0.500000, 0.500000)
This project was designed for cross-compliation. Compile your toolchain according to https://docs.onion.io/omega2-docs/cross-compiling.html, change the paths in the
TOOLCHAIN_ROOT_DIR) and do a
make all. Optionally,
make upload will attempt to use
scp to transfer the compiled binary to your Omega Onion2 system. Simply change the IP address and the password if you whish to use this feature.
For resons of simplicity, the header and library files for the I2C functionality has been included in this project. You can also compile the project by yourself (https://github.com/OnionIoT/i2c-exp-driver/).
make all, the library file
libwiiclassic.so and a executable file
main will be created. If you wish to to use the dynamic library in your own project, you have to:
- set the include path to where the
- set the library path to where the
libwiiclassic.soand the dependency
- set the linker flags to link your executable against the prementioned dependencies (
-lwiiclassic -lonioni2c -loniondebug)
See the Makefile of this project to see how a userspace program may be compiled and linked against this library.
Testing the compiled binaries
- Install the I2C library by typing
opkg update && opkg install libonion2cIf you already have that library, skip this step.
- Transfer the
libwiiclassic.sofile from this repository to the
/usr/lib/folder on your Omega2, e.g. by using
- Transfer the
mainfile (ELF) to some directory on your Omega2, e.g.
/root/and run it!
This library has only been tested with an original Nintendo Wii classic controller. Clones might or might not work.
- Maximilian Gerhardt, library porter
- Andrew Mascolo, original library
- Frank Zhao, for the instructable on the Wii classic