user70385: I am trying to setup bluetooth with a board that contains Arduino Leonardo chip.
My full setup is:
The main board: https://www.dfrobot.com/product-1148.html
The base shield: https://coolcomponents.co.uk/products/grove-base-shield-for-arduino-v2
The bluetooth module: https://wiki.seeedstudio.com/Grove-Serial_Bluetooth_v3.0/
The bluetooth module is connected to D8 port of the base shield.
The reason is "not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)." as explained here: https://www.arduino.cc/en/Reference/SoftwareSerial
Here is the full code.
#include <SoftwareSerial.h>   //Software Serial Port

/*Connect your Bluetooth Module to D8 otherwise it will not work due to Arduino Leonardo */

#define RxD         8
#define TxD         9
 
SoftwareSerial blue(RxD,TxD);

void setup()
{
    Serial.begin(9600);
    blue.begin(9600); //anything other than 9600 will not work
   
    // wait for serial port to connect. Needed for native USB
    while(!Serial){
    ;
    }
   
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
   
    Serial.print("Started\n");
    setupBlueToothConnection();
   
}

void loop() {
char recvChar;
    while(1)
    {
        if(blue.available())
        {//check if there's any data sent from the remote bluetooth shield
            recvChar = blue.read();
            Serial.print(recvChar);
           
        }
        if(Serial.available())
        {//check if there's any data sent from t he local serial terminal, you can add the other applications here
            recvChar  = Serial.read();
            blue.print(recvChar);
            delay(400);
        }
    }
}

void setupBlueToothConnection()
{
  //blue.begin(9600);
 
  blue.print("AT");
  delay(400);
 
  blue.print("AT+ROLES");  // set the role as slave
  delay(400);
 
  blue.print("AT+NAMESlave");   // set the bluetooth name as "Slave" ,the length of bluetooth name must less than 12 characters.
  delay(400);
 
  blue.print("AT+AUTH1");
  delay(400);
  blue.flush();
}

The output from the Serial Monitor (set as BOTH NL & CR, 9600) as follows:
Started
OKOK+Set:SOK+Set:SlaveOK+Set:1

The problem is when I send AT commands from terminal I get nothing in return.
However if I send AT command from the IDE, I am getting feedback from the bluetooth.

user70385: The issue is fixed.
Note: This is the version includes Serial1 rather than SoftwareSerial. The rest is the same.
Serial.read()

Returns the first byte of incoming serial data available.

So, when I send AT command from terminal, it does send "A" and then "T" rather than "AT" as a string which Bluetooth expects as stated in the product's documentation:

AT Command format: Uppercase AT command format. string format, without any other symbol. (e.g. \r or \n).

Hence, I have added the following function:
String SerialString() {   // Function to generate string from chars sent via Serial Monitor
  
  String inputString = "";  // to hold the string
  
  while (Serial.available()) {
    
    char inputChar = (char)Serial.read(); // get the new byte:
    inputString += inputChar;             // add it to the inputString:
    }
    
    return inputString;     // returns completed string 
}

Then inside void loop():
String WholeCommand = ""; 
if(Serial.available() > 0){
    WholeCommand = SerialString();
    Serial1.print(WholeCommand);
  }

Now, when I send AT from Serial Monitor, I can get OK from Bluetooth.

70385: <p>I am trying to setup bluetooth with a board that contains <strong>Arduino Leonardo</strong> chip.</p>
<p>My full setup is:</p>
<p>The main board: <a href="https://www.dfrobot.com/product-1148.html" rel="nofollow noreferrer">https://www.dfrobot.com/product-1148.html</a></p>
<p>The base shield: <a href="https://coolcomponents.co.uk/products/grove-base-shield-for-arduino-v2" rel="nofollow noreferrer">https://coolcomponents.co.uk/products/grove-base-shield-for-arduino-v2</a></p>
<p>The bluetooth module: <a href="https://wiki.seeedstudio.com/Grove-Serial_Bluetooth_v3.0/" rel="nofollow noreferrer">https://wiki.seeedstudio.com/Grove-Serial_Bluetooth_v3.0/</a></p>
<p>The bluetooth module is connected to D8 port of the base shield.
The reason is &quot;not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).&quot; as explained here: <a href="https://www.arduino.cc/en/Reference/SoftwareSerial" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/SoftwareSerial</a></p>
<p>Here is the full code.</p>
<pre><code>#include &lt;SoftwareSerial.h&gt;   //Software Serial Port

