I am trying to get serial data thru TX/RX on nano 33 iot. but not receiving anything
so, I decided to verify using the example
and get the same results.. the sender responds to entered data on usb serial port
the receiver never responds.
I added verification in the receiver loop that it is running
but Serial1.available()>=0 never becomes true
the sender
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // set LED pin as output
digitalWrite(LED_BUILTIN, LOW); // switch off LED pin
while(!Serial)
Serial.begin(9600);
while(!Serial1)// initialize serial communication at 9600 bits per second:
Serial1.begin(9600);
//Serial1.println("test");// initialize UART with baud rate of 9600
}
void loop() {
if (Serial.read() == '1'){
Serial1.println('1');
Serial.println("loop");
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LEDS ON");
}
else if (Serial.read() == '0'){
Serial1.println('0');
Serial.println("loop1");
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LEDS OFF");
}
}
the receiver
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // set LED pin as output
digitalWrite(LED_BUILTIN, LOW); // switch off LED pin
while(Serial)
Serial.begin(9600);
while(!Serial1)
Serial1.begin(9600); // initialize UART with baud rate of 9600
}
void loop() {
while (Serial1.available() >= 0) {
char receivedData = Serial1.read(); // read one byte from serial buffer and save to receivedData
if (receivedData == '1') {
digitalWrite(LED_BUILTIN, HIGH); // switch LED On
}
else if (receivedData == '0') {
digitalWrite(LED_BUILTIN, LOW); // switch LED Off
}
}
}
Please provide details. I don't see anything added to the "receiver" sketch that could be considered "verification".
I do see this code you added though:
This code will cause the sketch to hang in a perpetual loop, calling Serial.begin(9600); over and over and over again until you connect the "receiver" board to your computer via its USB cable and open that board's serial port in the Arduino IDE Serial Monitor (or any equivalent application).
The tutorial is written with the intent that you only have the "sender" board connected to your computer with the Serial Monitor.
Since you aren't even doing anything with Serial in the "receiver" sketch, this seems like a very bad addition all around.
I also see this addition:
while(!Serial1)// initialize serial communication at 9600 bits per second:
Serial1.begin(9600);
This would cause Serial1.begin(9600); to be called over and over again as long as Serial1 is false. That a strange thing on its own, since you only need to call Serial1.begin(9600); once, but you'll see it is downright disastrous once you study the documentation:
On the boards with native USB, if (Serial) (or if(SerialUSB) on the Due) indicates whether or not the USB CDC serial connection is open. For all other boards, and the non-USB CDC ports, this will always return true.
Serial1 is a "non-USB CDC port", so this means the while condition will never evaluate as true, and thus Serial1 is never initialized.
I strongly recommend starting out by following the tutorial exactly. Once you have the "known good" code working as expected, you can feel free to methodically iterate on that to add whatever additional functionality you want. But jumping right in with random modifications from the start is not a recipe for success.
so, altho the code isn't there now, I added a Serial.println() to loop, to insure it was running
I added a serial.println() to the end of setup to insure it finished
I added Serial.println to show that data was received from the Serial.available and read
the example says you don't NEED to have the receiver connected, but I do.
I added the whiles, just because my other sketches do.
Serial1.begin(115200);
while (!Serial){
Serial.begin(115200);
loop
void loop() {
while (Serial1.available() >= 0){
Serial.println("incoming data");
// write a message to serial to acknowledge data received
Serial.write(Serial1.read());
}
other stuff (BLE) which works)
get stuck in the while loop
08:54:54.436 -> ⸮incoming data
08:54:54.436 -> ⸮incoming data
08:54:54.436 -> ⸮incoming data
08:54:54.436 -> ⸮incoming data
08:54:54.436 -> ⸮incoming data
08:54:54.539 -> ⸮incoming data
08:54:54.539 -> ⸮incoming data
08:54:54.539 -> ⸮incoming data
08:54:54.539 -> ⸮incoming data
so, is serial1 not available when using BLE? on nano iot
i think there are two different chips Nina for wifi/ble
from the datasheet page 8
Communication with NINA W102 happens through a serial port and a SPI bus through the following pins
31 PA22 23 GPIO3 Processor TX Nina RX
32 PA23 22 GPIO1 Processor RX Nina TX