scrapyardelectric
Published © GPL3+

Seeed Studio XIAO RP2040 18 Key Numpad

A minimalist 18 key numpad using the Seeed Studio XIAO RP2040, a single analogue pin, and room for expansion!

IntermediateFull instructions provided12 hours890
Seeed Studio XIAO RP2040 18 Key Numpad

Things used in this project

Hardware components

Seeed XIAO RP2040
Seeed Studio Seeed XIAO RP2040
×1
Kailh CHOC Low Profile Red Linear Key Switches
×18
Kailh Low Profile Keycaps (Black)
×18
Resistor 1kΩ (SMD, 1206)
×5
Resistor 4.7kΩ (SMD, 1206)
×3

Software apps and online services

Seeed Studio Fusion PCB
For production of the PCB!
JLCPCB EasyEDA
For designing the schematic!
Arduino IDE
Arduino IDE
For creating the code!
Autodesk Tinkercad
For designing the housing!
Ultimaker Cura
For slicing the .stl files!

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
For printing the housing!
Calipers
For taking accurate measurements to design the housing!

Story

Read more

Custom parts and enclosures

Seeed Studio Numpad Housing

.stl file for 3D printing a housing the device. You'll need to slice it with a profile that matches your specific model of printer.

Schematics

Keyboard schematic & PCB files

Code

Seeeduino_Xiao_Numpad_Sketch_3.ino

C/C++
Basic sketch to operate the described device as a numpad/small keyboard.
/* Seeed Studio XIAO RP2040-based 18 key numpad, using one
   analogue input pin and resistor network.

   Written by Scrapyard Electric, May 2022.

   This table gives averaged ADC values for the keys on my 
   device, and may differ to yours. It is recommended to use 
   a simple analogRead(A0) sketch to determine to appropriate 
   values for your device.
   _____________________________________________________
   |7 = 152, 8 = 1023, 9 = 139, X = 101                 |
   |4 = 128, 5 = 120,  6 = 107, / = 95,  Clear(Esc)= 524|
   |1 = 90,  2 = 315,  3 = 163, + = 783, Backspace = 393|
   |. = 236, 0 = 205,  = = 182, - = 278                 |
   -----------------------------------------------------

   If flashing code fails:
   1) Hold Reset, then hold Boot, relese Reset.
      This will open a folder with INDEX & IFO_UF2 files.
   2) Place file blink.ino.elf.uf2 in the folder,
      which should flash the board and close the folder.
   3) You may need to press Reset again, but the Xiao
      should be visible in the Arduino IDE under Ports again.

      ***WS2812 RGB Neopixel on Pin 12***
       ***Requires Pin 11 to be HIGH***

*/

#include <USBKeyboard.h>
#include <PluggableUSBHID.h>
#include <Adafruit_NeoPixel.h>

#define NUMPIXELS 1

int Power = 11;
int PIN  = 12;
int keyPin = A0;
int keyValue = 0;

USBKeyboard Keyboard;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  pinMode(Power, OUTPUT);
  digitalWrite(Power, HIGH);

  pixels.begin();
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(15, 25, 205));
  pixels.show();

  Serial.begin(115200);

}

void loop() {

  keyValue = analogRead(keyPin);
  
  if ((keyValue >= 80) && (keyValue <= 90)) { //90, 1
    Keyboard.printf("1");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 95) && (keyValue <= 97)) { //95, /
    Keyboard.printf("/");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 98) && (keyValue <= 102)) { //101, X
    Keyboard.printf("*");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 104) && (keyValue <= 109)) { // 107, 6
    Keyboard.printf("6");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 116) && (keyValue <= 122)) { //120, 5
    Keyboard.printf("5");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 125) && (keyValue <= 130)) { //128, 4
    Keyboard.printf("4");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 133) && (keyValue <= 141)) { //139, 9
    Keyboard.printf("9");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 145) && (keyValue <= 154)) { //152, 7
    Keyboard.printf("7");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 159) && (keyValue <= 165)) { //163, 3
    Keyboard.printf("3");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 175) && (keyValue <= 184)) { //182, =
    Keyboard.printf("=");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 198) && (keyValue <= 207)) { //205, 0
    Keyboard.printf("0");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 230) && (keyValue <= 238)) { //236, .
    Keyboard.printf(".");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 270) && (keyValue <= 280)) { //278, -
    Keyboard.printf("-");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 308) && (keyValue <= 319)) { //315, 2
    Keyboard.printf("2");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 380) && (keyValue <= 410)) { //393, Backspace
    Keyboard.printf("Backspace");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 515) && (keyValue <= 540)) { //524, Escape
    Keyboard.printf("Escape");
    Serial.println(keyValue);
    delay(150);
  }

  else if ((keyValue >= 765) && (keyValue <= 785)) { //783, +
    Keyboard.printf("+");
    Serial.println(keyValue);
    delay(150);
  }

  else if (keyValue > 1000) { //1023, 8
    Keyboard.printf("8");
    Serial.println(keyValue);
    delay(150);
  }

}

Credits

scrapyardelectric

scrapyardelectric

1 project • 2 followers
PCB design, specifically automotive; modifying commercial products; 3D printing. Available for commissioned work. Hobbyist.

Comments