I do not understand how the output works. I modified a Bluetooth sample program to work with my HM-19 Bluetooth module:
#include <SoftwareSerial.h>
#define rxPin 10 // yellow
#define txPin 11 // green
SoftwareSerial BTSerial(rxPin, txPin); // RX, TX
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
while(!Serial);
BTSerial.println("AT+DISI?");
}
void loop() {
// read from HM-19 and print in the Serial
if(BTSerial.available())
Serial.write(BTSerial.read());
//read from the Serial and print to the HM-19
if(Serial.available())
BTSerial.write(Serial.read());
}
My first guess would be that you are running out of input buffer. Instead of starting to empty the buffer almost immediately you are waiting for a full second and then asking for more input before even starting to pull characters from the buffer.
johnwasser:
My first guess would be that you are running out of input buffer. Instead of starting to empty the buffer almost immediately you are waiting for a full second and then asking for more input before even starting to pull characters from the buffer.
Something like that was my first guess, too. But the other way round: It was the reason for me to add the delay, because
My guess is that the module receiving the second command before the first command has completed was causing both to fail.
You should probably only send a command when you are immediately ready to receive the response and not send another command until the first response is complete.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
johnwasser:
My guess is that the module receiving the second command before the first command has completed was causing both to fail.
You should probably only send a command when you are immediately ready to receive the response and not send another command until the first response is complete.
My guess exactly. That's why I put the delay in there.
Robin2:
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.