Testing programming code
Testing code in Arduino is important because it helps to ensure that the code is working correctly and producing the desired results. Testing can help to catch bugs and errors in the code, and can also help to verify that the code is performing the tasks that it is intended to perform. By thoroughly testing code, you can improve the reliability and functionality of your Arduino projects.
The Serial.println()
function is a useful tool for debugging Arduino code because it allows you to print information to the serial monitor, which can help you understand what your code is doing and troubleshoot any problems.
To use Serial.println()
for debugging, you will need to include the Serial library at the top of your sketch and initialize the serial monitor using the Serial.begin()
function. Then, you can use Serial.println() to print strings or variables to the serial monitor.
Here is an example of how to use Serial.println()
for debugging in an Arduino sketch:
#include <RobotMovingFunctions.h>
//include <RobDuinoSerialTesting.h>
void setup()
{
Serial.begin(115200);
Serial.print("Setting IO pins .."); // Reporting start of function.
setIOpins(); // Function execution.
Serial.println("..DONE"); // Reporting end of function.
moveForward();
delay(3000);
stopTheRobot();
}
void loop() { }
: Testing programming code. {#lst:053_Testing_programming_code}
To view the output of the Serial.println() statements, you will need to open the serial monitor in the Arduino IDE. You can do this by clicking on the “magnifying glass” icon in the top right corner of the window.
RobDuino Testing Mode
Since testing programming code and hardware is one of the key features in designing a robot it is recommended that testing functions are a part of your main program.
In further lectures we will be using more advances Testing mode
where single digital outputs can be controlled; and inputs will be measured in digital and analog manner. This testing process is available if you have installed RobDuino Library
(see Program Installing chapter). The testing mode will be trigged by the command testing
. The output will show every output state:
******* Testing mode ********************
Dig. Out Dig. In. An.In.
D0 = 1 A0 = 0 A0 = 293
D1 = 0 A1 = 0 A1 = 334
D2 = 0 A2 = 0 A2 = 353
D3 = 0 A3 = 0 A3 = 369
D4 = 0 A4 = 0 A4 = 339
D5 = 0 A5 = 0 A5 = 264
D6 = 0
D7 = 0
-------------------------------------------
Task: RobDuino module testing
- Uncomment line 2 in [@lst:053_Testing_programming_code]:
`#include- Explore testing functions with command
testing
writing it into Serial Monitor and you will get this respond:
*** Testing mode - menu - ******************
* help - prints this text menu
* D5 - toggles output state of D5
* Dx - toggles output state of any Dx,
* x is any num. from 0 .. 13.
* run - toggles monitoring od I/O pins
* exit - exits the Testing mode.
*-------------------------------------------
Type any command to continue ...
Questions:
- Explain why testing is important.
- Describe the techniques of testing.
- What parts of the robot should be tested regularly.
Summary:
Testing mode
Issues:
How can I get RobDuinoSerialTesting working.
Basically you need to do these steps:
- install RobDuino Library
- put this code at the top of your porgram:
#include <RobDuinoSerialTesting.h>
- Compile and write the porgram to your Arduino UNO controller
- Open
Serial Monitor
window - and write
testing
command into prompt.