Go Down

Topic: MRK1000 won't work out with serialevent() (Read 845 times) previous topic - next topic

leo0918555

Hi, everyone
First, sorry about my bad english.
I've got a MKR1000 board. And I am trying function with serialevent().
The example code is from example >> 04.communication >> SerialEvent
The above example I've tried with Arduino Uno, it works well.
But when I upload the same example into MKR1000, it didn't work.
Does anyone have the same question or figure out how to make it?

Very appreciate for helping.

Code: [Select]
String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

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

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (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;
    }
  }
}

seitzt

#1
May 31, 2019, 03:55 pm Last Edit: May 31, 2019, 03:59 pm by seitzt
I am working on trying to get this to work as well. Probably to late for this to help, but the RxTx pins are not Serial, they are Serial1. If you need those pins use serialEvent1.
https://www.arduino.cc/reference/en/language/functions/communication/serial/serialevent/

Go Up