mauroaraujo
mauroaraujo

Reputation: 342

How to send AT commands to BT Shield iteadstudio (Master/Slave) - Arduino?

I'm here to ask a question about how to send AT commands to BT Shield. I've already tried all tha ways with the iteadstudio's guide...

Hardware: Arduino UNO R3 BT Shield (Master-Slave) iteadstudio

Proccedure: Programmed that code:

#include <SoftwareSerial.h>   //Inlcui a biblioteca SoftwareSerial.h

#define RxD         6 //Define RxD como 6
#define TxD         7 //Define TxD como 7

#define LED_AMARELO    2 //LED_AMARELO_BLINK como 2
#define LED_VERMELHO    3 //LED_VERMELHO_FADE como 3
#define RELE_LAMPADA         4 //RELE_LAMPADA como 4

SoftwareSerial blueToothSerial(RxD,TxD); //Instância a biblioteca SoftwareSerial.h

void setup()
{

  pinMode(LED_AMARELO, OUTPUT); //Configura o pino 2 como saída
  pinMode(LED_VERMELHO, OUTPUT); //Configura o pino 3 como saída
  pinMode(RELE_LAMPADA, OUTPUT); //Configura o pino 4 como saída
parear_dispositivo(); //Executa a função para parear o dispositivo
}

void loop()
{
  char letra; //Variável char para armazenar o caractere recebido
if(blueToothSerial.available()) //Se algo for recebido pela serial do módulo bluetooth
    {
      letra = blueToothSerial.read(); //Armazena o caractere recebido na variável letra
if(letra == 'A') digitalWrite(LED_AMARELO, HIGH); //Se o caractere recebido for a letra A, liga o LED Amarelo
      else if(letra == 'a') digitalWrite(LED_AMARELO, LOW); //Senão se o caractere recebido for a letra a, desliga o LED Amarelo
      else if(letra == 'B') digitalWrite(LED_VERMELHO, HIGH); //Senão se o caractere recebido for a letra B, liga o LED Vermelho
      else if(letra == 'b') digitalWrite(LED_VERMELHO, LOW); //Senão se o caractere recebido for a letra b, delisga o LED Vermelho
      else if(letra == 'C') digitalWrite(RELE_LAMPADA, HIGH); //Senão se o caractere recebido for a letra C, liga a Lâmpada
      else if(letra == 'c') digitalWrite(RELE_LAMPADA, LOW); //Senão se o caractere recebido for a letra c, desliga a Lâmpada
      else if(letra == 'H') digitalWrite(9, LOW);
      else if(letra == 'h') digitalWrite(9, HIGH);
  }
}

void parear_dispositivo()
{
  blueToothSerial.begin(9600); // Configura o baud rate do bluetooth como 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); // Configura o módulo bluetooth para trabalhar como slave
  blueToothSerial.print("\r\n+STNA=SeedBTShield\r\n"); // Configura o nome do disopsitivo bluetooth
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permite que outros dispositivos encontrem o módulo bluetooth
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Desabilita a auto conexão
  delay(2000); // Aguarda 2 segundos
  blueToothSerial.print("\r\n+INQ=1\r\n"); // Habilita modo de paridade
  delay(2000); // Aguarda 2 segundos
  blueToothSerial.flush(); // Dá um flush na serial do módulo bluetooth
}

Mode Set switch: CMD

UART multiplexer: D0 as RX, D1 as TX -> At manual it's saying: "When using the connection as Figure 4, the HC-05 connectswith the FT232RL chip, and the FT232RL connect to PC by USB. Whit this configuration you can use the serial software on PC to control or configurethe HC-05 module."

PS.: I've already tried with D0 as TX and D1 as RX.

Proccedure:

-> Set mode set switch to CMD.

-> Plugged BT Shield in Arduino

-> Connect Arduino at PC

-> Selected the correct serial port

-> Flashed/Uploaded to Arduino UNO the program (according to the code). (I've also tried the dafault sample at File->Examples->SoftwareSerial->SoftwareSerialExample).

-> Finally open the Monitor Serial

What happens:

-> When I open the Monitor serial and send a command as: AT\n\r or just AT nothing happens...

-> The maximun I've conquested was with the SoftwareSerialExample.ino code... It appeared "Test OK" (Yes, I've just modified the string).

->So, I cannot send any AT command because it doesn't works.

PS.: I'm just trying to send AT because the BT isn't working when I send a command from my application as "A" or "b", so the program isn't working with this shield (Before you ask me, yes, I've already tried this code with another arduino (also UNO) and another shield). I hope you can help me.

Upvotes: 1

Views: 4537

Answers (1)

mauroaraujo
mauroaraujo

Reputation: 342

I found a way to do what I was needing. Just following this seteps you can do what I was trying to do. XD.

Step 1

Disconnect the shield from the arduino and upload the default blink sketch. Verify the sketch is running. Step 2

Image_PIN_MODE

On the unconnected shield set the jumpers as in this picture. Put the switch to CMD

Step 3

Connect the shield to the arduino and connect the arduino to the PC. Configure the com port on the PC (using device manager under windows) to use

Baud    38400
data bits   8
stop bits   1
parity  none
flow control    none

and connect to the shield using a terminal program like TeraTerm. Make sure, the terminal program uses the same port settings.

Under TeraTerm, an empty window appeares and when I hit return, I got ERROR:(0). No worries, just type AT and return and you should get OK as answer. You may need to retype this command several times. After that, any of the documented AT commands can be issued. I used AT+NAME=ArduinoBT to test Be aware, that the UART port speed only affects the port speed the board talks to the arduino! The port speed for command settings using AT is fixed to 38400.

I've found this example at: Reference

Upvotes: 2

Related Questions