Week 5 Flashcards
debugging
correcting the difference between what you want and what the programm actually does
how to go about debugging
- First understand and have an expectation of what a program does
- then extract info: meassure output, look at led’s, check the order in which things are happening
- review code: what path was executed to produce the output and what went wrong
serial debugging
serial communication is usefull, keep the following in mind:
- using serial changes the timing of the program
- serial and interrupts do not go hand in hand
- serial is slow
use a debug mode that you can switch on and off
how to serial debug
debug the smallest portion of code possible
turn of irrelevant code
write debug lines wherever you have doubts and on conditionals and return values
measure what the arduino does
What to do if there is no serial output
check serial port on pc and check baudrate
print a debug line early in the setup
use the built in led to confirm the program is running
what to do/causes if the program keeps running setup()
an error(memory acces or division by 0) causes arduino to crassh
a crash causes a reboot
look at variable declaration and usage
look at the math
variables that are not initialised have random values
memory basics
a computer (memory) stores bits (1 or 0), a group of 8 bits is a byte
a single byte can accomodate 256 states
communication speed is described in bits (lowercase b)
adressable memory is a magnitude of 2 kiB = 1024 bytes
pointer
reserve a piece of memory, it is a stored memory adress and can be initialised using malloc, it needs to be freed manually using “free”, otherwise it will overwrite itself leading to bugs