Usage of 4 byte integer to transfer value of slider

Hello ! , I seem to misunderstand something. cant i transfer integers using send 2 byte number?. The baud rate is set to 115200 in both serial and setup

ESP32 code:

#include "BluetoothSerial.h"

//#define USE_PIN // Uncomment this to use PIN during pairing. The pin is specified on the line below

const char *pin = "1234"; // Change this to more secure PIN.

String device_name = "ESP32-BT-Slave";

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

#if !defined(CONFIG_BT_SPP_ENABLED)

#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.

#endif

BluetoothSerial SerialBT;

void setup() {

  Serial.begin(115200);

  SerialBT.begin(device_name); //Bluetooth device name

  Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());

  //Serial.printf("The device with name \"%s\" and MAC address %s is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str(), SerialBT.getMacString()); // Use this after the MAC method is implemented

  #ifdef USE_PIN

    SerialBT.setPin(pin);

    Serial.println("Using PIN");

  #endif

}

void loop() {

  if (Serial.available()) {

    SerialBT.write(Serial.read());

  }

  if (SerialBT.available()) {

    Serial.write(SerialBT.read());

  }

  delay(20);

}

Show us the code for arduino. What BT module are you using?

// I am just using an example code for now
// I am using an esp32 module
// i need integers so that i can code them as angles for my stepper motor (will be converted)

#include "BluetoothSerial.h"

//#define USE_PIN // Uncomment this to use PIN during pairing. The pin is specified on the line below

const char *pin = "1234"; // Change this to more secure PIN.

String device_name = "ESP32-BT-Slave";

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

#if !defined(CONFIG_BT_SPP_ENABLED)

#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.

#endif

BluetoothSerial SerialBT;

void setup() {

  Serial.begin(115200);

  SerialBT.begin(device_name); //Bluetooth device name

  Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());

  //Serial.printf("The device with name \"%s\" and MAC address %s is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str(), SerialBT.getMacString()); // Use this after the MAC method is implemented

  #ifdef USE_PIN

    SerialBT.setPin(pin);

    Serial.println("Using PIN");

  #endif

}

void loop() {

  if (Serial.available()) {

    SerialBT.write(Serial.read());

  }

  if (SerialBT.available()) {

    Serial.write(SerialBT.read());

  }

  delay(20);

}

The app sends the bytes, your esp receives those bytes, and the terminal displays those bytes as ASCII characters. Do a test and send, for example, the number 100, you will get the letter "d" in the terminal.

1 Like

Serial comms explained: