[partially solved] Using AT-Commands to setup HC-05 BT device

Hello together,

I'm pretty new in this environment and currently on my way to realize my first Arduino project :slight_smile:

'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?

Many thanks,
mathies

One line of code won't help anybody much but you might try here:

http://forum.arduino.cc/index.php?topic=209363.0

Are you sure that when you send AT commands with Serial.write the HC-05 is in AT mode?

Hello,

first of all, thanks for the fast response! :slight_smile:

@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.

Regards,
mathies

Try to change from Serial1.write("AT+NAME=Test\r\n"); to Serial1.print("AT+NAME=Test\r\n");

But i think this is not the problem..

Hello,

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?!

Regards,
mathies

I realy dont know why this dont work :confused:

Hey,

I partially got it :slight_smile:

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...?!

Thanks so far.

Regards,
mathies

Nice. Try to use two pull up resistors on the TX and RX if this changes anything.

Hi Luis,

what should be the size of the resistor? Is 1k sufficient?

Thanks,
mathies