From 76ff89e48e9f0aab32f87f7069045e0d660114a1 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 Date: Mon, 2 May 2022 15:44:43 +0200 Subject: [PATCH 01/11] Create If_setup()_runs_twice.md --- .../IDE Settings/If_setup()_runs_twice.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md diff --git a/content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md b/content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md new file mode 100644 index 00000000..22d949e1 --- /dev/null +++ b/content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md @@ -0,0 +1,18 @@ +--- +title: "If setup() runs twice" +--- + +The issue of the ```setup()``` function running twice when uploading a sketch has been reported in some boards. + +Since a port can only be connected to one application at a time, the Arduino IDE has to close and open the port a number of times to upload a sketch while the Serial Monitor is open. This process resets the board and the program runs again. + +The repeated output can be avoided in two ways + +1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. This resets the board without closing the port, resulting in no repeated output. +2. The board resets after approximately 100 milliseconds. By adding ```delay(150)``` at the start of the ```setup()``` function, the board will be reset before any of the following code is executed, preventing the repeated output. + +## Useful information + +* [Serial.read()](https://www.arduino.cc/reference/en/language/functions/communication/serial/read/) in Arduino reference +* [Serial input basics](https://forum.arduino.cc/t/serial-input-basics-updated/382007) in the Arduino Forum +* [If you get unexpected zeroes using Serial.parseInt() or Serial.parseFloat()](https://support.arduino.cc/hc/en-us/articles/4407876044434-If-you-get-unexpected-zeroes-using-Serial-parseInt-or-Serial-parseFloat-) From 38f40be80f169c77bf1422c3908da39998d69607 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 Date: Mon, 2 May 2022 15:48:52 +0200 Subject: [PATCH 02/11] linter --- .../{If_setup()_runs_twice.md => If_setup_runs_twice.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/Software and Downloads/IDE Settings/{If_setup()_runs_twice.md => If_setup_runs_twice.md} (100%) diff --git a/content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md b/content/Software and Downloads/IDE Settings/If_setup_runs_twice.md similarity index 100% rename from content/Software and Downloads/IDE Settings/If_setup()_runs_twice.md rename to content/Software and Downloads/IDE Settings/If_setup_runs_twice.md From d7d6684f03154ca409c0f7c807ebdc862e3284e3 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 Date: Mon, 2 May 2022 15:51:08 +0200 Subject: [PATCH 03/11] change filename to match title --- .../{If_setup_runs_twice.md => If-setup-runs-twice.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/Software and Downloads/IDE Settings/{If_setup_runs_twice.md => If-setup-runs-twice.md} (100%) diff --git a/content/Software and Downloads/IDE Settings/If_setup_runs_twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md similarity index 100% rename from content/Software and Downloads/IDE Settings/If_setup_runs_twice.md rename to content/Software and Downloads/IDE Settings/If-setup-runs-twice.md From 5417796849765e0b6bf5fa68af7e4739ea834047 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:30:00 +0200 Subject: [PATCH 04/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../Software and Downloads/IDE Settings/If-setup-runs-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index 22d949e1..f153264b 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -1,5 +1,5 @@ --- -title: "If setup() runs twice" +title: "If your board runs the sketch twice" --- The issue of the ```setup()``` function running twice when uploading a sketch has been reported in some boards. From 2fd4f09923d0f5b39859bd2dc6ce16ac297af5dc Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:30:29 +0200 Subject: [PATCH 05/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../Software and Downloads/IDE Settings/If-setup-runs-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index f153264b..31704121 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -6,7 +6,7 @@ The issue of the ```setup()``` function running twice when uploading a sketch ha Since a port can only be connected to one application at a time, the Arduino IDE has to close and open the port a number of times to upload a sketch while the Serial Monitor is open. This process resets the board and the program runs again. -The repeated output can be avoided in two ways +The repeated output can be avoided in two ways: 1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. This resets the board without closing the port, resulting in no repeated output. 2. The board resets after approximately 100 milliseconds. By adding ```delay(150)``` at the start of the ```setup()``` function, the board will be reset before any of the following code is executed, preventing the repeated output. From d9403913a1e1757ec54848791edb3c4f4db867b5 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:30:45 +0200 Subject: [PATCH 06/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../Software and Downloads/IDE Settings/If-setup-runs-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index 31704121..795a662f 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -9,7 +9,7 @@ Since a port can only be connected to one application at a time, the Arduino IDE The repeated output can be avoided in two ways: 1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. This resets the board without closing the port, resulting in no repeated output. -2. The board resets after approximately 100 milliseconds. By adding ```delay(150)``` at the start of the ```setup()``` function, the board will be reset before any of the following code is executed, preventing the repeated output. +2. The board resets after approximately 100 milliseconds. By adding `delay(150)` at the start of the `setup()` function, the board will be reset before any of the following code is executed. Increase the delay if needed. ## Useful information From f92ba7ca90e2a589853338c9fd829ede5690b07b Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:31:05 +0200 Subject: [PATCH 07/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../Software and Downloads/IDE Settings/If-setup-runs-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index 795a662f..b5a4021a 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -8,7 +8,7 @@ Since a port can only be connected to one application at a time, the Arduino IDE The repeated output can be avoided in two ways: -1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. This resets the board without closing the port, resulting in no repeated output. +1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. 2. The board resets after approximately 100 milliseconds. By adding `delay(150)` at the start of the `setup()` function, the board will be reset before any of the following code is executed. Increase the delay if needed. ## Useful information From 8489fe6d5820c1b29394dfc0c7b3bccbe84ac2ff Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:31:27 +0200 Subject: [PATCH 08/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../IDE Settings/If-setup-runs-twice.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index b5a4021a..5660a883 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -2,9 +2,15 @@ title: "If your board runs the sketch twice" --- -The issue of the ```setup()``` function running twice when uploading a sketch has been reported in some boards. +On some boards, uploading while the Serial Monitor is open causes the board to run once, before resetting and running the new sketch. This can cause `Serial.println()` output to display twice in the Serial Monitor. -Since a port can only be connected to one application at a time, the Arduino IDE has to close and open the port a number of times to upload a sketch while the Serial Monitor is open. This process resets the board and the program runs again. +This happens on boards without native USB capabilities (such as the UNO and Mega), which automatically reset when the port is opened. Since Arduino IDE needs to close the Serial Monitor for the upload tool to access the port, we get the following sequence of events: + +1. Upload is started in Arduino IDE. +2. The Serial Monitor port is closed. +3. The port is opened by the upload tool. The board resets, and runs briefly runs any sketch currently on the board. +4. After a short while (typically ~100 ms), upload finishes. +5. Serial Monitor reopens the port. The board resets a second time, and starts running the new sketch. The repeated output can be avoided in two ways: From 0007883bf269af6abee19b71bcde0172100f679c Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 <86349945+Renat0Ribeir0@users.noreply.github.com> Date: Mon, 9 May 2022 11:31:36 +0200 Subject: [PATCH 09/11] Update content/Software and Downloads/IDE Settings/If-setup-runs-twice.md Co-authored-by: seaxwi <71350948+seaxwi@users.noreply.github.com> --- .../Software and Downloads/IDE Settings/If-setup-runs-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md index 5660a883..74355681 100644 --- a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md +++ b/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md @@ -17,7 +17,7 @@ The repeated output can be avoided in two ways: 1. If one simply wants to repeatedly run the sketch to observe the output, there’s no need to upload the (same) sketch multiple times. Just press the reset button with the Serial Monitor open. 2. The board resets after approximately 100 milliseconds. By adding `delay(150)` at the start of the `setup()` function, the board will be reset before any of the following code is executed. Increase the delay if needed. -## Useful information +## Further reading * [Serial.read()](https://www.arduino.cc/reference/en/language/functions/communication/serial/read/) in Arduino reference * [Serial input basics](https://forum.arduino.cc/t/serial-input-basics-updated/382007) in the Arduino Forum From 7d921394c01fbaf9629c95f185c926a322f02d26 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 Date: Mon, 9 May 2022 11:47:36 +0200 Subject: [PATCH 10/11] change filename to match title --- ...setup-runs-twice.md => If-your-board-runs-the-sketch-twice.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/Software and Downloads/IDE Settings/{If-setup-runs-twice.md => If-your-board-runs-the-sketch-twice.md} (100%) diff --git a/content/Software and Downloads/IDE Settings/If-setup-runs-twice.md b/content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md similarity index 100% rename from content/Software and Downloads/IDE Settings/If-setup-runs-twice.md rename to content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md From 49a92a10347448b3e5746592e2cb95a0a7d23d41 Mon Sep 17 00:00:00 2001 From: Renat0Ribeir0 Date: Mon, 9 May 2022 11:49:02 +0200 Subject: [PATCH 11/11] linter --- .../IDE Settings/If-your-board-runs-the-sketch-twice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md b/content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md index 74355681..b02666f8 100644 --- a/content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md +++ b/content/Software and Downloads/IDE Settings/If-your-board-runs-the-sketch-twice.md @@ -8,7 +8,7 @@ This happens on boards without native USB capabilities (such as the UNO and Mega 1. Upload is started in Arduino IDE. 2. The Serial Monitor port is closed. -3. The port is opened by the upload tool. The board resets, and runs briefly runs any sketch currently on the board. +3. The port is opened by the upload tool. The board resets, and runs briefly runs any sketch currently on the board. 4. After a short while (typically ~100 ms), upload finishes. 5. Serial Monitor reopens the port. The board resets a second time, and starts running the new sketch.