Bluetooth & HC-06: unreadable Serial Output

Hi All

The serial monitor output is not readable. Also, earlier this afternoon, I have had clear (readable) responses from the HC-06 both from the Serial Monitor input and from the Android input over BTClassic. Now I get nothing.

The responses to the AT-commands input from the Serial Monitor are now nothing. The responses from the HC-06 input by the Android app are now unreadable.

What could the problem be?

A Fritzing image of my setup is attached. I’m compiling with an Arduino/Genuino Board. My platform is Linux, Fedora28. From my Android I’m using Marcelo Jose Rovai’s MJRobotBT Digi Ana Voice Control. I’ve done some house-keeping like switching my USB cables, clearing out old compiler objects from the /tmp-directory; ensured that the BT is disconnected before uploading, and stopped and started everything (except my PC?).

I’m puzzled as to why there are such changes over the space of a few hours.

The sketch I’m using is from Marcelo Jose Rovai, 30Jan16.

 /************************************************************
 Sketch for HC-06 test:
 
 AT Commands for test:
 
 ==> AT
 ==> AT+VERSION
 ==> AT+BAUDx where 'x' is 1 or 2 or 3 or ... (Baud rates)
  1——1200 2——2400 3——4800 4——9600 5——19200
  6——38400 7——57600 8——115200

 ==> AT+NAMEYYY where 'YYY' is a 20 char or less name.
 ==> AT+PINxxxx where 'xxxx' is four numbers. Example 1234.
 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

Marcelo Jose Rovai  - 30Jan16
 **********************************************************/

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); // RX, TX
String command = ""; // Stores response of bluetooth device
 
void setup()
{
 Serial.begin(9600);
 Serial.println("Type AT commands!");
 BT.begin(9600); // HC-06 usually default baud-rate
}

void loop()
{
 // Read device output if available.
 if (BT.available()) 
 {
   while(BT.available())  // While there is more to be read, keep reading.
   {
     delay(10); //Delay added to make things stable 
     char c = BT.read(); //Conduct a serial read
     command += c; //build the string.
   }
   Serial.println(command);
   command = ""; // Avoids repeating prev inputs
 }
 if (Serial.available()) // Read user input if available.
 {
   delay(10); // The DELAY!  ********** VERY IMPORTANT *******
   BT.write(Serial.read());
 }
}

This is an example of the the output when using the MJRobotBT app:

Type AT commands!
⸮
⸮
⸮
⸮
⸮

The output should have text like: dev1on, dev1off, dev2on, dev2off, dev3on, dev3off, etc, depending on which buttons I press.

Earlier this afternoon, when I typed in AT commands at the Serial Monitor, I had these responses; all readable and agreeing with documented replies, (from memory):

AT => OK
AT+NAMEEGB => OKsetNAME
AT+PIN9876 => OKsetPIN
AT+BAUD8 => I forget what the reply was.

Because it is an HC-06, I have limited myself to these 4 commands.

But now I get nothing back - no responses.

Well, I’m sure it’s something simple - but I can’t see it. Can you help?

I look forward to your ideas, Thanks
EGB

Is that the entire code? The display you're showing is indicative of the monitor receiving unprintable characters, i.e. 8bit bytes instead of 7bit char.

I can’t explain the display, particularly since the first line is OK, and the code looks reasonable.
Here is something similar that might fix it.
Serial monitor is just aide memoire, no user input. Modify the prints to suit.

 */
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 4); // RX | TX
String command = ""; // Stores response from HC-06 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth 

  Serial.print("AT      ");  
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    char c = Serial1.read();
      command += c;    
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats

  Serial.print("AT+NAMEFosters      "); 
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats

  Serial.println("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }
  delay(2000);   
  Serial.println(command);
  command = ""; // No repeats

  Serial.print("AT+BAUD8      ");  
  Serial1.print("AT+BAUD8");               //CHANGE SPEED TO 115K
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      command += (char)Serial1.read();    
    } 
  } 
delay(2000);       
Serial.println(command);
}

void loop(){
}   //one-shot - nothing here

DKWatson: Is that the entire code? The display you're showing is indicative of the monitor receiving unprintable characters, i.e. 8bit bytes instead of 7bit char.

