receive data sent to HM-19 ble module and print to serial

Hi,
I am new to bluetooth, and there was a question I have:

I wanted to print things hm-19 receive to the Arduino Serial

Setup:

HM-19 ---> Arduino UNO
VCC ---> 5v
GND ---> GND
Tx ---> 8
Rx ---> 9

The software I used to send to HM-19 is LightBlue

when I use the following code, it won't work:

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial ble(8, 9);

void setup()
{
    Serial.begin(9600);
    ble.begin(9600);
}

void loop()
{
    if (ble.available() > 0)
    {
        Serial.write(ble.read());
    }

}

it prints:

If I change the "Serial.write(ble.read());" to "Serial.println(ble.read));", it prints a int.

**But it works when I use this code: **

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial ble(8, 9);
char recChar;

void setup()
{
    Serial.begin(9600);
    ble.begin(9600);
}

void loop()
{
    if (ble.available() > 0)
    {
        recChar = ble.read();
        Serial.println(recChar);
    }

}

In this case, I created a char variable 'recChar', and it works.

Can someone help me explain why that happens.

Thanks

Serial.write sends the raw data, the serial.print converts numbers to base 10 and characters to ASCII.

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