With the following code I have successfully read data from the HM-10 module, but am unable to successfully write to the module. The original code from Martyn Currey had the read only within the Serial.available conditional, but I would like to write to the module (BTserial.write("done")) when it is done reading and writing to the serial monitor for a use within a mobile app I am building that relies on a response from the module.
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
// AltSoftSerial Library, for an extra serial port
char c=' ';
String inData;
boolean NL = true;
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(FILE);
Serial.print("Uploaded: "); Serial.println(DATE);
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
char recieved = BTserial.read();
inData += recieved;
// Process message when new line character is recieved
if (recieved == ' ')
{
Serial.print("Arduino Received: ");
Serial.print(inData + "\n");
BTserial.write("done");
inData = ""; // Clear recieved buffer
}
//c = BTserial.read();
//Serial.write(c);
//delay(1000);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
// do not send line end characters to the HM-10
if (c!=10 & c!=13 )
{
BTserial.write(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}
Any suggestions would be super helpful