I wrote my custom sketch, where I am printing some greeting text inside setup()
method.
I found, that each time I am restarting IDE, and opening serial monitor, a greeting text is printed there again, i.e. setup()
method running again.
How can this happen? I was thinking setup()
method run once, when Arduino is powered up by connecting to the USB socket?
If it is possible to restart it already connected, then how this can be done?
UPDATE
Code is follows:
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
String command;
String awaitingMessage = "Temperature and pressure sensor awaiting commands\r\nCommand \'help\' is for help";
void awaiting() {
Serial.println(awaitingMessage);
}
void help() {
Serial.println("Temperature and pressure sensor commands:");
Serial.println("temp\t- output temperature in degrees Celsius");
Serial.println("press\t- output pressure in Pascals");
Serial.println("wait\t- print awaiting message");
Serial.println("help\t- output this text");
}
void temperature() {
Serial.println(bmp.readTemperature());
}
void pressure() {
Serial.println(bmp.readPressure());
}
void unknown() {
if( command.length() > 0 ) {
Serial.println("Unknown command was \'" + command + "'");
}
}
void setup() {
Serial.setTimeout(50000);
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
else {
awaiting();
}
}
void loop() {
command = Serial.readStringUntil('\n');
if( command.startsWith("temp") ) {
temperature();
}
else if( command.startsWith("press") ) {
pressure();
}
else if( command.startsWith("wait") ) {
awaiting();
}
else if( command.startsWith("help") ) {
help();
}
else {
unknown();
//awaiting();
}
}
Video is here: https://youtu.be/-QBleGVxaus