/*Connect your Bluetooth Module to D8 otherwise it will not work due to Arduino Leonardo */

#define RxD         8
#define TxD         9
 
SoftwareSerial blue(RxD,TxD);

void setup()
{
    Serial.begin(9600);
    blue.begin(9600); //anything other than 9600 will not work
   
    // wait for serial port to connect. Needed for native USB
    while(!Serial){
    ;
    }
   
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
   
    Serial.print(&quot;Started\n&quot;);
    setupBlueToothConnection();
   
}

void loop() {
char recvChar;
    while(1)
    {
        if(blue.available())
        {//check if there's any data sent from the remote bluetooth shield
            recvChar = blue.read();
            Serial.print(recvChar);
           
        }
        if(Serial.available())
        {//check if there's any data sent from t he local serial terminal, you can add the other applications here
            recvChar  = Serial.read();
            blue.print(recvChar);
            delay(400);
        }
    }
}

void setupBlueToothConnection()
{
  //blue.begin(9600);
 
  blue.print(&quot;AT&quot;);
  delay(400);
 
  blue.print(&quot;AT+ROLES&quot;);  // set the role as slave
  delay(400);
 
  blue.print(&quot;AT+NAMESlave&quot;);   // set the bluetooth name as &quot;Slave&quot; ,the length of bluetooth name must less than 12 characters.
  delay(400);
 
  blue.print(&quot;AT+AUTH1&quot;);
  delay(400);
  blue.flush();
}
</code></pre>
<p>The output from the Serial Monitor (set as BOTH NL &amp; CR, 9600) as follows:</p>
<pre><code>Started
OKOK+Set:SOK+Set:SlaveOK+Set:1
</code></pre>
<p>The problem is when I send AT commands from terminal I get nothing in return.
However if I send AT command from the IDE, I am getting feedback from the bluetooth.</p>
 70385: <p>The issue is fixed.</p>
<p><strong>Note:</strong> This is the version includes <strong>Serial1</strong> rather than <strong>SoftwareSerial</strong>. The rest is the same.</p>
<p><strong>Serial.read()</strong></p>
<blockquote>
<p>Returns the first byte of incoming serial data available.</p>
</blockquote>
<p>So, when I send AT command from terminal, it does send &quot;A&quot; and then &quot;T&quot; rather than &quot;AT&quot; as a string which Bluetooth expects as stated in the <a href="https://files.seeedstudio.com/wiki/Bluetooth_Shield_V2/res/Bluetooth_en.pdf" rel="nofollow noreferrer">product's documentation</a>:</p>
<blockquote>
<p>AT Command format: Uppercase AT command format. string format, without any other symbol. (e.g. \r or \n).</p>
</blockquote>
<p>Hence, I have added the following function:</p>
<pre><code>String SerialString() {   // Function to generate string from chars sent via Serial Monitor
  
  String inputString = &quot;&quot;;  // to hold the string
  
  while (Serial.available()) {
    
    char inputChar = (char)Serial.read(); // get the new byte:
    inputString += inputChar;             // add it to the inputString:
    }
    
    return inputString;     // returns completed string 
}
</code></pre>
<p>Then inside <code>void loop():</code></p>
<pre><code>String WholeCommand = &quot;&quot;; 
if(Serial.available() &gt; 0){
    WholeCommand = SerialString();
    Serial1.print(WholeCommand);
  }
</code></pre>
<p>Now, when I send AT from Serial Monitor, I can get OK from Bluetooth.</p>
