Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Homepage
Gamecube Controller Interface¶
This is a library to interface the Gamecube Controller to the mbed. The goal of this project is to read input data from the controller.
Introduction¶
Wiring¶
Pinout¶
Color | Function |
---|---|
Yellow | 5V power supply (rumble) |
Red | Data: bi-directional / 3.3V |
Green | Ground |
White | Ground |
Blue | 3.3V power supply |
Note this pinout is for the latest Gamecube controller*
Gamecube Controller Protocol¶
The Gamecube controller uses 3.3V logic (bidirectional), 3.3V power, 5V rumble power.
The 5V power used by the rumble motor is always on, and the motor is controlled by a command sent to the controller.
The controller uses one bi-directional data line to communicate with the console. This is an active high 3.3V logic signal, using a pull-up resistor to hold the line high, and pulling it low with an open-collector transistor when a low needs to be transmitted. Communication is initiated by the console sending a 24-bit string to the controller, after which the controller responds with 64-bits of button state and joystick data.
The transfer speed is fast at around 4 microseconds per bit. .A low bit is signalled by a 3us low followed by 1us high, and a high bit is signalled by 1us low followed by 3us high.
Polling for Data¶
When the Gamecube or the controller sends a string of bits, it terminates it with a single (high) stop bit. Therefore, in order to send the string 00000000, the Gamecube would send 000000001.
There is a typical interval of about 6ms between successive updates. In fact, I believe that the update rate is controlled by the game, perhaps divided from the video frame rate. Each update lasts around 348us. The sequence starts with a 24-bit command from the console:
0100 0000 0000 0011 0000 0010
Example Code¶
Basic program to use with library
#include "mbed.h" #include "Gamecube.h" Serial pc1(USBTX, USBRX); // tx, rx DigitalOut myled(LED1); int main() { Gamecube g(p9); // gamecube controller connected to pin 9 int device_id = g.get_device_id(); if (device_id != NINTENDO_DEVICE_GC_WIRED) { pc1.printf("this device is not a nintendo gamecube wired controller!, it returned an ID of %d\n", device_id); } while(1) { g.update(); pc1.printf("A: %d \n\rB: %d \n\rX: %d \n\rY: %d \n\rL: %d \n\rR: %d \n\rZ: %d \n\rSTART: %d \n\rD_UP: %d \n\rD_LEFT: %d \n\rD_DOWN: %d \n\rD_RIGHT: %d \n\rJOYSTICK_X: %d \n\rJOYSTICK_Y: %d \n\rC_STICK_X: %d \n\rC_STICK_Y: %d \n\rLEFT_TRIGGER: %d \n\rRIGHT_TRIGGER: %d \n\r", g.A, g.B, g.X, g.Y, g.L, g.R, g.Z, g.START, g.D_UP, g.D_LEFT, g.D_DOWN, g.D_RIGHT, g.JOYSTICK_X, g.JOYSTICK_Y, g.C_STICK_X, g.C_STICK_Y, g.LEFT_TRIGGER, g.RIGHT_TRIGGER); wait(1); g.rumble(true); // rumble working myled = 1; wait(1); myled = 0; g.rumble(false); wait(.2); } }