This board's construction is really simple; we insert all of the mechanical switches in their proper locations, including the female header pins for the XIAO and OLED screens.
Flipping the board around allows us to solder all of the mechanical switch and header pins.
The XIAO M0 then gets placed alongside the OLED screen.
2
Final Assembly
We tighten four PCB standoffs to four mounting holes on the board with four M2.5 bolts and a screwdriver.
We then attached keycaps to all five mechanical switches to complete the assembly process.
3
CODE
Here's the sketch that we used in this project and its a simple one.
#include<Wire.h>#include<Adafruit_GFX.h>#include<Adafruit_SSD1306.h>#include<Keyboard.h>#define SCREEN_WIDTH 128#define SCREEN_HEIGHT 32#define OLED_RESET -1Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
constint buttonCopyPin = 0; // Pin for the copy buttonconstint buttonPastePin = 1; // Pin for the paste buttonconstint buttonScrollUpPin = 2; // Pin for the page scroll up buttonconstint buttonScrollDownPin = 3; // Pin for the page scroll down buttonconstint buttonEnterPin = 6; // Pin for the enter buttonvoidsetup(){
// Initialize the OLED displayif(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
// Initialize the buttons
pinMode(buttonCopyPin, INPUT_PULLUP);
pinMode(buttonPastePin, INPUT_PULLUP);
pinMode(buttonScrollUpPin, INPUT_PULLUP);
pinMode(buttonScrollDownPin, INPUT_PULLUP);
pinMode(buttonEnterPin, INPUT_PULLUP);
// Initialize the Keyboard library
Keyboard.begin();
}
voidloop(){
if (digitalRead(buttonCopyPin) == LOW) {
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(20, 5);
display.print("Copy");
display.display();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press('c');
delay(100);
Keyboard.releaseAll();
delay(500); // Debounce delay
}
if (digitalRead(buttonPastePin) == LOW) {
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(20, 5);
display.print("Paste");
display.display();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press('v');
delay(100);
Keyboard.releaseAll();
delay(500); // Debounce delay
}
if (digitalRead(buttonScrollUpPin) == LOW) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 5);
display.print("Scroll UP");
display.display();
Keyboard.press(KEY_PAGE_UP);
delay(100);
Keyboard.releaseAll();
delay(500); // Debounce delay
}
if (digitalRead(buttonScrollDownPin) == LOW) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 5); // Adjusted cursor position
display.print("Scroll Down");
display.display();
Keyboard.press(KEY_PAGE_DOWN);
delay(100);
Keyboard.releaseAll();
delay(500); // Debounce delay
}
if (digitalRead(buttonEnterPin) == LOW) {
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(25, 5);
display.print("Enter");
display.display();
Keyboard.press(KEY_RETURN);
delay(100);
Keyboard.releaseAll();
delay(500); // Debounce delay
}
}
In this sketch, we are using two main libraries: one for running the OLED screen and the other to execute keyboard functions.
Make sure to download and install these above libraries before using this sketch.
This sketch makes our XIAO act like a keyboard when specific buttons are pressed, giving feedback on an OLED display. Each button press simulates a keyboard shortcut or key press, and the OLED display updates to reflect the action.
4
RESULT
The end result of this small build is a working Macropad that can execute the Copy paste command, scroll a webpage (any app that supports Page up and down), and enter commands.
We can use Copy and Paste macros for typing and even cad work.
The scrolling feature is especially useful while browsing YouTube or other websites that demand frequent scrolling.
Overall, this project has reached its peak and requires no additional revisions, thanks to the excellent XIAO and Seeed Studio Fusion Service.
Leave a comment if you need any help regarding this project. This is it for today, folks.
You guys can check them out if you need great PCB and stencil service for less cost and great quality.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.