Hi
Im completely new to Arduino and wanted to start with it but I have always the same issue. When I upload my sketch to my Arduino Nano ESP32 it disconnects instantly after. I want to use it over Bluetooth and I've heard that it's normal then that it disconnects, but it disconnects also if I dont use Bluetooth and I can't see the Arduino as a Bluetooth device. I've used several different sketches, also the example ones and it didnt work. I don't know if it's an issue with the drivers or a Version of something.
What else I can say is I use the newest Arduino IDE. I use the ESP BLE32 Keyboard Library. I have the Arduino ESP32 Boards 20.0.18-arduino.5 Board Manager installed. I have as additional board manager URL this URL: "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json". My selected Board is the "Arduino Nano ESP32 - Arduino ESP32 boards"
If you want to see my main Code: (Yes I am ashamed that I let Chatgpt generate my Code :()
#include <BleKeyboard.h>
// Bluetooth Keyboard erstellen
// Name = was du am PC siehst
BleKeyboard bleKeyboard("ESP32 Deck", "Custom", 100);
// ==========================
// 🔌 PIN KONFIGURATION
// ==========================
// Hier DEINE verkabelten Pins eintragen
const int rowPins[4] = { 3, 4, 5, 6 }; // Rows (Ausgänge)
const int colPins[5] = { 7, 8, 9, 10, 11 }; // Columns (Eingänge)
// ==========================
// 🔁 SYSTEM STATUS
// ==========================
// true = NUMPAD, false = STREAM DECK
bool isNumpadMode = true;
// aktuelle Seite (0,1,2)
int currentPage = 0;
// für LONG PRESS (Taste 20)
unsigned long pressStart = 0;
bool keyHeld = false;
// ==========================
// 🔢 KEYMAP (PHYSISCHES LAYOUT)
// ==========================
// Jede Zahl entspricht einer Taste
// Passe das an, wenn dein Layout anders ist!
int keymap[4][5] = {
{ 1, 2, 3, 4, 5 },
{ 6, 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15 },
{ 16, 17, 18, 19, 20 } // Taste 20 = MODE + PAGE
};
// ==========================
// ⚙️ SETUP
// ==========================
void setup() {
bleKeyboard.begin(); // Bluetooth starten
// Rows als OUTPUT setzen
for (int i = 0; i < 4; i++) {
pinMode(rowPins[i], OUTPUT);
digitalWrite(rowPins[i], LOW);
}
// Columns als INPUT_PULLUP setzen
// → Taste gedrückt = LOW
for (int i = 0; i < 5; i++) {
pinMode(colPins[i], INPUT_PULLUP);
}
}
// ==========================
// 🔄 LOOP (MATRIX SCAN)
// ==========================
void loop() {
// Nur wenn Bluetooth verbunden
if (!bleKeyboard.isConnected()) return;
// Jede Row einzeln aktivieren
for (int r = 0; r < 4; r++) {
digitalWrite(rowPins[r], HIGH);
for (int c = 0; c < 5; c++) {
// Wenn Taste gedrückt
if (digitalRead(colPins[c]) == LOW) {
handlePress(keymap[r][c]);
}
}
digitalWrite(rowPins[r], LOW);
}
}
// ==========================
// 🔘 TASTEN VERARBEITUNG
// ==========================
void handlePress(int keyID) {
// ======================
// 🎯 SPEZIALTASTE (20)
// ======================
if (keyID == 20) {
// Startzeit merken
if (!keyHeld) {
pressStart = millis();
keyHeld = true;
}
// LONG PRESS → MODE wechseln
if (millis() - pressStart > 600) {
isNumpadMode = !isNumpadMode;
keyHeld = false;
delay(500); // Schutz vor mehrfach auslösen
}
} else {
// Normale Taste
sendKey(keyID);
delay(200); // Debounce
}
// ======================
// SHORT PRESS → PAGE wechseln
// ======================
if (keyID == 20 && digitalRead(colPins[4]) == HIGH) {
if (keyHeld) {
// Nur im Stream Deck Mode
if (!isNumpadMode) {
currentPage++;
// 3 Seiten → 0,1,2
if (currentPage > 2) currentPage = 0;
}
keyHeld = false;
}
}
}
// ==========================
// 🔁 MODE SWITCH
// ==========================
void sendKey(int keyID) {
if (isNumpadMode) {
sendNumpad(keyID);
} else {
sendStreamDeck(keyID);
}
}
// ==========================
// 🔢 NUMPAD (ALLE 20 TASTEN BELEGT)
// ==========================
void sendNumpad(int keyID) {
switch (keyID) {
case 1: bleKeyboard.print("1"); break;
case 2: bleKeyboard.print("2"); break;
case 3: bleKeyboard.print("3"); break;
case 4: bleKeyboard.print("4"); break;
case 5: bleKeyboard.print("5"); break;
case 6: bleKeyboard.print("6"); break;
case 7: bleKeyboard.print("7"); break;
case 8: bleKeyboard.print("8"); break;
case 9: bleKeyboard.print("9"); break;
case 10: bleKeyboard.print("0"); break;
case 11: bleKeyboard.print("+"); break;
case 12: bleKeyboard.print("-"); break;
case 13: bleKeyboard.print("*"); break;
case 14: bleKeyboard.print("/"); break;
case 15: bleKeyboard.print("="); break;
case 16: bleKeyboard.press(KEY_RETURN); break;
case 17: bleKeyboard.press(KEY_BACKSPACE); break;
case 18: bleKeyboard.press(KEY_ESC); break;
case 19:
bleKeyboard.press(KEY_TAB);
break;
// Taste 20 = Spezialtaste → keine Aktion hier
}
bleKeyboard.releaseAll();
}
// ==========================
// 🎛️ STREAM DECK (3 PAGES)
// ==========================
void sendStreamDeck(int keyID) {
// ======================
// PAGE 0
// ======================
if (currentPage == 0) {
switch (keyID) {
case 1:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('c');
break;
case 2:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('v');
break;
case 3:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('x');
break;
case 4:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('z');
break;
case 5:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('y');
break;
case 6:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('s');
break;
case 7:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('p');
break;
case 8:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('a');
break;
case 9:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('f');
break;
case 10:
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('n');
break;
case 11: bleKeyboard.print("Hello"); break;
case 12: bleKeyboard.print("Test"); break;
case 13: bleKeyboard.print("ESP32"); break;
case 14: bleKeyboard.print("StreamDeck"); break;
case 15: bleKeyboard.print("OK"); break;
case 16:
bleKeyboard.press(KEY_LEFT_GUI);
bleKeyboard.press('d');
break;
case 17:
bleKeyboard.press(KEY_LEFT_ALT);
bleKeyboard.press(KEY_TAB);
break;
case 18: bleKeyboard.press(KEY_MEDIA_PLAY_PAUSE); break;
case 19: bleKeyboard.press(KEY_MEDIA_VOLUME_UP); break;
}
}
// ======================
// PAGE 1
// ======================
if (currentPage == 1) {
switch (keyID) {
case 1: bleKeyboard.print("Page2-1"); break;
case 2: bleKeyboard.print("Page2-2"); break;
case 3: bleKeyboard.print("Page2-3"); break;
case 4: bleKeyboard.print("Page2-4"); break;
case 5: bleKeyboard.print("Page2-5"); break;
case 6: bleKeyboard.press(KEY_F1); break;
case 7: bleKeyboard.press(KEY_F2); break;
case 8: bleKeyboard.press(KEY_F3); break;
case 9: bleKeyboard.press(KEY_F4); break;
case 10: bleKeyboard.press(KEY_F5); break;
case 11: bleKeyboard.press(KEY_F6); break;
case 12: bleKeyboard.press(KEY_F7); break;
case 13: bleKeyboard.press(KEY_F8); break;
case 14: bleKeyboard.press(KEY_F9); break;
case 15: bleKeyboard.press(KEY_F10); break;
case 16: bleKeyboard.press(KEY_F11); break;
case 17: bleKeyboard.press(KEY_F12); break;
case 18: bleKeyboard.press(KEY_HOME); break;
case 19: bleKeyboard.press(KEY_END); break;
}
}
// ======================
// PAGE 2
// ======================
if (currentPage == 2) {
switch (keyID) {
case 1: bleKeyboard.print("OBS1"); break;
case 2: bleKeyboard.print("OBS2"); break;
case 3: bleKeyboard.print("OBS3"); break;
case 4: bleKeyboard.print("OBS4"); break;
case 5: bleKeyboard.print("OBS5"); break;
case 6:
bleKeyboard.press(KEY_LEFT_GUI);
bleKeyboard.press(KEY_LEFT_SHIFT);
bleKeyboard.press('s');
break;
case 7: bleKeyboard.press(KEY_TAB); break;
case 8: bleKeyboard.press(KEY_INSERT); break;
case 9: bleKeyboard.press(KEY_DELETE); break;
case 10: bleKeyboard.press(KEY_PAGE_UP); break;
case 11: bleKeyboard.press(KEY_PAGE_DOWN); break;
case 12: bleKeyboard.press(KEY_UP_ARROW); break;
case 13: bleKeyboard.press(KEY_DOWN_ARROW); break;
case 14: bleKeyboard.press(KEY_LEFT_ARROW); break;
case 15: bleKeyboard.press(KEY_RIGHT_ARROW); break;
case 16: bleKeyboard.press(KEY_MEDIA_VOLUME_DOWN); break;
case 17: bleKeyboard.press(KEY_MEDIA_MUTE); break;
case 18: bleKeyboard.press(KEY_MEDIA_NEXT_TRACK); break;
case 19: bleKeyboard.press(KEY_MEDIA_PREVIOUS_TRACK); break;
}
}
delay(50);
bleKeyboard.releaseAll();
}