Skip to content

A library with which one can use a Wii classic controller with the Omega2.

License

Notifications You must be signed in to change notification settings

gamer-cndg/omega2-wii-classic-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Onion Omega2 Wii classic controller library

Description

This library enables the Omega2(+) to communicate with a WiiClassic controller via I2C.

Hardware Wireup

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.

Library Usage

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.

Example output

Buttons: A B
Shoulder: L 
DPAD: UP 
Analog stick left/right: (1.000000, 0.500000), (0.500000, 0.500000)

Compilation

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 Makefile (TOOLCHAIN_ROOT_DIR) and do a make all. Optionally, make upload will attempt to use sshpass with 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/).

After executing 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:

  1. set the include path to where the WiiClassic.h is (-I somedir)
  2. set the library path to where the libwiiclassic.so and the dependency libonioni2c.so and liboniondebug.so is (-L somelibdir)
  3. 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

  1. Install the I2C library by typing opkg update && opkg install libonion2c If you already have that library, skip this step.
  2. Transfer the libwiiclassic.so file from this repository to the /usr/lib/ folder on your Omega2, e.g. by using ssh or scp.
  3. Transfer the main file (ELF) to some directory on your Omega2, e.g. /root/ and run it!

Compatibility

This library has only been tested with an original Nintendo Wii classic controller. Clones might or might not work.

Credits

hardware setup example execution

About

A library with which one can use a Wii classic controller with the Omega2.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published