HC-05 and Arduino Nano Every

I am using the HC-05 with the Arduino Nano Every and with this Code:

const unsigned int MAX_MESSAGE_LENGHT=12;
#include <SoftwareSerial.h>
SoftwareSerial BT (2,3);
void setup() {
  // put your setup code here to run once:
BT.begin(38400);
Serial.begin(38400);
Serial.println("Booted up");
}
void loop() {
  // put your main code here, to run repeatedly:
while (BT.available()>0)
  {
    
    static char message[MAX_MESSAGE_LENGHT];
    static int mymesssage_position=0;

    char inByte=BT.read();
  
  if (inByte!='\n'&&(mymesssage_position<MAX_MESSAGE_LENGHT-1))
  {
    message[mymesssage_position]=inByte;
    mymesssage_position++;
  }
  else
  {
    message[mymesssage_position]='\0';
    Serial.println(message);
    mymesssage_position=0;

  }
}
while (Serial.available()>0)
  {
    
    static char message[MAX_MESSAGE_LENGHT];
    static int mymesssage_position=0;

    char inByte=Serial.read();
  
  if (inByte!='\n'&&(mymesssage_position<MAX_MESSAGE_LENGHT-1))
  {
    message[mymesssage_position]=inByte;
    mymesssage_position++;
  }
  else
  {
    message[mymesssage_position]='\0';
    BT.print(message);
    Serial.println("Message received. Redirecting to HC-05");
    mymesssage_position=0;

  }
}
}

Im only getting something like this on the serial monitor:

?xxxxx??x

I tried to work with stop bits,parity,...
You get the point.
Can you help me with this?

try to use Serial1 on RX/TX pins

Captain Obvious here but did you match the baud rate in your serial monitor to 38400? It defaults to 9600 I think. Did your "booted up" line in setup() print properly?

I am using the Arduino Nano Every.
It has only 1 Serial.

yes it printed

1 Like

Maybe add more Serial prints to the loop (after all your expected data in changes) that indicate where you are in the loop and see where it fails? So maybe

Serial.println("BT message in");

or things like that?

it has two

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