Skip to content

Commit 8fab2ac

Browse files
committed
Update tutorial content
1 parent 64c6f6a commit 8fab2ac

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed
Loading
Loading
Loading

content/learn/02.microcontrollers/04.debugging/debugging.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ A simple example will demonstrate the implementation of some of the debugging te
234234

235235
```arduino
236236
/*
237-
LSM9DS1 accelerometer, gyroscope, and magnetometer tasks operation with debugging.
237+
Program:
238+
- Debugging_techniques_example.ino
238239
239240
Description:
240241
- 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
243244
The circuit:
244245
- Arduino Nano 33 BLE Sense.
245246
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.
247248
Modified by Taddy Ho Chung and José Bagur (16/02/22).
248249
*/
249250
@@ -428,32 +429,33 @@ As shown, the complete code unifies the accelerometer, gyroscope, and magnetomet
428429

429430
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:
430431

431-
![Only one runtime instance of the debugging array.](assets/debug_dump_print.png)
432+
![Only one runtime instance of the debugging array.](assets/debugging_img11.png)
432433

433434
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:
434435

435-
![5 runtime instance of the debugging array.](assets/debug_dump_print_iter.png)
436+
![5 runtime instance of the debugging array.](assets/debugging_img12.png)
436437

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.
438439

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:
440441

441442
```arduino
442443
void loop() {
443444
for (int i = 0; i < 5; i++) {
444-
digitalWrite(LED_BUILTIN, HIGH);
445+
digitalWrite(12, LOW);
445446
accelerometer_task();
446447
gyroscope_task();
447448
magnetometer_task();
448-
digitalWrite(LED_BUILTIN, LOW);
449+
digitalWrite(12, HIGH);
449450
}
450451
451452
save_debug_buffer();
452-
453453
debug_stop();
454454
}
455455
```
456456

457+
![Using an oscillocope and a GPIO to measure the time it takes to complete tasks.](assets/debugging_img10.png)
458+
457459
## Final Thoughts about Debugging
458460

459461
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

Comments
 (0)