Arduino Micro sends with HC-06 but won't receive

Greetings! I am trying to simply send data to an Arduino Micro using and HC-06 bluetooth card. From the code below you'll see I have an LED on pin 7 which I'm trying to turn off as an indication that data has been received.

All of my send messages seem to work just fine ("Hello!", "You there?") however anything I send doesn't seem to get through. If I turn on the inData and printing statement, all I get are a bunch of -1 lines in my terminal (using Qwerty Bluetooth Terminal on my android phone to communicate with it).

Not sure if this is some kind of timing issue? If I change the baud rate to something other than 9600 the send messages come thru garbled.

Note: I included the FastLED library to leverage the "Every x seconds" functionality. Sort of ping to make sure I haven't dropped connection.

#include <SoftwareSerial.h>
#include <FastLED.h>

SoftwareSerial BT(6,5);
//int inData;

void setup() {
  // put your setup code here, to run once:
  BT.begin(9600);
  BT.println("Hello!");
  pinMode(7, OUTPUT);
  delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
//  inData = BT.read();
//  BT.println(inData);
  
  if (BT.available()) {
    delay(10);
    fromPC = (char)BT.read();
    digitalWrite(7,LOW);
    BT.println("received BT data");
  } else {
    digitalWrite(7,HIGH);
  }
  delay(100);

  EVERY_N_MILLIS(20000) BT.println("You there?");
}

SoftwareSerial will not send and receive data at the same time and your loop() may be atytempting to do that
setup the sertial monitor and change

BT.println("received BT data");

to output to Serial

Changed to below so that the write is happening at a different time than the read. The serial monitor is just showing a bunch of -1's still. What's interesting to me is that in the previous code the LED wouldn't even go off. Seems like either the chip is expecting some kind of different data to be sent to it, OR maybe there a setting I missed in my phone bluetooth terminal to work right?

looking at code in post#1

SoftwareSerial BT(6,5);

what Arduino board are you using? Not all pins on all boards support change interrupts required for SoftwareSerial.

I tested a version of your code from post#1 on a Mega using software serial on pins 10 and 11

#include <SoftwareSerial.h>
//#include <FastLED.h>

SoftwareSerial BT(10, 11);
//#define BT Serial1
//int inData;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  BT.begin(9600);
  BT.println("Hello!");
  pinMode(7, OUTPUT);
  delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
//  inData = BT.read();
//  BT.println(inData);
  
  if (BT.available()) {
    delay(10);
    char fromPC = (char)BT.read();
    digitalWrite(7,LOW);
    BT.println("received BT data");
    Serial.print("received BT data ");
    Serial.println(fromPC);
  } else {
    digitalWrite(7,HIGH);
  }
  delay(100);

//  EVERY_N_MILLIS(20000) BT.println("You there?");
}

works OK
Android displays

and the Arduino Serial monitor displays
IMega_SS_1

Note that the HC-06 uses 3.3V logic - when used with a Mega 5V logic a potential divider is required on the Mega TX to HC-06 Rx pin, e.g.

I'm using an Arduino Micro, not sure if that's an issue.

the Arduino Micro uses 5V logic so you require a potential divider on the Micro Tx to HC-06 Rx (similar to mega in post #4)
software-serial documentation states
Not all pins on the Leonardo and Micro boards support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
so you need to modify

SoftwareSerial BT(6,5);

try

SoftwareSerial BT(10, 11);

as in the sample code of post # 4

Perfect, switching to Pins 10 and 11 fixed it!! Thanks a bunch for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.