11. Programming (5) Flashcards
Why do we need to use the serial interface?
To get things started and to print data
Function for setting things up using the serial port?
Serial.begin()
Function for printing using the serial port?
Serial.print()
Function for printing and starting a new line using the serial port?
Serial.println()
How can you debug using the serial port?
By printing values of variables at certain locations you can trace what is going wrong.
If there is nothing wrong with your program what else could be wrong?
There could be something wrong with the hardware: maybe how it is connected/ connected to the wrong pin. If not, then look elsewhere, what happens next in your program?
What are the advantages and disadvantage of debugging using print statements?
Disadvantage: not very elegant
Advantages: simple and often very effective
What must you remember to do after using print statements for debugging?
Delete all the print statements afterwards
What is another option for debugging?
More advanced debuggers exist, these let you step through your code line by line, to see what is happening at each step.
What is an example of an advanced debugger?
Uno Ardu Sim, a free arduino uno simulator
How can the monitor be used for a more useful application?
Can be used as a simple datalogger
What is a datalogger?
A system that collects information and lets us download it to a computer when we are ready
What does the hardware setup look like to investigate switch bouncing?
DRAW
What happens when the pushbutton is pressed?
It acts as an analogue input at the upper pin and as a digital input at the lower pin
Should we use the built in pull up resistor here? What value should the resistor roughly have?
R should be low (about 2kOhms) since this is the input impedance to the ADC. For this reason we do not use the built in pull up resistor.
What function can be used to set the number of bits in an analogue input pin?
analogReadResolution()
How is the analogue data read?
Using the analogRead() function
For a 12 bit analogue reading what value would the analogue input signal return for 0V and 3.3v?
0V - reading of 0
3.3V - reading of 4095 (2^(12) - 1)
If we want to use the mc as a data logger, what is the problem with just reading the data, writing it to the serial port and then repeating?
It succeeds in reading the data and passing it to a computer BUT:
- the mc needs to be attached to the computer at all times. You may want it to be stand alone.
- This is REALLY SLOW. The Serial.println() command takes a long time. E.g. with a max baud rate of 115200 it takes about 100microseconds to transmit one byte, and we need at least 2 bytes for a 12bit number. For comparison the ADC conversion takes around 1microsecond.
With the SAM3X how much memory do we have to store data? How many 4byte readings do we have the potential to store then?
Have 96kBytes of SRAM…. 24000 readings.
How can we store a large amount of readings/numbers?
In an array
How to create an array of 1000 integers?
int readings[1000];
What is the start index and final index number for this array?
reading[0] is the first reading and reading[999] is the last reading.
Why cant we use the variable reading[1000] for this array?
The compiler wont give an error but the program would be liable to crash in unexpected and horrible ways. That is because this refers to a chunk of memory that the program may be using for something else.