serialEvent arduino 101 - on Serial1

I can not figure out if it’s my code that does not work or SerialEvents sela SerialEvents function is linked only to “Serial”

#include <SoftwareSerial.h>
SoftwareSerial myLog(7, 6); // RX, TX
//SoftwareSerial myLoRa(7, 6); // RX, TX
//HardwareSerial& myLoRa = Serial;
HardwareSerial& myLoRa = Serial1;
//HardwareSerial& myLoRa = Serial2;
//HardwareSerial& myLoRa = Serial3;

void serialEvent() {

  myLog.println( F("serialEvent") );
while ( myLoRa.available() > 2 ) {
     }
    }

Hi dataino,
the SerialEvent API is obsolete and only makes sense on boards with a single UART (or Processing).
The relevant code is here and it shows that only the first serial port is handled. You should move to available() calls inside the loop to make your sketch compatible with all boards generations.

Hello

I welcome the suggestion and I will modify the code in the coming hours
But then why does my code work?
properly receive the data on LoRa modem on pin 0 and 1

look at my code attached.

Thank you

IOT-LORA.ino (10.1 KB)

You should put serialEvent1 code into loop(), out of timeout handling, so it is only called when Serial1.available() returns more than 0. This way you achieve the same result you had with an AVR board (the SerialEvent code is called after every loop() execution)

So I’m a bit new with Arduino, and not sure I really understand the solution for this issue. I currently have a project where one board is broadcasting over UART every five seconds with a fixed String (will expand it later, but trying to make it work first), and I can receive it on an Uno board without a problem. I’ve modified my sketch after reading this post, but not seeing the text come through.

#include <UARTClass.h>

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial1.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  while (Serial1.available()) {
    Serial1.println("Serial available");
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial1.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

Anyone able to point me in the right direction? I’m required to use an Arduino 101 for this project via the rules in a contest.

The following code works for Serial1. I tried it, it works.
You can try.

So serial1 to

void serialEvent1 () {

}

is used.

gps_EVENT.ino.ino (1.67 KB)