Answers:
Debugging in Arduino is mostly done using the Serial Monitor. You add Serial.print(); and Serial.println(); statements to your code to check the values of variables or to see which part of the code is running.
e.g. code
void setup() {
Serial.begin(9600); // Start serial communication
Serial.println("Starting setup");
}
void loop() {
int value = analogRead(A0); // Read sensor
Serial.print("Sensor value: ");
Serial.println(value); // Print value to monitor
delay(1000); // Wait for a second
}
You can also check and debug the code using a hardware component like an LED.
Turn an LED on or off to see if a certain part of the code is executing properly.
Thank you .... But what about AVR-GCC? Is that find any errors in the code while compiling?
When compiling the code with avr gcc, add avr-gcc-g to do the debugging of the code.
For more information on avr-gcc, type avr-gcc --help in the terminal.
Login to add comment