11. Programming (5) Flashcards

1
Q

Why do we need to use the serial interface?

A

To get things started and to print data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Function for setting things up using the serial port?

A

Serial.begin()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Function for printing using the serial port?

A

Serial.print()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Function for printing and starting a new line using the serial port?

A

Serial.println()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you debug using the serial port?

A

By printing values of variables at certain locations you can trace what is going wrong.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If there is nothing wrong with your program what else could be wrong?

A

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?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the advantages and disadvantage of debugging using print statements?

A

Disadvantage: not very elegant
Advantages: simple and often very effective

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What must you remember to do after using print statements for debugging?

A

Delete all the print statements afterwards

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is another option for debugging?

A

More advanced debuggers exist, these let you step through your code line by line, to see what is happening at each step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an example of an advanced debugger?

A

Uno Ardu Sim, a free arduino uno simulator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can the monitor be used for a more useful application?

A

Can be used as a simple datalogger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a datalogger?

A

A system that collects information and lets us download it to a computer when we are ready

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the hardware setup look like to investigate switch bouncing?

A

DRAW

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens when the pushbutton is pressed?

A

It acts as an analogue input at the upper pin and as a digital input at the lower pin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Should we use the built in pull up resistor here? What value should the resistor roughly have?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What function can be used to set the number of bits in an analogue input pin?

A

analogReadResolution()

17
Q

How is the analogue data read?

A

Using the analogRead() function

18
Q

For a 12 bit analogue reading what value would the analogue input signal return for 0V and 3.3v?

A

0V - reading of 0

3.3V - reading of 4095 (2^(12) - 1)

19
Q

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?

A

It succeeds in reading the data and passing it to a computer BUT:

  1. the mc needs to be attached to the computer at all times. You may want it to be stand alone.
  2. 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.
20
Q

With the SAM3X how much memory do we have to store data? How many 4byte readings do we have the potential to store then?

A

Have 96kBytes of SRAM…. 24000 readings.

21
Q

How can we store a large amount of readings/numbers?

A

In an array

22
Q

How to create an array of 1000 integers?

A

int readings[1000];

23
Q

What is the start index and final index number for this array?

A

reading[0] is the first reading and reading[999] is the last reading.

24
Q

Why cant we use the variable reading[1000] for this array?

A

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.

25
Q

What is the error for trying to use an index outside of an array?

A

“array index out of bounds”

26
Q

What is the loop for reading in all the values from an analogue signal using an array of 1000 integers ?

A

int readings[1000];

for(int index=0; index

27
Q

In the previous examples where the array was declared as int readings[1000]; what do we call the number 1000 and is this a good thing?

A

1000 would be known as a ‘magic number’ it is a bad thing but not as bad as an array index out of bounds error.

28
Q

How do we get rid of the magic number 1000 that is the array size?

A
using the # define statement, known as a preprocessor directive. E.g.
#define DATAPOINTS 1000;
29
Q

What would the previous code for reading in the values now become?

A
#define DATAPOINTS 1000;
int reading[DATAPOINTS];
for(int index=0; index
30
Q

Why is this code with the define statement better?

A

Because now if we wanted to change (eg double) the number of data points all we have to do is change the first line.

31
Q

What is DATAPOINTS here called? and does it have to be in capitals?

A

It is called an identifier and it is in capitals because of tradition, not because it is essential.

32
Q

What is good about having it in capitals?

A

It is useful because it makes the constants in the program stand out.

33
Q

Could we use: const int DATAPOINTS = 1000; instead of the #define statement?

A

NO, cant use constants for an array size

34
Q

How would we then transmit the data readings to a computer?

A

Using a loop:

for(int index=0; index

35
Q

How could we save the time of capture for the data?

A

using the micros() function, which returns the number of microseconds since the sam3X was powered up.