I am implementing BLE with a HM-10 connected to an arduino UNO.
I have encountered an issue where attempting to add another characteristic results in the overwrite of the first one, leaving me with only one characteristic. Is it possible to implement multiple characteristics, and if so, how can I achieve this in my Arduino code?
Any assistance would be greatly appreciated.
#include <SoftwareSerial.h>
SoftwareSerial HM10(2, 3); // RX, TX, or choose any other suitable pins
byte vspeedValue = 0xEE; // Value for "vspeed" characteristic in hexadecimal
byte rpmValue = 0xAA; // Value for "rpm" characteristic in hexadecimal
void sendATCommand(String command) {
HM10.println(command);
delay(500); // Allow time for the HM-10 to respond
while (HM10.available()) {
Serial.println(HM10.readString());
}
}
void setup() {
Serial.begin(9600);
HM10.begin(9600); // Initialize SoftwareSerial for HM-10
// Configure HM-10
sendATCommand("AT+ROLE0"); // Set the HM-10 as a peripheral (GATT server)
sendATCommand("AT+UUID0xFFE0"); // Set a custom service UUID (0xFFE0)
// Define and set the "vspeed" characteristic with UUID 0xFFE1
sendATCommand("AT+CHAR0xFFE3");
// Define and set the "rpm" characteristic with UUID 0xFFE2
sendATCommand("AT+CHAR0xFFE4");
sendATCommand("AT+NAMEYourDeviceName"); // Set the device name
delay(500); // Give the HM-10 some time to configure
Serial.println("Peripheral device is advertising...");
}
void loop() {
// Use AT commands to write data to the "vspeed" characteristic
String atCommandVSpeed = "AT+CHAR0xFFE1=" + String(vspeedValue);
sendATCommand(atCommandVSpeed);
// Use AT commands to write data to the "rpm" characteristic
//String atCommandRPM = "AT+CHAR0xFFE2=" + String(rpmValue);
//sendATCommand(atCommandRPM);
// Wait for a moment (optional)
delay(5000); // Delay for 5 seconds before sending the next values
}