Hardware serial issue, HC-05 to Nano 33 BLE Sense

Hi, I am trying to get an HC-05 working with newly purchased Nano 33 BLE Sense - I need classic bluetooth, not BLE.
I have spent days reading every post and troubleshooting, to no avail.

The below code works perfectly using software serial on my Uno (you can see the test code at the top) , but I cannot seem to get it working properly using either Serial1 or additional UART on the Nano.
Code is taken from the Serial basics thread.

//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3); //RX, TX
#include <Wire.h>
UART mySerial (digitalPinToPinName(8), digitalPinToPinName(3), NC, NC);  //TX, RX 

// Serial comm variables
char readTxt;    // string to store incoming message from bluetooth
const byte numChars = 32;
char receivedChars[numChars];
static byte ndx = 0;
boolean newData = false;

void setup(){
  mySerial.begin(9600);// Open serial port for HC-05
  Serial.begin(9600); // serial communication to check the data on serial monitor

 void loop(){

  void SerialReceive() {
    static boolean receiveInProgress = false;
    char startMarker = '<';
    char endMarker = '>';
  if (mySerial.available()>0) {
   while (mySerial.available()>0 && newData == false) {
      readTxt = mySerial.read();
        if (receiveInProgress == true) { // Receiving command
            if (readTxt != endMarker) {
                receivedChars[ndx] = readTxt;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
            else { // Command received
                receivedChars[ndx] = '\0'; // terminate the string
                receiveInProgress = false;
                ndx = 0;
                newData = true;
        else if (readTxt == startMarker) { // Beginning of command
            receiveInProgress = true;
    void showNewData() {
      if (newData == true) {
         receivedChars[0] = '\0'; // clear the string
          newData = false;

I have looped the serials and can send test messages from mySerial to Serial (USB), so I am certain there is no hardware issue.
Not sure why I need to include <Wire.h>, but it won't compile without it?

I actually do get some data transmitted, but shows nothing but rubbish in the serial window, and data only sometimes makes it through.
After sending the letter c about thirty times, I eventually get this in the serial monitor -

I really hope there is something simple I am missing, can someone please help?
Thank you very much!

Are you sending something like <hello> ?
Is the pairing done?

Thanks for the reply!

Yes, bluetooth paired/connected properly and transmission with start and end markers.
if I report each character as it is read readTxt = mySerial.read(); by sending readTxt to the serial terminal, I get a reading through almost every time I send something - but not always, sometimes it misses and the data is almost always rubbish (very occasionally the correct character seems to come through!). Something is changing the characters along the course of the transmission, maybe garbling the bytes?

It all works exactly as expected with the Uno so I am confident that the hardware side of it is all ok, baud rates ok. Also my loop wiring tests can send text backwards and forwards from any combinationof Serial, Serial1 and mySerial so I am sure I have the correct pins.
I use Bluetooth Serial Terminal from Win10 PC, and an app on android phone - exactly the same result with each, both work great with Uno but not with the Nano 33 BLE.
Also have tried with the HC-05 connected through Serial1, exact same result.


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