본문 바로가기
키보드 DIY 프로젝트

블루투스 42KEY 키보드 (with ESP-WROOM-32 Keyboard, 3D프린팅)

by Newtle Kim 2025. 10. 20.
반응형

🚨 반드시 읽어야할 이전 글 

1. 블루투스키보드 1KEY TEST(BleKeyboard 라이브러리에 관한내용) : https://newtlekim.tistory.com/7

2. 블루투스 키패드 (응용 프로젝트) : https://newtlekim.tistory.com/9

위 내용에 대한 이해가 완벽하다면 블루투스 키보드는 어렵지 않게 만들 수 있습니다.

 

 

 

🔻 PCB제작을 위한 Gerber Files🔻

1. 키보드 모듈 PCB 거버파일

Gerber_40key_keyboard_PCB_40key_keyboard_2025-10-22.zip
0.03MB

 

2. ESP-WROOM-32 인터페이스보드 거버파일

Gerber_interfaceboard_ESP32WROOM_PCB_interfaceboard_ESP32WROOM_2025-10-22.zip
0.01MB

 

🔻 키보드 관련 3D 모델파일 🔻

keyboard_housing V2.0.stl
1.60MB
Switch_holder_plate_V2.0.stl
1.34MB
topcover_V2.0.stl
3.75MB

 

 

 

🔻 블루투스 키보드에 대한 아두이노 코드 🔻

#include <BleKeyboard.h>

const uint8_t rowPins[4] = {23, 32, 33, 5};  //ROW0 ~ ROW3
const uint8_t colPins[12] = {4, 13, 14, 16, 17, 18, 19, 21, 22, 25, 26, 27};  //COL0 ~ COL11

// 일반 키로 변경 (문자/기호 직접 입력)
const uint8_t keymap[4][12] = {
  {KEY_ESC, 'q',  'w',  'e',  'r',  't',  'y',  'u',  'i',  'o',  'p',  KEY_BACKSPACE},      // ROW 0
  {KEY_CAPS_LOCK, 'a',  's',  'd',  'f',  'g',  'h',  'j',  'k',  'l',  0,  KEY_RETURN},   // ROW 1 (Enter)
  {KEY_LEFT_SHIFT,  'z',  'x',  'c',  'v',  'b',  'n',  'm',  ',',  '.',  KEY_UP_ARROW, KEY_DELETE},      // ROW 2
  {KEY_LEFT_CTRL, KEY_LEFT_ALT, KEY_LEFT_GUI, 0,  0,  ' ',  0,  0,  0,  KEY_LEFT_ARROW, KEY_DOWN_ARROW, KEY_RIGHT_ARROW},    // ROW 3
};

BleKeyboard btKeyboard("NewtleKIMBOARD");
bool keyPressed[4][12] = {false};  // 눌림 상태 추적

void setup() {
  Serial.begin(115200);
  for (uint8_t i = 0; i < 12; i++) {
    pinMode(colPins[i], INPUT_PULLUP);
  }
  for (uint8_t i = 0; i < 4; i++) {
    pinMode(rowPins[i], OUTPUT);
    digitalWrite(rowPins[i], HIGH);  // 기본 HIGH
  }

  btKeyboard.begin();
  Serial.println("BLE Keyboard ready. Waiting for connection...");
}

void loop() {
  if (btKeyboard.isConnected()) {
    for (uint8_t row = 0; row < 4; row++) {
      digitalWrite(rowPins[row], LOW);
      delayMicroseconds(5);

      for (uint8_t col = 0; col < 12; col++) {
        uint8_t pin = colPins[col];
        uint8_t key = keymap[row][col];

        if (key == 0) continue;  // 빈 칸

        bool currentState = digitalRead(pin) == LOW;

        if (currentState && !keyPressed[row][col]) {
          btKeyboard.press(key);
          keyPressed[row][col] = true;
          Serial.printf("Pressed [%d,%d] keycode: %d\n", row, col, key);
        }

        if (!currentState && keyPressed[row][col]) {
          btKeyboard.release(key);
          keyPressed[row][col] = false;
          Serial.printf("Released [%d,%d] keycode: %d\n", row, col, key);
        }
      }

      digitalWrite(rowPins[row], HIGH);
    }
  } else {
    Serial.println("BLE not connected...");
    delay(500);
  }

  delay(10);
}