I'm pretty new in this environment and currently on my way to realize my first Arduino project
'Cause I did not found any point in this forum dealing with the HC-05 device I hope that somebody is able to help me.
I'm using a Arduino Leonardo with an HC-05 BT device. What I realized so far is to change all settings of the HC-05 by using the Serial Monitor.
My problem now is that all commands which are working perfect if sent by Serial Monitor are not working if I sent it from internal functions. For example:
Entry made by Serial Monitor (using NL and CR) which works fine: AT+NAME=Test
(Internaly this string is sent via Serial1.write() to the HC-05 device.)
Code snippet which has no effect on BT Settings:
Serial1.write("AT+NAME=Test\r\n");
Does anyone has an idea what is going wrong here? Is there a syntax problem or something like that?
@Nick_Pyner:
I just want to avoid any additional complexity. Because of that I just put one line of code here. I'm doing exactly the same in both cases, just the way of sending the AT Command is different (function and Serial Monitor input). So my thought was that there is a formatting mistake or something like that.
@LuisCRSousa:
I'm pretty sure, yes - 2 seconds blinking. Furthermore, as mentioned above, it is exactly the same code until sending the AT Command. If it comes from Serial Monitor everything is great, if from function call nothing happens.
I do not have access to my code right now but the following lines should show the difference.
Code snippet for Serial Monitor control:
// entering AT command mode
...
// state machine for command control
...
// state for listening to Serial Monitor
case X:
 // Read input from Serial Monitor
 if( Serial.available() )
 {
  Serial1.write( Serial.read() );
 }
 // Write response of BT module to Serial Monitor
 if( Serial1.available() )
 {
  Serial.write( Serial1.read() );
 }
 break;
...
Code snippet for function control:
// entering AT command mode
...
// state machine for command control
switch( nextState )
...
// state for sending just one command
case X:
 Serial1.write("AT+NAME=Test\r\n");
 nextState = Y;
 break;
// State for checking response
case Y:
 if( Serial1.available() )
 {
  Serial.write( Serial1.read() );
 }
 break;
...
So, the procedure to enter the command mode is exactly the same, I just modify the content of the states which are responsible to send the AT command.
I also tried the print function call -> no change in behaviour. There must be a difference between the input of the Serial Monitor and the string I sent directly?!
I don't know why but if I send the command Serial1.write("AT+NAME=Test\r\n"); two times, it works. For the first command I got some strange reply ASCII sign 254 or ASCII sign 255. For the second command I got the OK.
Maybe there is something left in the send buffer...?!