Hi @DKWatson

Yes, that the entire code. It doesn't match my setup (which is the same as the Fritzing image), but it serves to debug my BT stuff.

And, your observation about "8bit bytes instead of 7bit char" is deep, the puzzle is noted. Strangely: earlier that afternoon, all characters were displaying fully as expected and in human readable form. Why would the Serial read()'s and write()'s change?

EGB

Often it has to do with timing issues. We forget at times that what we do elsewhere in our tasks is typically accomplished much quicker than the time it takes to process characters for serial output, which is incredibly slow by comparison. We can overwrite the buffers or even interrupt the entire process. There are very few built-in safeguards. It is said that programming in C gives you the tools to shoot yourself in the foot. Well, bare metal programming gives you what's needed to blow your whole bloody leg off. That's one reason there are delay functions. With nothing else to do, sometimes we simply have to wait for other processes to finish.

Hi All

Nick_Pyner:
I can’t explain the display, particularly since the first line is OK, and the code looks reasonable.
Here is something (code) similar that might fix it.
[/code]

I implemented your code. Added a few formatting features to help with debugging, etc. Then added a chunck into the loop() to capture commands from the MJRobot App to the HC-06.

Here’s that modified code:

/* */
#include <SoftwareSerial.h>
//SoftwareSerial Serial1(2, 4); // RX | TX // 2,4 for Nick_Pyner; 10, 11 for EGB
SoftwareSerial Serial1(10, 11); // RX | TX for EGB
String command = ""; // Stores response from HC-06
char c = "";

void   delay_function() {
  delay(5);
}
void   delay_function2() {
  delay(5);
}
void delay_function_read() {
  delay(10);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth
  Serial.println(" - - - - ");
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println("Type AT commands!");
  Serial.println(" - - - - \n");
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT      "); 
  delay_function();
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    c = Serial1.read();
    command += c;   
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT+NAMEFosters      ");
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      delay_function2();
      c = Serial1.read();
      command += c;   
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.println("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      delay_function2();
      c = Serial1.read();
      command += c;   
    }
  }
  delay(2000);   
  Serial.println(command);
  command = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT+BAUD8      "); 
  Serial1.print("AT+BAUD8");               //CHANGE SPEED TO 115K
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      delay_function2();
      c = Serial1.read();
      command += c;   
    }
  }
delay(2000);       
Serial.println(command);
}

void loop(){
  // Read device output if available.
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      delay_function_read();
      c = Serial1.read(); //Conduct a serial read
      command += c; //build the string.
    }
    Serial.println(command);
    command = ""; // Avoids repeating prev inputs
  }
  if (Serial.available()) { // Read user input if available.
    delay_function_read();
    Serial1.write(Serial.read()); // Cannot use Serial1.write(command);
  }
}

Before uploading, the BT was disconnected. After uploading your example, the HC-06 was manually connected with the App. Next the HC-06 was reset, causing the setup() to rerun. So a double entry of setup() output can be seen. Next, I pressed the 8 MJRobot buttons. This is the output:

 - - - - 
Sketch:   /home/graham/monitoring/ArduinoUno/HC_05_06_shells/HC-06_AT_NameFosters_Nick_Pyner/HC-06_AT_NameFosters_Nick_Pyner.ino
Uploaded: Jul 29 2018
Type AT commands!
 - - - - 

AT      
AT+NAMEFosters      
AT+PIN1234

AT+BAUD8      
 - - - - 
Sketch:   /home/graham/monitoring/ArduinoUno/HC_05_06_shells/HC-06_AT_NameFosters_Nick_Pyner/HC-06_AT_NameFosters_Nick_Pyner.ino
Uploaded: Jul 29 2018
Type AT commands!
 - - - - 

AT      
AT+NAMEFosters      
AT+PIN1234

AT+BAUD8      
⸮
⸮
⸮
⸮
⸮
⸮
⸮
⸮

I pressed 8 MJRobot buttons in sequence expecting the following output on the Serial Monitor:
dev1on
dev1off
dev2on
dev2off
dev3on
dev3off
dev4on
dev4off

Instead, I got 8 reverse question marks.

