I got a custom made ESP32-S3 pcb. I tried my sketch wich is running on an ESP32-Wroom 32D Devboard. I can uoload it and got it running via USB with some modifications, but i can not make it advertice ble, even with using nimBLE.
What could be the reason?
Thank you
- //Changelog:
- //made center doubleklick toggle between STF/Vario (toggle sending S/V)
- // Reset XCREMOTE with 5sec X-Hold added
- //New BLEKeyboard Library keeps BLE Advertising when disconnected
- // uses libraries from
- // https://github.com/r89m/PushButton
- // https://github.com/r89m/Button
- // https://github.com/thomasfredericks/Bounce2
- #include <Button.h>
- #include <ButtonEventCallback.h>
- #include <PushButton.h>
- #include <Bounce2.h>
- #include <BluetoothSerial.h>
- #include <BleKeyboard.h>
- // Updating server
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <WebServer.h>
- #include <ESPmDNS.h>
- #include <Update.h>
- #include "OneButton.h"
- // Version
- #define VERSION "2.3.2"
- #define USE_NIMBLE
- // Init BLE
- BleKeyboard bleKeyboard("XCREMOTE", "XCNAV UG", 100);
- // Pin Assignments
- const int LED_Pin = 02;
- const int Up_Pin = 15; // UP (Joystick Up)
- const int Down_Pin = 26; // Down (Joystick Down)
- const int Left_Pin = 25; // Left (Joystick Left)
- const int Right_Pin = 27; // Right (Joystick Right)
- const int Center_Pin = 17; // Enter (Joystick Press)
- const int Rectangle_Pin = 18; // Rectangle (Button 2)
- const int Triangle_Pin = 05; // Triangle (Button 3)
- const int Circle_Pin = 33; // Circle (Button 4)
- const int Cancel_Pin = 04; // X (Button 5)
- // Button's keys
- const char Up_Press_Key = KEY_UP_ARROW;
- const char Down_Press_Key = KEY_DOWN_ARROW;
- const char Left_Press_Key = KEY_LEFT_ARROW;
- const char Right_Press_Key = KEY_RIGHT_ARROW;
- const char Rectangle_Press_Key = KEY_F4;
- const char Rectangle_Hold_Key = KEY_F3;
- const char Triangle_Press_Key = KEY_F6;
- const char Triangle_Hold_Key = KEY_F2;
- const char Circle_Press_Key = 'M';
- const char Circle_Hold_Key = KEY_F1;
- const char Cancel_Press_Key = KEY_ESC;
- const char Cancel_Hold_Key = 'T';
- const int Joy_Rebounce_Interval = 3;
- const int Joy_Rebounce_Threshold = 20;
- const int Joy_Active_Threshold = 100;
- const int Button_Hold_Threshold = 500;
- const int Button_Rebounce_Interval = 500;
- const int Reset_Threshold = 5000;
- const int Joy_Hold_Threshold = 1;
- // PushButton's instances
- PushButton Up = PushButton(Up_Pin);
- PushButton Down = PushButton(Down_Pin);
- PushButton Left = PushButton(Left_Pin);
- PushButton Right = PushButton(Right_Pin);
- PushButton Center = PushButton(Center_Pin);
- PushButton Rectangle = PushButton(Rectangle_Pin);
- PushButton Triangle = PushButton(Triangle_Pin);
- PushButton Circle = PushButton(Circle_Pin);
- PushButton Cancel = PushButton(Cancel_Pin);
- // Setup a new OneButton on pin PIN_INPUT
- // The 2. parameter activeLOW is true, because external wiring sets the button to LOW when pressed.
- OneButton button(Center_Pin, true);
- // save the millis when a press has started.
- unsigned long HoldCenterTime;
- // Variables
- int bt_first_connected = false;
- boolean Joy_Inactive = true;
- int Joy_Active_Counter = 0;
- // Updating server
- const char* host = "esp32";
- const char* ssid = "XCREMOTE";
- //const char* ssid = "xcremote";
- const char* password = "xcremote";
- boolean server_running = 0;
- WebServer server(80);
- // current Cruise_Climb (Joy Center) state, staring with LOW (0)
- int Cruise_Climb = LOW;
- void setup() {
- pinMode(Up_Pin, INPUT_PULLUP);
- pinMode(Down_Pin, INPUT_PULLUP);
- pinMode(Left_Pin, INPUT_PULLUP);
- pinMode(Right_Pin, INPUT_PULLUP);
- pinMode(Center_Pin, INPUT_PULLUP);
- pinMode(Rectangle_Pin, INPUT_PULLUP);
- pinMode(Triangle_Pin, INPUT_PULLUP);
- pinMode(Circle_Pin, INPUT_PULLUP);
- pinMode(Cancel_Pin, INPUT_PULLUP);
- Serial.begin(115200);
- Serial.println("Version: " VERSION);
- Serial.print("XCRemote MAC Address: ");
- Serial.println(WiFi.macAddress());
- // link the xxxclick functions to be called on xxxclick event.
- button.attachClick(SingleClick);
- button.attachDoubleClick(DoubleClick);
- button.setPressTicks(1000); // that is the time when LongHoldCenter is called
- button.attachLongPressStart(HoldCenter);
- // pinMode(LED_Pin, OUTPUT);
- if (digitalRead(Center_Pin) == 0) updating_server_start();
- else {
- Serial.println("Starting BLE work!");
- bleKeyboard.begin();
- Up.onRelease(Joy_onRelease);
- Down.onRelease(Joy_onRelease);
- Left.onRelease(Joy_onRelease);
- Right.onRelease(Joy_onRelease);
- Up.onHoldRepeat(Joy_Hold_Threshold, Joy_Rebounce_Interval, Joy_onHoldRepeat);
- Down.onHoldRepeat(Joy_Hold_Threshold, Joy_Rebounce_Interval, Joy_onHoldRepeat);
- Left.onHoldRepeat(Joy_Hold_Threshold, Joy_Rebounce_Interval, Joy_onHoldRepeat);
- Right.onHoldRepeat(Joy_Hold_Threshold, Joy_Rebounce_Interval, Joy_onHoldRepeat);
- Center.onRelease(0, Button_Hold_Threshold-1, Button_onRelease);
- Rectangle.onRelease(0, Button_Hold_Threshold-1, Button_onRelease);
- Triangle.onRelease(0, Button_Hold_Threshold-1, Button_onRelease);
- Circle.onRelease(0, Button_Hold_Threshold-1, Button_onRelease);
- Cancel.onRelease(0, Button_Hold_Threshold-1, Button_onRelease);
- Center.onHold(Button_Hold_Threshold, Button_onHold);
- Rectangle.onHold(Button_Hold_Threshold, Button_onHold);
- Triangle.onHold(Button_Hold_Threshold, Button_onHold);
- Circle.onHold(Button_Hold_Threshold, Button_onHold);
- Cancel.onHoldRepeat(Button_Hold_Threshold, Button_Rebounce_Interval,Button_onHoldRepeat);
- Joy_Active_Counter = 0;
- }
- }
- void loop() {
- // keep watching the push button:
- button.tick();
- if (server_running) {
- server.handleClient();
- delay(1);
- }
- else {
- if(bleKeyboard.isConnected()) {
- Serial.println("ok");
- if (not bt_first_connected) {
- bt_first_connected = true;
- Serial.println("BT connected");
- delay (2000);
- bleKeyboard.print("C");
- }
- Up.update();
- Down.update();
- Left.update();
- Right.update();
- Center.update();
- Rectangle.update();
- Triangle.update();
- Circle.update();
- Cancel.update();
- }
- }
- }
- void keyboardPress(char key) {
- bleKeyboard.press(key);
- }
- void Button_onRelease(Button& btn, uint16_t duration){
- if (btn.is(Rectangle)) keyboardPress(Rectangle_Press_Key);
- if (btn.is(Triangle)) keyboardPress(Triangle_Press_Key);
- if (btn.is(Circle)) keyboardPress(Circle_Press_Key);
- if (btn.is(Cancel)) keyboardPress(Cancel_Press_Key);
- bleKeyboard.releaseAll();
- }
- void Button_onHold(Button& btn, uint16_t duration){
- if (btn.is(Rectangle)) keyboardPress(Rectangle_Hold_Key);
- if (btn.is(Triangle)) keyboardPress(Triangle_Hold_Key);
- if (btn.is(Circle)) keyboardPress(Circle_Hold_Key);
- bleKeyboard.releaseAll();
- }
- void Joy_onHoldRepeat(Button& btn, uint16_t duration, uint16_t repeat_count){
- if(btn.isPressed() && Joy_Active_Counter == 5) {
- if(btn.is(Up)) keyboardPress(Up_Press_Key);
- if(btn.is(Down)) keyboardPress(Down_Press_Key);
- if(btn.is(Left)) keyboardPress(Left_Press_Key);
- if(btn.is(Right)) keyboardPress(Right_Press_Key);
- bleKeyboard.releaseAll();
- }
- Joy_Active_Counter = Joy_Active_Counter +1;
- if (Joy_Inactive && Joy_Active_Counter > Joy_Active_Threshold){
- Joy_Active_Counter = 0;
- Joy_Inactive = false;
- }
- if (!Joy_Inactive && Joy_Active_Counter > Joy_Rebounce_Threshold) Joy_Active_Counter = 0;
- }
- void Joy_onRelease(Button& btn, uint16_t duration){
- Joy_Active_Counter = 0;
- Joy_Inactive = true;
- }
- void SingleClick() { // this function will be called when the Joy center button is pressed 1 time only.
- bleKeyboard.write(KEY_RETURN);
- Serial.println("SingleClick() detected.");
- } // SingleClick
- void DoubleClick() { // this function will be called when the Joy center button was pressed 2 times in a short timeframe.
- if(Cruise_Climb == LOW) {
- bleKeyboard.print("V");
- Serial.println("Vario");
- }
- else {
- bleKeyboard.print("S");
- Serial.println("Speed to fly");
- }
- Cruise_Climb = !Cruise_Climb; // reverse the Cruise_Climb
- } // DoubleClick
- void HoldCenter() { // this function will be called when the Joy center button is held down for 0.5 second or more.
- bleKeyboard.print("P");
- Serial.println("PAN()");
- HoldCenterTime = millis() - 500; // as set in setPressTicks()
- } // HoldCenter()
- void Button_onHoldRepeat(Button& btn, uint16_t duration, uint16_t repeat_count){ // this function will be called when the Cancel button is held down for a longer time
- if (btn.is(Cancel)) {
- if (repeat_count == 1) {
- keyboardPress(Cancel_Hold_Key);
- bleKeyboard.releaseAll();
- }
- if (duration > 5000){
- bleKeyboard.print("E");
- delay(1000);
- ESP.restart(); // ESP32_Restart
- }
- }
- }