Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Arnov Sharma
Published © MIT

HID Numpad with XIAO SAMD21

Made a compact NUMPAD project using the XIAO SAMD21 and XIAO Expansion Board.

BeginnerFull instructions provided1 hour175
HID Numpad with XIAO SAMD21

Things used in this project

Hardware components

Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
×1
Seeeduino XIAO Expansion board
Seeed Studio Seeeduino XIAO Expansion board
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA

Story

Read more

Custom parts and enclosures

cad file

Schematics

SCH

Code

TEST SKETCH

C/C++
#include <Keyboard.h>         //TEST SKETCH
int buttonPin = 1;  // Set a button to any pin

void setup()
{
  pinMode(buttonPin, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin, HIGH);  // Pull the button high
}

void loop()
{
  if (digitalRead(buttonPin) == 0)  // if the button goes low
  {
    Keyboard.write('1');  // send a '1' to the computer via Keyboard HID
    delay(500);  // delay so there aren't a kajillion z's
  }
}

Main SKetch

C/C++
#include <Keyboard.h>

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

#define OLED_WIDTH 128
#define OLED_HEIGHT 64

#define OLED_ADDR   0x3C
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);



int buttonPin1 = 0;  
int buttonPin2 = 1; 
int buttonPin3 = 2; 
int buttonPin4 = 3; 
int buttonPin5 = 6; 
int buttonPin6 = 7; 
int buttonPin7 = 8; 
int buttonPin8 = 9; 
int buttonPin9 = 10; 




void setup()
{
  pinMode(buttonPin1, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin1, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin2, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin2, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin3, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin3, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin4, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin4, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin5, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin5, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin6, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin6, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin7, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin7, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin8, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin8, HIGH);  // Pull the bu11tton high

  pinMode(buttonPin9, INPUT_PULLUP);  // Set the button as an input
  digitalWrite(buttonPin9, HIGH);  // Pull the bu11tton high  


  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay(); 
}

void loop()
{
  if (digitalRead(buttonPin1) == 0) // 01
  {
    Keyboard.write('1');  
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("1");
  display.display();
  delay(500);  
  }
    display.clearDisplay();

  if (digitalRead(buttonPin2) == 0) // 02
  {
    Keyboard.write('2');  
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("2");
  display.display();      
  delay(500);  
  }

display.clearDisplay();

  if (digitalRead(buttonPin3) == 0)  // 03 
  {
    Keyboard.write('3'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("3");
  display.display();
  delay(500);  
  }

display.clearDisplay();

  if (digitalRead(buttonPin4) == 0)  // 04 
  {
    Keyboard.write('4'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("4");
  display.display();
  delay(500);  
  }  

display.clearDisplay();

  if (digitalRead(buttonPin5) == 0)  // 05 
  {
    Keyboard.write('5'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("5");
  display.display();
  delay(500);  
  }  


display.clearDisplay();

  if (digitalRead(buttonPin6) == 0)  // 06 
  {
    Keyboard.write('6'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("6");
  display.display();
  delay(500);  
  } 

display.clearDisplay();

  if (digitalRead(buttonPin7) == 0)  // 07
  {
    Keyboard.write('7'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("7");
  display.display();
  delay(500);  
  } 

display.clearDisplay();

  if (digitalRead(buttonPin8) == 0)  // 08
  {
    Keyboard.write('8'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("8");
  display.display();
  delay(500);  
  } 

display.clearDisplay();

  if (digitalRead(buttonPin9) == 0)  // 09
  {
    Keyboard.write('9'); 
    
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(55, 20);
  display.println("9");
  display.display();
  delay(500);  
  }
  
display.clearDisplay();   

}

Credits

Arnov Sharma

Arnov Sharma

310 projects • 311 followers
Just your average MAKER

Comments