Hello,
When HC-05 is connected to RX and TX pins of Nano 33 BLE, Serial1 sends data to PC, but transmitting to Arduino does not work . The same code works well in Arduino Uno using SoftwareSerial as well as hardware Serial. What's wrong with Nano 33 BLE?
br, EHi
// #include <SoftwareSerial.h>
// SoftwareSerial mySerial(10, 11); // RX, TX
boolean newData = false;
const byte numChars = 32;
char receivedCmd[numChars];
unsigned long t1 = millis();
void setup() {
Serial1.begin(9600); // Nano 33 BLE (RX, TX)
// Serial.begin(9600); // Uno hardware serial (RX, TX)
// mySerial.begin(9600); // Uno software serial
}
void loop() {
// put your main code here, to run repeatedly:
readCommandData();
delay(1000);
if (newData == true) { // new command string
String cmdStr = String(receivedCmd);
Serial1.print("Reveived command: ");
// Serial.print("Reveived command: ");
// mySerial.print("Reveived command: ");
Serial1.println(cmdStr);
// Serial.print("Reveived command: ");
// mySerial.println(cmdStr);
newData = false;
}
//---
if (millis() - t1 > 5000) {
Serial1.println("Still alive...");
// Serial.println("Still alive...");
// mySerial.println("Still alive...");
t1 = millis();
}
}
void readCommandData() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial1.available() > 0 && newData == false) {
// while (Serial.available() > 0 && newData == false) {
// while (mySerial.available() > 0 && newData == false) {
rc = Serial1.read();
// rc = Serial.read();
// rc = mySerial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedCmd[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedCmd[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
Serial1.flush();
// Serial.flush();
// mySerial.flush();
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}