How can i change the string sent by my hm-10?

I am creating simple projects to understand how to work with the arduino uno and hm-10 module.

Currently, when I 'Read' from my hm-10, the output string is the Device Address. This has been the default since it was first used. I would like to send simple strings using this method. Is that possible?

Currently HM10.write() sends the string as a notification but i want to send the string such that when i connect in LightBlue, i can click 'read' instead of 'subscribe' to read the data.

Here is the code I am using:


#include <SoftwareSerial.h>

SoftwareSerial HM10(2, 3); // RX = 2, TX = 3

char appData;  

String inData = "";

void setup() {

  Serial.begin(9600);

  Serial.println("HM10 serial started at 9600");

  HM10.begin(9600); // set HM10 serial at 9600 baud rate

  pinMode(13, OUTPUT); // onboard LED

  digitalWrite(13, LOW); // switch OFF LED


}


void loop() {

  HM10.listen();  // listen the HM10 port

  while (HM10.available() > 0) {   // if HM10 sends something then read

    appData = HM10.read();

    inData = String(appData);  // save the data in string format

    Serial.write(appData);

  }


 

  if (Serial.available()) {           // Read user input if available.

    delay(10);

    //HM10.write(Serial.read());

  }

  if ( inData == "F") {

    Serial.println("LED OFF");

    digitalWrite(13, LOW); // switch OFF LED
    HM10.write("Testing...");


  }

  if ( inData == "N") {

    Serial.println("LED ON");

    digitalWrite(13, HIGH); // switch OFF LED

    HM10.write("Testing...");

  }

}

What is an HM-10?

1 Like

when you do that you just save the last byte in inData, you are not building it up with the full message

I would suggest to study Serial Input Basics to understand how to deal with the Serial port

1 Like

@jaredgibb
Try the following simple sketch first and then add other features.

#include <SoftwareSerial.h>
SoftwareSerial HM10(2, 3); // RX = 2, TX = 3

char appData;

void setup()
{
  Serial.begin(9600);
  HM10.begin(9600); // set HM10 serial at 9600 baud rate
  Serial.println("HM10 serial started at 9600");
}

void loop()
{
  while (HM10.available() > 0)
  {
    appData = HM10.read();
    Serial.println(appData);
  }
}
1 Like

It's not clear to me what your issue is with LightBlue.

See this tutorial on using it
https://punchthrough.com/lightblue-features/

When you navigate to the HM10 custom service, you should be able to see a Read Again and a Subscribe button.

1 Like

allow me to clarify:). LightBlue works as expected. I’m hoping to learn how to send vs transmit the string. I’m building an app in Thunkable that can send/receive strings using the Arduino and ble module.

At the moment, I can send single character commands as strings but can’t get a string back.

Instead the string is sent back as garbled text (in my app) But in light blue, when I “read” from the device, the message is always the devices connectionId. Only when I subscribe in LightBlue do I see the string I am trying to send.

I don't have an hm10 to test with and I don't understand what you are seeing.

Instead of Light Blue, perhaps you can try this custom app for the HM10.
http://www.dsdtech-global.com/2018/02/dsdtechbluetooth-android.html

Martyn Curry has a very detailed tutorial on the HM10 here
http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/

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