The Serial1.read() of commands, reading input to the HC-06 from the MJRobot-App, doesn’t seem to be working. It gets corrupted!

The MJRobot-App does work. And has generated the above chars earlier today. I cannot recreate the circumstances though. Frustrating.

Could there be a BAUD-rate problem? To slow; too fast. Tuning issue? Also the delay(n) seems to be critical. Does the solution lie in a mix of these of BAUD-rate and delay(n)?

If you have any ideas, please let me know!

Thanks
EGB

Hmmm. Maybe your problem is your insistence on adding the "formatting features", which are utterly unwarranted. Since this code uses software serial, there is no need to disconnect bluetooth.

On the understanding that your problem is all to do with configuring Bluetooth and nothing to do with robots, I can't comment on the robot buttons other than that, since they have nothing to do with configuring bluetooth, they are best left out of the game. Do one job at a time.

Nick_Pyner: ... Since this code uses software serial, there is no need to disconnect bluetooth.

Your comment helps focus me. 1) You suggest the upload is not affected by whether BT is connected ir not. That simplifies testing. 2) It also points to an area where I am VERY unclear, namely: how the data gets read and transferred between the two channels, like: Serial (to/from the Monitor) and Serial1 (to/from devices connected by BT). 3) I also need to understand why the corruption is occurring.

I will dig further.

Thank you for your support,

Regards EGB

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

3) I also need to understand why the corruption is occurring.

It sounds to me like the issue is with the output of the MJRobot-App.

One thing to help you trouble shoot is to use a standard Android Bluetooth Terminal App like Kai Morich's Bluetooth Serial Terminal. As well as text input , it has six buttons you can program for your commands. You can set different line endings as well..

https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US

Hi All All!

I am still getting corrupted data in the serial patheway from the BT-app to the HC-06 to the Serial-Monitor.

cattledog:
One thing to help you trouble shoot is to use a standard Android Bluetooth Terminal App like Kai Morich’s
Bluetooth Serial Terminal.

Hi there @cattledog
I am using

  • Bluetooth Terminal by Qwerty
  • Serial Bluetooth - with 6 programmable buttons and a free text field
  • and, of course, the MJRobot.

I am finding the Serial Bluetooth very, very good. Honestly, I couldn’t get it to connect, until I realised that one button meant open/connected! I’m slow! But, I’ll get there!

All applications show the same corruption. The corrupted data transmission is not to do with the applications - I believe!

The material about the hardware/software pins is confusing. I have wired my board/arduino as specified in GUIDE_2BT.

I worked with 5 test configurations:

// SoftwareSerial Serial1(2, 4); // RX | TX // 2,4 for Nick_Pyner; with and without the 2K/1Kohm bridge
// SoftwareSerial Serial1(10, 11); // RX | TX with and without the 2K/1Kohm bridge
SoftwareSerial Serial1(0, 1); // RX | TX for HC-06 using the 2K/1Kohm bridge

I generated this output:
AT from the setup() for all test confurations
AT+NAMEFosters from the setup() for all test confurations
AT+PIN1234 from the setup() for all test confurations
AT+BAUD4 from the setup() for all test confurations
AT loop(); Serial Monitor input, except when using Serial1(0, 1); RX | TX test
⸮ loop();from Serial Terminal Key1, for all test configurations
⸮ loop();from Serial Terminal Key2, for all test configurations
⸮ loop();from Serial Terminal Key3, for all test configurations
⸮ loop();from Serial Terminal Key4, for all test configurations
⸮ loop();from Serial Terminal Key5, for all test configurations
⸮ loop();from Serial Terminal Key6, for all test configurations
⸮ loop();from Serial Terminal string input, for all test configurations

I get this syncing error when uploading using the Serial1(0, 1) RX|TX. But I was still able to connect:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
 ...

Here’s my code:

/* */
#include <SoftwareSerial.h>
// SoftwareSerial Serial1(2, 4); // RX | TX // 2,4 for Nick_Pyner; 10, 11 for EGB
// SoftwareSerial Serial1(10, 11); // RX | TX for EGB
SoftwareSerial Serial1(0, 1); // RX | TX for HC-06
String readString = ""; // Stores response from HC-06
char c = "";
// String c = "";

