I'll be teaching a year 10 class on the Intel Galileo gen2 and there'll be a wide (but high-level) programming curriculum, which includes introduction to console printing, using Serial
.
I'd like the students to be able to write their printing code in setup()
so that it's only printed once and easily readable by them. However, it's impossible to be fast enough to upload a sketch and open the Serial Monitor (which flat out refuses to open before the sketch has started), and the Serial Monitor closes itself upon re-uploading code.
Without unnecessary (and potentially for the students, confusing) use of the delay
function in setup()
, it's impossible to read any output originating from setup()
; only things printed in loop()
(which are constantly re-printed) are ever discoverable.
So; is there a way to somehow keep the Serial Monitor open, or make it capture output from before it's opened, or delay the entire running of the sketch (rather than chucking in delays)?
We'll be using the standard Arduino IDE.
EDIT
This script was run in one of two conditions...
void setup() {
Serial.begin(9600);
// ensure Serial is ready
delay(1000);
for (int i=0; i < 10000; i++) {
Serial.println(i);
}
}
void loop() {
}
When the Serial Monitor was opened immediately after upload, all numbers from and including 0 to 9999 were recorded in the monitor.
When the Serial Monitor was opened around 5s after upload, only numbers upward of 2243 were observed. This suggests the sketch WAS being re-run (else no numbers would have been captured; the sketch runs in significantly less time than 5s) but that all numbers between 0 and 2243 were not captured by the monitor; as if opening the Serial Monitor late enough to cause a re-run causes some monitor overhead.
This strange loss of numbers is NOT time dependent: increasing the initial delay from 1s to 4s (and waiting longer after upload before opening the Serial) did not at all vary the soonest number recorded, suggesting it is some 'line' based overhead
(but of course, how could anything fail for 2243 lines?!)
With that mystery aside, this negates the automatic re-running of the sketch upon Serial Monitor opening from being actually useful.
Serial Monitor
is only a convenience (although the need to close and reopen it is APITA). There is nothing stopping you from using any other serial program; e.g. I have used Minicom, but most often use a dedicated serial program for logging.