By visualxl
#4947
I know that you can issue
[code]
+++
AT+EXIT
[/code]

But, how do you do that from sketch?

According to your documentation, the Serial Monitor has to be switched to [b]newline[/b] only before it can enter the AT mode. But what if I don't even want to open the Serial Monitor and just enter the AT mode?
[code]
Serial.println("+++"); //this won't enter the AT mode.
[/code]

The full codes as below. I was trying to send SMS. And the GSM can only be initialised after I enter the AT mode, and exit the AT mode. Please assist.

[code]
/*
* Send SMS
* Written by Syahmul on 22/5/2014
* Memory consumed: 15Kb
* Need to active AT command first before it can work
* Ref: http://arduino.cc/en/Tutorial/GSMExamplesSendSMS
*/

// libraries
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

void setup()
{
  // initialize serial communications
  Serial.begin(9600);

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected) {
    Serial.println("+++"); //how to do this??
    Serial.println(gsmAccess.begin());
    if(gsmAccess.begin()==GSM_READY) {
      notConnected = false;
    }else {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  Serial.println("AT+EXIT\r\n"); //and this??
  Serial.println("GSM initialized");
}

void loop()
{

  Serial.print("Enter a mobile number: ");
  char remoteNumber[20];  // telephone number to send sms
  readSerial(remoteNumber);
  Serial.println(remoteNumber);

  // sms text
  Serial.print("Now, enter SMS content: ");
  char txtMsg[200];
  readSerial(txtMsg);
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNumber);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

/*
  Read input serial
*/
int readSerial(char result[])
{
  int i = 0;
  while(1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if(inChar!='\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}

[/code]
By Jose
#4948
[quote="visualxl"]
[code]
Serial.println("+++"); //this won't enter the AT mode.
[/code]
[/quote]

Try Serial.print("+++"); // to enter AT mode
then
Serial.println("yourATcommand");
#4949
I have tried Serial.print("+++"); to enter AT mode but in vain. Should I be aware of any "AT" settings, so that the code below might work? Since, the name of Bluetooth by default is "BlunoV1.8", the LED 13 should blink for 3 seconds continuously. But, currently, I am not able to receive any response even after checking out Serial Monitor.

[code]char charReceived;

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(115200);
  Serial.print("+++");
  Serial.println("AT+NAME=?");
}

void serialEvent()
{
  while (Serial.available())
  {
    charReceived = Serial.read();
    if(charReceived == 'B') {
      digitalWrite(13, HIGH);
      delay(3000);
      digitalWrite(13, LOW);
      delay(3000);
    }
  }
}

void loop()
{
  delay(1000);
  Serial.println("AT+NAME=?");
  }
}[/code]
#4950
Oh, you need to throw in some delay.

Try something like this

[code]
void masterConfiguration() {
  Serial.print("+++");
  delay(150);
  Serial.println("AT+SETTING=DEFCENTRAL");
  delay(250);
  Serial.println("AT+ROLE=ROLE_CENTRAL");
  delay(150);
  Serial.println("AT+NAME=BabyRealMaster");
  delay(150);
  Serial.println("AT+BIND=0xD0FF50676DFD"); //Destination MAC to bind to
  Serial.println("AT+EXIT");
}
[/code]