I'm using a LinkIt ONE Arduino-like to send sensor data via MQTT.
It always worked very well, then out of the blue, it stopped printing anything using Serial.print();
But if I ommit the "Serial.begin(9600);" line, the code runs normally, sending sensor data via MQTT, even if I can't see debug output.
This shows the problem is on the Serial handling.
Since I can't show the entire code here, here's two test cases:
1.
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
while(!Serial); //Wait until Serial is ready before printing
}
void loop() {
Serial1.println("This came from serial 1"); //does nothing
Serial.println("This came from serial 0"); //works
delay(1000);
}
It shows me the following output:
This came from serial 0
This came from serial 0
Thi
Looks like the module freezes before the third iteration.
But if I omit the lines that aren't printed, from Serial1:
2.
void setup(){
Serial.begin(9600);
while(!Serial); //Wait until Serial is ready before printing
}
void loop() {
Serial.println("This came from serial 0"); //works
delay(1000);
}
No output is shown on Serial monitor.
What is the reason behind this? Since Serial1 prints nothing, why can't I remove it?
Observations:
I tested the code in two LinkIt ONE modules of the same model.
I tested it in Arduino SDK 1.6.8, 1.5.6r2 and 1.6.5.
Edit:
Just made another test using the code below. It blinked two times showing that
Serial.begin(9600); runs
while(!Serial); runs (it didn't freeze the module waiting for Serial to initialize)
But Serial.println(); freezes
void setup(){
pinMode(13, OUTPUT);
blink();
Serial.begin(9600);
blink();
while(!Serial); //Wait until Serial is ready before printing
}
void loop() {
Serial.println("This came from serial 0"); //works
blink();
delay(1000);
}
void blink(){
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}