Arduino Nano ESP32 BleKeyboard Not Sending Data

Greetings,

I am using a genuine Arduino Nano ESP32 to function as a wireless keyboard.

When uploading the following code, I am able to connect the Nano ESP32 to touchscreen "smart devices" via Bluetooth as "ESP32 Keyboard".

However, the built-in touchscreen keyboards on the bluetooth devices I am trying to control with the Nano ESP32 via bluetooth do not move out of the way as they have in the past when the Adafruit 32u4 Bluefruit LE has been connected as a bluetooth keyboard.

More significantly, I have not been able to print/ read data on either of the connected Bluetooth devices or even the serial monitor on the computer I'm uploading the code from, whether by activating a pushbutton to send the data or automatically upon running the code.

I would greatly appreciate assistance in determining if there needs to be more setup of the data structure being sent via BleKeyboard, or if the ESP32 and associated libraries have done that already, what might be the right path to get a direct data transmission to an app like notes or notepad?

Thanks!

My apologies. Here is the code referenced in post #1:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

/**
 * This example turns the ESP32 into a Bluetooth LE keyboard that writes the words, presses Enter, presses a media key and then Ctrl+Alt+Delete
 */
#include "BleKeyboard.h"

BleKeyboard bleKeyboard;

int pinA = 7;                                       //Declaring variables for the pins
int pinB = 9;
int pinC = 17;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  
  bleKeyboard.begin();
  
}

void loop() {
  
  
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);if(bleKeyboard.isConnected()) {
    Serial.println("Sending 'Hello world'...");
    bleKeyboard.print("Hello world");

    //delay(1000);

    //Serial.println("Sending Enter key...");
    //BleKeyboard.write(KEY_RETURN);

    delay(1000);
  }
  if (digitalRead(pinA) == LOW){
    delay(90);
    
    bleKeyboard.print("Don't");        //Sending a string
    delay(50);}
    
    if (digitalRead(pinB) == LOW){
      
    bleKeyboard.print("Give");         //Sending a string
    delay(50);}

   else if (digitalRead(pinC) == LOW){
   
    bleKeyboard.print("Up!");         //Sending a str
    
    delay(50);}}
  //  Serial.println("Sending Play/Pause media key...");
  //  bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);

  //  delay(1000);
    
   
   // Below is an example of pressing multiple keyboard modifiers 
   // which by default is commented out. 
   
   /* Serial.println("Sending Ctrl+Alt+Delete...");
    bleKeyboard.press(KEY_LEFT_CTRL);
    bleKeyboard.press(KEY_LEFT_ALT);
    bleKeyboard.press(KEY_DELETE);
    delay(100);
    bleKeyboard.releaseAll();
    */

//  }
//  Serial.println("Waiting 5 seconds...");
//  delay(5000);
//}

Please check if the Bluetooth connection is established successfully. You can do this by checking the return value of BleKeyboard.begin().

Thank you for the reply. I am still not sure how to return the value to check the connection as suggested. I have inserted return(bleKeyboard()); into the loop section as well as using the Serial.print function, though have not been able to display a value.
I am pretty sure the device is connected due to "ESP32 Keyboard" showing as "Connected" in my smartphone's bluetooth settings menu and only appearing available once I upload the bluetooth code. Thanks in advance for any additional information!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.