Using the Mini I2C STEMMA QT Gamepad with Arduino involves wiring up the Gamepad to your Arduino-compatible microcontroller, installing the Adafruit_Seesaw library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the Gamepad VIN.
Here is an Adafruit Metro wired up to the Gamepad using the STEMMA QT connector:
-
Board 5V to Gamepad VIN (red wire)
-
Board GND to Gamepad GND (black wire)
-
Board SCL to Gamepad SCL (yellow wire)
- Board SDA to Gamepad SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to Gamepad VIN (red wire)
-
Board GND to Gamepad GND (black wire)
-
Board SCL to Gamepad SCL (yellow wire)
- Board SDA to Gamepad SDA (blue wire)
Library Installation
You can install the Adafruit_Seesaw library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for seesaw, and select the Adafruit seesaw Library library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
#include "Adafruit_seesaw.h" Adafruit_seesaw ss; #define BUTTON_X 6 #define BUTTON_Y 2 #define BUTTON_A 5 #define BUTTON_B 1 #define BUTTON_SELECT 0 #define BUTTON_START 16 uint32_t button_mask = (1UL << BUTTON_X) | (1UL << BUTTON_Y) | (1UL << BUTTON_START) | (1UL << BUTTON_A) | (1UL << BUTTON_B) | (1UL << BUTTON_SELECT); //#define IRQ_PIN 5 void setup() { Serial.begin(115200); while(!Serial) { delay(10); } Serial.println("Gamepad QT example!"); if(!ss.begin(0x50)){ Serial.println("ERROR! seesaw not found"); while(1) delay(1); } Serial.println("seesaw started"); uint32_t version = ((ss.getVersion() >> 16) & 0xFFFF); if (version != 5743) { Serial.print("Wrong firmware loaded? "); Serial.println(version); while(1) delay(10); } Serial.println("Found Product 5743"); ss.pinModeBulk(button_mask, INPUT_PULLUP); ss.setGPIOInterrupts(button_mask, 1); #if defined(IRQ_PIN) pinMode(IRQ_PIN, INPUT); #endif } int last_x = 0, last_y = 0; void loop() { delay(10); // delay in loop to slow serial output // Reverse x/y values to match joystick orientation int x = 1023 - ss.analogRead(14); int y = 1023 - ss.analogRead(15); if ( (abs(x - last_x) > 3) || (abs(y - last_y) > 3)) { Serial.print("x: "); Serial.print(x); Serial.print(", "); Serial.print("y: "); Serial.println(y); last_x = x; last_y = y; } #if defined(IRQ_PIN) if(!digitalRead(IRQ_PIN)) { return; } #endif uint32_t buttons = ss.digitalReadBulk(button_mask); //Serial.println(buttons, BIN); if (! (buttons & (1UL << BUTTON_A))) { Serial.println("Button A pressed"); } if (! (buttons & (1UL << BUTTON_B))) { Serial.println("Button B pressed"); } if (! (buttons & (1UL << BUTTON_Y))) { Serial.println("Button Y pressed"); } if (! (buttons & (1UL << BUTTON_X))) { Serial.println("Button X pressed"); } if (! (buttons & (1UL << BUTTON_SELECT))) { Serial.println("Button SELECT pressed"); } if (! (buttons & (1UL << BUTTON_START))) { Serial.println("Button START pressed"); } }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the seesaw firmware recognized by the code. Then, when you press any of the buttons or move the joystick, it will print to the Serial Monitor. You'll also see the interrupt LED light up with each button press.
For details on the concepts used in this example, check out Reading Joystick Values and Reading Button Presses on the CircuitPython and Python page in this guide.
Text editor powered by tinymce.