void   delay_function() {
  delay(3);
}
void   delay_function2() {
  delay(3);
}
void delay_function_read() {
  delay(3);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT"); 
  delay_function();
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    c = Serial1.read();
    readString += c;   
    }
  }
  delay(1000);
  Serial.println(readString);
  readString = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT+NAMEFosters");
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more, keep reading.
      delay_function2();
      c = Serial1.read();
      readString += c;   
    }
  }
  delay(1000);
  Serial.println(readString);
  readString = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more, keep reading.
      delay_function2();
      c = Serial1.read();
      readString += c;   
    }
  }
  delay(1000);   
  Serial.println(readString);
  readString = ""; // No repeats
// - - - - - - - - - - - - - - - - - - - - - - - 
  Serial.print("AT+BAUD4"); 
  Serial1.print("AT+BAUD4");               //9600 HZ
  delay_function();
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      delay_function2();
      c = Serial1.read();
      readString += c;   
    }
  }
  delay(1000);       
  Serial.println(readString);
}

void loop(){
  // Read Bluetooth transmissions, from Android to HC-06
  if (Serial1.available() > 0) { // number of chars waiting in the serial-pipeline
    while(Serial1.available() > 0) { // While there is more, keep reading.
      delay_function_read();
      c = Serial1.read(); //Conduct a serial read
      readString += c; //build the string.
    }
    // Serial.println(readString);
    // readString = ""; // Avoids repeating prev inputs
  }
  // Relays Bluetooth transmission to serial monitor
  if (readString.length() > 0) {  
    int i;
    int j = readString.length();
    for (i = 0; i < j; i++) {
      Serial.print(readString.charAt(i));
    }
    Serial.println("");
  }
  readString = ""; 
  
  // Read Serial Monitor input
  if (Serial.available() > 0) { // Read user input if available.
    while(Serial.available() > 0) { // While there is more, keep reading.
      delay_function_read();
      c = Serial.read(); //Conduct a serial read
      readString += c; //build the string.
    }
    // Serial.println(readString);
  }

  // Transmit the Serial string into the Bluetooth channels
  if (readString.length() >0) {  
    int i;
    int j = readString.length();
    for (i = 0; i < j; i++) {
      Serial.print(readString.charAt(i));
      Serial1.write(readString.charAt(i));
    }
    Serial.println("");
    Serial1.write("\r");
    Serial1.write("\n");
  }
  readString = ""; 
  delay_function_read();
}

The word is that BT is so simple. Yet I am unable to solve this corruption.

Can you help?

Regards
EGB

Read reply #9 again, twice. The same goes for line 3 of reply #2.

EGB: The material about the hardware/software pins is confusing. I have wired my board/arduino as specified in GUIDE_2BT.

The reasons for using pins 0,1 hardware serial is clearly explained in the notes

SoftwareSerial Serial1(0, 1); // RX | TX for HC-06

Never use software serial on hardware serial pins - ever. It is always a good idea to use a 1k/2k voltage divider. If you have intended to change the name of HC-06, you can check that by scanning for it with the phone. If you have succeeded in that, all the other commands should be kosher. I admit that method is pretty crude, but it is really all you need.

You need to pick a path. Either use Software Serial for the Arduino/Bluetooth communication, or use Hardware Serial on 0/1 after you upload the code. You may be confusing the situation trying to get both to work.

For now, lets stick with SoftwareSerial Serial1(10, 11);

  • RX is digital pin 10 (connect to TX of other device)
  • TX is digital pin 11 (connect to RX of other device)

The HC06 modules TX pin is connected to 10 and the RX pin to 11. This is maybe where you are going wrong, in that the SoftwareSerial constructor is from the point of the Arduino with 10 the Aduino RX and 11 the Arduino TX. You must cross connect with the Bluetooth module. TX to RX and RX to TX.

The BT module will talk to the phone over the air, and to the Arduino over Software Serial. The Arduino will talk to the Serial Monitor over hardware serial through the usb which is the same as pin 0 and pin 1.

I am using Serial Bluetooth terminal. Connection is through the little icon which looks like two connectors, and the module flash is 2x every 5 seconds when connected.

