Built-in project · SparkFun Pro Micro

Stream deck on a Pro Micro

Six keys with their labels drawn on an SSD1306 OLED, a second page on the sixth key, and a Ctrl+Shift+F-key hotkey for each press through Keyboard.h. The whole build, a SparkFun Pro Micro and 7 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

Stream deck on a Pro Micro · SparkFun Pro Microlive0.000 s 0.00x
Press Run, then click a key and watch its label light
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · SparkFun Pro Micro
// Stream deck on a Pro Micro: six keys, their labels on a 128x64 OLED, and a
// hotkey sent over USB for each press through Keyboard.h.
//
// The labels are the point. A plain macro pad makes you remember which key
// is which; here the screen shows a label over each key, the one you press
// lights up, and the sixth key flips to a second page of five more actions.
//
// Wiring.
//
//   keys      4 5 6 7 8 9 (each to GND, pulled up inside the chip)
//   OLED      SSD1306 on I2C: SDA pin 2, SCL pin 3, VCC 5 V, GND
//
// In Mokxi: click the arcade buttons. The OLED shows the page and lights the
// key you hold, and the Serial Monitor shows the hotkey the board would type.
//
// Hotkeys. Each action is Ctrl + Shift + an F-key from F13 to F22. Almost no
// program uses F13 and up on its own, so streaming and recording software
// (OBS Studio's hotkey settings, for one) can take them without clashing with
// anything. Press the key in the program's hotkey box once and it learns it.
//
// Not simulated: the USB connection to a PC. Mokxi models this chip's USB as
// a serial pipe, so each press prints as a [Keyboard] line on the Serial
// Monitor. Flash the same sketch to a real Pro Micro and it types the keys.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keyboard.h>

// ---------------------------------------------------------------------------
// Make it yours
// ---------------------------------------------------------------------------

const uint8_t KEY_PINS[6] = {4, 5, 6, 7, 8, 9};

// Two pages of five actions; key 6 always turns the page. Labels are six
// characters at most so they fit a key's box.
const char *const LABELS[2][5] = {
    {"SCENE1", "SCENE2", "MUTE", "CAM", "REC"},
    {"BRB", "CLIP", "MARKER", "CHAT", "LIVE"},
};
const uint8_t HOTKEYS[2][5] = {
    {KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17},
    {KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22},
};
// Held with every hotkey. Change to just KEY_LEFT_CTRL, or add KEY_LEFT_ALT.
const uint8_t MODIFIERS[2] = {KEY_LEFT_CTRL, KEY_LEFT_SHIFT};

const unsigned long LOCK_MS = 20;  // debounce: ignore a key this long after a change

// ---------------------------------------------------------------------------

Adafruit_SSD1306 display(128, 64, &Wire, -1);

uint8_t page = 0;
bool held[6];
unsigned long changedAt[6];

void drawKey(uint8_t k) {
  int16_t x = (k % 3) * 43;
  int16_t y = 16 + (k / 3) * 24;
  bool lit = held[k];
  display.fillRect(x, y, 42, 22, lit ? SSD1306_WHITE : SSD1306_BLACK);
  display.drawRect(x, y, 42, 22, SSD1306_WHITE);
  display.setTextColor(lit ? SSD1306_BLACK : SSD1306_WHITE);
  display.setCursor(x + 3, y + 7);
  display.print(k == 5 ? "PAGE>" : LABELS[page][k]);
}

void draw() {
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 2);
  display.print("STREAM DECK  page ");
  display.print(page + 1);
  for (uint8_t k = 0; k < 6; k++) {
    drawKey(k);
  }
  display.display();
}

void send(uint8_t k) {
  for (uint8_t m = 0; m < 2; m++) Keyboard.press(MODIFIERS[m]);
  Keyboard.press(HOTKEYS[page][k]);
  Keyboard.releaseAll();
  Serial.print("Key ");
  Serial.print(k + 1);
  Serial.print(": ");
  Serial.println(LABELS[page][k]);
}

void setup() {
  for (uint8_t k = 0; k < 6; k++) {
    pinMode(KEY_PINS[k], INPUT_PULLUP);
  }
  Serial.begin(115200);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Wire.setClock(400000);  // fast mode: the screen redraws sooner
  Keyboard.begin();
  draw();
  Serial.println("Stream deck ready: page 1");
}

void loop() {
  unsigned long now = millis();
  bool redraw = false;
  for (uint8_t k = 0; k < 6; k++) {
    bool down = digitalRead(KEY_PINS[k]) == LOW;
    if (down == held[k] || now - changedAt[k] < LOCK_MS) {
      continue;
    }
    held[k] = down;
    changedAt[k] = now;
    redraw = true;
    if (!down) {
      continue;
    }
    if (k == 5) {
      page = (uint8_t)(1 - page);
      Serial.print("Page ");
      Serial.println(page + 1);
    } else {
      send(k);
    }
  }
  if (redraw) {
    draw();
  }
}

Parts list

9 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

10 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: SparkFun Pro Micro pin GND; OLED display, 128x64 pin GND; Arcade button (1) pin 1; Arcade button (2) pin 1; Arcade button (3) pin 1; Arcade button (4) pin 1; Arcade button (5) pin 1; Arcade button (6) pin 1
  • SparkFun Pro Micro pin 2; OLED display, 128x64 pin SDA
  • SparkFun Pro Micro pin 3; OLED display, 128x64 pin SCL
  • SparkFun Pro Micro pin 4; Arcade button (1) pin 2
  • SparkFun Pro Micro pin 5; Arcade button (2) pin 2
  • SparkFun Pro Micro pin 6; Arcade button (3) pin 2
  • SparkFun Pro Micro pin 7; Arcade button (4) pin 2
  • SparkFun Pro Micro pin 8; Arcade button (5) pin 2
  • SparkFun Pro Micro pin 9; Arcade button (6) pin 2
  • SparkFun Pro Micro pin VCC; OLED display, 128x64 pin VCC

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.