     }
   }
 
+  //try forcing a hardware reset
+  if (USE_HARDWARE_RESET) hardwareResetWithChecking();
+
+  //switch to desired baudrate
   if (cur_baudrate != TARGET_BAUDRATE) {
     //let's try commanding the BC127 to the new baud rate anyway
     Serial.println("Change baudrate on the BC127 to "  + String(TARGET_BAUDRATE) + "...");

  cur_baudrate = new_baud;
}

//If the baudrate to the BLE modue matches that baudrate that the BLE module expects,
//we should be able to ask its status and get a valid reply.  So, we don't get a valid
//reply, the baudrate of Serial1 probably does not match.


// USER PARAMETERS
const int TARGET_BAUDRATE = 115200;    //try 115200 (fast!) or 9600 (factory original)
const int FIRMWARE_VERSION = 7;        // what Melody firmware we are dealing with
const bool USE_HARDWARE_RESET = true;  //try to use the BC127 GPIO Pins to force a factory reset

const int pin_PIO0 = 5; //RevD = 56, RevE = 5   // Pin # for connection to BC127 PIO0 pin
const int pin_RST = 9;  //RevD = 34, RevE = 9   // Pin # for connection to BC127 RST pin


// //////////////////////////////////////////// Helper functions

const int baudrate_factory = 9600;       // here is the factory default
const int baudrate1 = baudrate_factory;  //here is one possible starting baudrate for the BLE module
const int baudrate2 = 115200;            //here is the other possible starting baudrate for the BLE module
int cur_baudrate;  // this is the baudrate that we've set Serial1 to be
void setSerial1BaudRate(int new_baud) {
  Serial1.flush();