Your code as written is working properly for me with the connections as described. What is entered in the Serial monitor is seen on both the monitor and the phone and what is entered on the phone is seen on both the phone and the monitor.

Your serial communication code is not written as I would do, but that can be left for later, once you get things working. Recognizing the specific input from the phone or the monitor for the arduino to take action is also down the road.

One difference in my testing, which may or may not be relevant, is that I am using an HC05, and I am not entering AT mode.

As Nick has pointed out, if you have changed the module name, you may have to re-pair the phone in the Bluetooth settings of Android. In the terminal app, under "devices", you should see the module with the name you have given it.

Hi All

I’m still getting corrupted input over Bluetooth. The purpose of this response is 1) to CLEARLY address and USE YOUR KEY ADVICE. But still, 2) TO FIND the CAUSE of the CORRUPTED INPUT - dragging on painfully!

Line 3, message #2:

Nick_Pyner:
Serial monitor is just aide memoire, no user input. Modify the prints to suit.

@Nick_Pyner, I’m learning that the serial monitor is just a feedback/tracking/debugging/visualisation facility. It has nothing to do with the BT itself!

cattledog:
… trouble shoot … use a standard Android Bluetooth Terminal App like Kai Morich’s
Bluetooth Serial Terminal. … As well as text input , it has six buttons you can program for your commands. You can set different line endings as well…
https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US

Yes, the Bluetooth Serial Terminal is super! I’m using it.

Nick_Pyner:
It is always a good idea to use a 1k/2k voltage divider.

Noted: Even in SoftwareSerial? I need to think about this one.

cattledog:
As Nick has pointed out, if you have changed the module name, you may have to re-pair the phone in the Bluetooth settings of Android. In the terminal app, under “devices”, you should see the module with the name you have given it.

Several times I have used different AT+NAMExxxxxxx and BAUDx settings. I’ve tried clearing out all cashed data. Including powering down the arduino and the HC-06, removing wires, and taking them out of the board. Limited success. The Android cached data specifies the mac-address and name. But, something keeps the password and, perhaps, BAUD rates. I set the password as 9876, once. Now that feature is permanent. I cannot cannot clear the password. The BAUD rate may be set at something like BAUD8, 115200Hz. That may be causing the problems I have with corrupted input!

Do these parameters get BURNT into the HC-06 chips? Perhaps the result of “Burn Bootloader”.

cattledog:
You need to pick a path. Either use Software Serial for the Arduino/Bluetooth communication, or use Hardware Serial on 0/1 after you upload the code. You may be confusing the situation trying to get both to work.

For now, lets stick with … SoftwareSerial Serial1(10, 11);

  • RX is digital pin 10 (connect to TX of other device)
  • TX is digital pin 11 (connect to RX of other device)
    You must cross connect with the Bluetooth module. TX to RX and RX to TX.

The BT module will talk to the phone over the air, and to the Arduino over Software Serial. The Arduino will talk to the Serial Monitor over hardware serial through the usb which is the same as pin 0 and pin 1.

Done!

Attached is my code with SoftwareSerial Serial1(10, 11) and image attached, below. Only one LED is setup on my breadboard.

/*********************************************************
* MJRoBot DIGI_Ana_Voice Control over BT
* Project with digital and Analog variables
* Marcelo Rovai - 29jan16
**********************************************************/

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); //TX, RX respectively
String readString;

const int dev1 = 3; //PWM

void setup() 
{
  Serial.begin(9600);
  BT.begin(9600);
  pinMode(dev1, OUTPUT);
}

void loop() 
{
  while (BT.available()) {  //Check if there is an available byte to read
    delay(10); //Delay added to make thing stable 
    char c = BT.read(); //Conduct a serial read
    readString += c; //build the string.
  }  
  if (readString.length() > 0) {
     Serial.println(readString); 
     // Button control:
     // if (readString == "Test1") {digitalWrite(dev1, HIGH);}
     if (readString == "Test2") {
       digitalWrite(dev1, LOW);   // Only BT throughput turns it ON
     } else {
       digitalWrite(dev1, HIGH);  // Any throughput, incl corrupted stuff, turns it ON
     }
     delay(5000);
     digitalWrite(dev1, LOW); // Turn it off anyway, after a while
     readString="";  //Reset the variable
  } 
}

