I have an Arduino Uno with a Dragino Yun Shield on it. I am trying to run the sample code provided online pasted at the bottom. I upload the sketch and it starts running. I try to look at the serial monitor for the dragino but only the first line of the sketch prints before the line "Connection closed by foreign host" prints and the sketch stops running. Does anyone know what causes this? Is it something specific to the Yun shield setting that I can change?
Here's the code:
#include <Console.h>
String name;
void setup() {
// Initialize Console and wait for port to open:
Bridge.begin();
Console.begin();
// Wait for Console port to connect
while (!Console);
Console.println("Hi, what's your name?");
}
void loop() {
if (Console.available() > 0) {
char c = Console.read(); // read the next char received
// look for the newline character, this is the last character in the string
if (c == '\n') {
//print text with the name received
Console.print("Hi ");
Console.print(name);
Console.println("! Nice to meet you!");
Console.println();
// Ask again for name and clear the old name
Console.println("Hi, what's your name?");
name = ""; // clear the name string
}
else { // if the buffer is empty Cosole.read() returns -1
name += c; // append the read char from Console to the name string
}
}
}