You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learn/02.microcontrollers/04.debugging/debugging.md
+11-9Lines changed: 11 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -234,7 +234,8 @@ A simple example will demonstrate the implementation of some of the debugging te
234
234
235
235
```arduino
236
236
/*
237
-
LSM9DS1 accelerometer, gyroscope, and magnetometer tasks operation with debugging.
237
+
Program:
238
+
- Debugging_techniques_example.ino
238
239
239
240
Description:
240
241
- This example combines data from the LSM9DS1 accelerometer, gyroscope, and magnetometer into a single code. On top of it,
@@ -243,7 +244,7 @@ A simple example will demonstrate the implementation of some of the debugging te
243
244
The circuit:
244
245
- Arduino Nano 33 BLE Sense.
245
246
246
-
Based on examples created by Riccardo Rizzo, Jose García, and Benjamin Dannegård.
247
+
Code based on examples created by Riccardo Rizzo, Jose García, and Benjamin Dannegård.
247
248
Modified by Taddy Ho Chung and José Bagur (16/02/22).
248
249
*/
249
250
@@ -428,32 +429,33 @@ As shown, the complete code unifies the accelerometer, gyroscope, and magnetomet
428
429
429
430
It is crucial to know when to stop the code from debugging. While the code shown above can be debugged at runtime, it is much easier to know when to stop or how to stop the code operation. For instance, stopping within the first run gives the following result:
430
431
431
-

432
+

432
433
433
434
In the Arduino Serial Monitor, we can observe that it has a `1` good mark and a `1` bad mark. The good mark came from the gyroscope having ready the data for use, while the bad mark came from the accelerometer as the data was not ready. So it is possible to see that the accelerometer does not have enough time to get the data ready before it gets to the measurement task. We can try by running a certain number of instances before it gets to the array dump sector, and the result can be seen as follows:
434
435
435
-

436
+

436
437
437
-
The accelerometer performed its task without any issue except the first runtime instance, resulting in `9` good marks but `1` bad mark due to this behavior. The `Serial.println(F())`instruction of module setups and task runtimes also shows us if the code could get past the operations without any issue. By this, it is possible to know the code structure does not misbehave, but for the first time when the device is starting, the accelerometer requires more time to get the data ready in the first instance.
438
+
The accelerometer performed its task without any issue except the first runtime instance, resulting in `9` good marks but `1` bad mark due to this behavior. The `Serial.println(F())` instruction of module setups and task runtimes also shows us if the code could get past the operations without any issue. By this, it is possible to know the code structure does not misbehave, but for the first time when the device is starting, the accelerometer requires more time to get the data ready in the first instance.
438
439
439
-
Additionally, it is possible to modify the loop code by simply adding a `digitalWrite(LED_BUILTIN, HIGH)` instruction before tasks are called instruction and a `digitalWrite(LED_BUILTIN, LOW)` instruction after the tasks are executed to measure the time it takes to complete them. This can also be helpful to understand the power consumption it draws from this runtime instance:
440
+
Additionally, it is possible to modify the loop code by simply adding a `digitalWrite(12, HIGH)` instruction before tasks are called instruction and a `digitalWrite(12, LOW)` instruction after the tasks are executed to measure the time it takes to complete them using GPIO 12 of the board and an oscilloscope. This can also be helpful to understand the power consumption it draws from this runtime instance:
440
441
441
442
```arduino
442
443
void loop() {
443
444
for (int i = 0; i < 5; i++) {
444
-
digitalWrite(LED_BUILTIN, HIGH);
445
+
digitalWrite(12, LOW);
445
446
accelerometer_task();
446
447
gyroscope_task();
447
448
magnetometer_task();
448
-
digitalWrite(LED_BUILTIN, LOW);
449
+
digitalWrite(12, HIGH);
449
450
}
450
451
451
452
save_debug_buffer();
452
-
453
453
debug_stop();
454
454
}
455
455
```
456
456
457
+

458
+
457
459
## Final Thoughts about Debugging
458
460
459
461
Debugging is a necessary step for developing robust and reliable embedded systems software. We can end this article by mentioning the **four** most essential phases of debugging stated by Robin Knoke in this [article](https://www.embedded.com/debugging-embedded-c/) about debugging embedded C that was published in the Embedded Systems Programming magazine:
0 commit comments