Go Down

Topic: SerialEvent() wont work (Read 4 times) previous topic - next topic

michaelheid

Hi,

iam currently porting my software for the ardunio mega to the new arduino Due.
Iam struggling currently with the simple thing "serialevent", however, it wont work.

I tested the blanko serialevent example.. i load it to the due board, opened the console and test to write some stuff to the board.
The RX of the programming port is blinkin when i write data, but serialevent never get called.

Any ideas? :(

IDE: arduino 1.5.1r2
Board: arduino due r3

Code:
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;
    }
  }
}


thanks alot..

michaelheid

I tried with another DUE board (i had another one, never used before) - just to be sure.
It also wont work with the other DUE, so i dont think its an hardware defect or something..

johnwasser

Code: [Select]

    if (inChar == '\n') {
      stringComplete = true;
    }


Is is possible that whatever code is sending text is not sending the expected newline character?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

selfonlypath

I'm struggling probably through the same issue where i've been using SerPro protocol open sourced by Alvaro, it has been working for more than 2 years within different MEGA (1280, 2560 rev 2 and rev 3) on different projects. When It will work OK then download on DUE but the SerPro protocol using Serial standard routines does not work. Please note that SerPro is an implementation HDLC on top of USB protocol plus has object oriented programming to add very easy any RX or TX commands coming from a GUI (Mac, PC or Linux) so among other things, has 16-bit CRC detection.

selfonlypath

Another aspect that might explain the problem, do some of you have been confronted to a endianness issue between MEGA, in fact all classic arduino AVR boards and DUE since we go from 8-bits to 32-bits. I've noticed the DUE compiler did check mistake when using INT on AVR so 16bits but if we leave this on DUE, it thinks of 32-bits or something else.

Go Up