-
1PCB Assembly Process
- 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.
-
2Final 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.
-
3CODE
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 -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); const int buttonCopyPin = 0; // Pin for the copy button const int buttonPastePin = 1; // Pin for the paste button const int buttonScrollUpPin = 2; // Pin for the page scroll up button const int buttonScrollDownPin = 3; // Pin for the page scroll down button const int buttonEnterPin = 6; // Pin for the enter button void setup() { // Initialize the OLED display if(!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(); } void loop() { 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.
#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>#include <Keyboard.h>
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.
-
4RESULT
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.
And I'll be back with a new project pretty soon!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.