From my Bluetooth Serial Terminal, the text in M1 Test1, in M2 is Test2. An example of corrupted BT data from above code:

⸮⸮
⸮
⸮
⸮

I believe we are issolating the CAUSE of the CORRUPTED INPUT down to something in the Bluetooth channel - perhaps the BAUD rate. Perhaps it’s set - burnt into the HC-06 - at BAUD8.

Is that likely? Could I have accidentally selected Burn Bootloader? Have I screwed my HC-06?

To chech that out, I will switch to my HC-05s, and see what they bring!

I look forward to your reply.
EGB

EGB:
:@Nick_Pyner, I’m learning that the serial monitor is just a feedback/tracking/debugging/visualisation facility. It has nothing to do with the BT itself!

Correct. It would do no harm to dispense with those commands.

Noted: Even in SoftwareSerial? I need to think about this one.

No, you don’t. Just do it. It has nothing to do with the type of serial you use, and everything to do with the voltage at the Tx pin.

Several times I have used different AT+NAMExxxxxxx and BAUDx settings. I’ve tried clearing out all cashed data. Including powering down the arduino and the HC-06, removing wires, and taking them out of the board. Limited success. The Android cached data specifies the mac-address and name. But, something keeps the password and, perhaps, BAUD rates. I set the password as 9876, once. Now that feature is permanent. I cannot cannot clear the password. The BAUD rate may be set at something like BAUD8, 115200Hz. That may be causing the problems I have with corrupted input!

Do these parameters get BURNT into the HC-06 chips? Perhaps the result of “Burn Bootloader”.
Done!

Attached is my code with SoftwareSerial Serial1(10, 11) and image attached, below. Only one LED is setup on my breadboard.

/*********************************************************
  • MJRoBot DIGI_Ana_Voice Control over BT
  • Project with digital and Analog variables
  • Marcelo Rovai - 29jan16



I believe we are issolating the CAUSE of the CORRUPTED INPUT down to something in the Bluetooth channel - perhaps the BAUD rate. Perhaps it's set - burnt into the HC-06 - at BAUD8. 

Is that likely? Could I have accidentally selected Burn Bootloader? Have I screwed my HC-06?

All of the above is utter nonsense, including the code, but you almost certainly haven’t screwed anything. There are only three commands for HC-06, and all you can do is overwrite an old one with a new one by sending AT commands at the default baud rate 9600 before connecting by wireless, i.e. no inquiry, just tell.

I understand that your objective is to get HC-06 to work. I rather suspect that your only problem in this regard is your steadfast refusal to get rid of the LEDs and all that robot shit, and address the problem in hand.

Your problems with the HC-06 are not likely to be fixed by getting an HC-05 out of the bottom drawer, and the HC-06 is probably just fine for your needs.

A lot of the exercise with bluetooth is procedure, not code. There is a faint chance that you might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Success in this arena would then mean that you can fiddle with robot stuff secure in the knowledge that bluetooth is not your problem.

The code you have posted works on my HC05 in so much as the Test1 and Test2 commands sent by the macro buttons on the Serial Terminal phone app are echoed correctly on the serial monitor. There are some refinements to be made on line endings for the String comparisons, but that is not your main issue. Both commands(indeed any entry from the phone like "123" or "Hello World" with any line ending turn on the led for 5 seconds and are echoed in the phone and monitor.

Can you see the led go on? The phone and the module communicate wirelessly at full bluetooth speed, and should be independent of any serial communications between the module, Arduino and monitor.

You are correct to focus on baud rate issues. If I deliberately set the software serial baud rate to different values in the sketch and the monitor, or use values other than 9600, I can get the backwards question marks in the monitor, but the led is still going on and off with the phone input to the module.

Is the phone paired and connected? The macro buttons won't work if not connected, but the terminal app will show the error.

As I understand the HC06, the AT command mode is only active when the module is not connected to a phone. When connected, you are not in AT mode. If you are trying to reset things with AT commands, make sure the phone is not connected.

Noted: Even in SoftwareSerial? I need to think about this one.

If you are going to talk to the module from the monitor(like with AT commands) its a good idea to have module RX through the divider, but as Nick says, it's not likely to be fatal.