The Adafruit NeoKey 1x4 QT I2C uses the Seesaw chip. To use the NeoKey 1x4 with Arduino, you'll use the Adafruit Seesaw library. With the key sockets and the STEMMA QT connectors, you can easily get started with no soldering necessary!
I2C Wiring
Here is how to wire up the breakout using one of the STEMMA QT connectors. The examples show a Metro but wiring will work the same for an Arduino or other compatible board.
- Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect board GND (black wire) to Arduino GND
- Connect board SCL (yellow wire) to Arduino SCL
- Connect board SDA (blue wire) to Arduino SDA
Here is how to wire the breakout to a board using a solderless breadboard. To do this, you must solder the header pins provided to the breakout.
- Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect board GND (black wire) to Arduino GND
- Connect board SCL (yellow wire) to Arduino SCL
- Connect board SDA (blue wire) to Arduino SDA
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:
When asked to install the Adafruit Seesaw library dependencies, click Install all.
After opening the basic_neoswirl file, upload it to the Arduino wired to your NeoKey 1x4. Open the Serial Monitor at 115200 baud. You should see the following as the sketch starts up.
Now try pressing the keys to see the corresponding NeoPixel light up, and a message printed to the serial output!
That's all there is to using the NeoKey 1x4 breakout with Arduino!
#include "Adafruit_NeoKey_1x4.h" #include "seesaw_neopixel.h" Adafruit_NeoKey_1x4 neokey; void setup() { Serial.begin(115200); while (! Serial) delay(10); if (! neokey.begin(0x30)) { Serial.println("Could not start NeoKey, check wiring?"); while(1) delay(10); } Serial.println("NeoKey started!"); for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) { neokey.pixels.setPixelColor(i, Wheel(map(i, 0, neokey.pixels.numPixels(), 0, 255))); neokey.pixels.show(); delay(50); } for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) { neokey.pixels.setPixelColor(i, 0x000000); neokey.pixels.show(); delay(50); } } uint8_t j=0; // this variable tracks the colors of the LEDs cycle. void loop() { uint8_t buttons = neokey.read(); for (int i=0; i< neokey.pixels.numPixels(); i++) { neokey.pixels.setPixelColor(i, Wheel(((i * 256 / neokey.pixels.numPixels()) + j) & 255)); } if (buttons & (1<<0)) { Serial.println("Button A"); } else { neokey.pixels.setPixelColor(0, 0); } if (buttons & (1<<1)) { Serial.println("Button B"); } else { neokey.pixels.setPixelColor(1, 0); } if (buttons & (1<<2)) { Serial.println("Button C"); } else { neokey.pixels.setPixelColor(2, 0); } if (buttons & (1<<3)) { Serial.println("Button D"); } else { neokey.pixels.setPixelColor(3, 0); } neokey.pixels.show(); delay(10); // don't print too fast j++; // make colors cycle } /******************************************/ // Input a value 0 to 255 to get a color value. // The colors are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { if(WheelPos < 85) { return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if(WheelPos < 170) { WheelPos -= 85; return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3); } return 0; }
Using Multiple NeoKey 1x4 Breakouts
The address jumpers on the back of the NeoKey 1x4 breakout enable you to chain together up to 16 of these breakouts on a single I2C bus. This example shows how to connect two and use them together.
This example requires minimal soldering.
Address Jumper Soldering
Use solder to bridge the A0 jumper (highlighted in green below) on the back of the board.
I2C Wiring
Here is how to wire up two breakouts using the STEMMA QT connectors. The examples show a Metro but wiring will work the same for an Arduino or other compatible board.
- Connect board one VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect board one GND (black wire) to Arduino GND
- Connect board one SCL (yellow wire) to Arduino SCL
- Connect board one SDA (blue wire) to Arduino SDA
- Connect board one STEMMA QT to board two STEMMA QT using a STEMMA QT cable such as this or this.
Library Installation
The library installation is the same as above. If you have not already, follow the library installation instructions above before continuing.
Load Multi-Key Example
Open up File -> Examples -> Adafruit seesaw Library -> NeoKey_1x4 -> basic_multikey.
After opening the basic_multikey file, upload it to the Arduino wired to your pair of NeoKey 1x4 breakouts. Open the Serial Monitor at 115200 baud.
Try pressing the keys to see the corresponding NeoPixel LEDs light up, and messages printed to the serial monitor on key press and release.
#include "Adafruit_NeoKey_1x4.h" #include "seesaw_neopixel.h" #define Y_DIM 2 //number of rows of keys #define X_DIM 4 //number of columns of keys // create a matrix of NeoKey 1x4's // this example is just two, one on top of another to make a 2x4 grid Adafruit_NeoKey_1x4 nk_array[Y_DIM][X_DIM/4] = { { Adafruit_NeoKey_1x4(0x30) }, { Adafruit_NeoKey_1x4(0x31) }, }; // pass this matrix to the multi-neokey object Adafruit_MultiNeoKey1x4 neokey((Adafruit_NeoKey_1x4 *)nk_array, Y_DIM, X_DIM/4); void setup() { Serial.begin(115200); while (! Serial) delay(10); if (! neokey.begin()) { // start matrix Serial.println("Could not start NeoKeys, check wiring?"); while(1) delay(10); } Serial.println("NeoKey started!"); // Pulse all the LEDs on to show we're working for (uint16_t i=0; i< X_DIM*Y_DIM; i++) { neokey.setPixelColor(i, 0x808080); // make each LED white neokey.show(); delay(50); } for (uint16_t i=0; i< X_DIM*Y_DIM; i++) { neokey.setPixelColor(i, 0x000000); neokey.show(); delay(50); } // activate all keys and set callbacks for(int y=0; y<Y_DIM; y++){ for(int x=0; x<X_DIM; x++){ neokey.registerCallback(x, y, blink); } } } void loop() { neokey.read(); delay(10); // don't print too fast } //define a callback for key presses NeoKey1x4Callback blink(keyEvent evt) { uint8_t key = evt.bit.NUM; if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) { Serial.print("Key press "); Serial.println(key); neokey.setPixelColor(key, Wheel(map(key, 0, X_DIM*Y_DIM, 0, 255))); } else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) { Serial.print("Key release "); Serial.println(key); neokey.setPixelColor(key, 0); } // Turn on/off the neopixels! neokey.show(); return 0; } /******************************************/ // Input a value 0 to 255 to get a color value. // The colors are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { if(WheelPos < 85) { return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if(WheelPos < 170) { WheelPos -= 85; return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3); } return 0; }
Page last edited January 22, 2025
Text editor powered by tinymce.