lab 12: arduino boards: using your laptop in the...

16
Lab 12: Arduino boards: Using your laptop in the laboratory Up to now we have used our computer to prepare documents, collect infor- mation from the Internet, analyze data and to study the dynamics of mathematical models of biological processes. However, a computer can also be used to translate mathematical ideas into experimental paradigms. One way this becomes possible is through the use of an A/D board. For example, analog data from a measuring device proportional to the amplitude of a time-varying signal can be inputted to the computer (A/D conversion). The computer can then perform some necessary calculations and output a signal in the form of a voltage (D/A conversion) as an inputted stimulus to the experimental preparation under study. In this way the computer can function as a feedback controller or to make it possible to mea- sure a phase resetting curve (PRC) (Laboratory 10). Another possibility is that the computer can use inputted information to turn on and off various measuring devices and stimulators to make possible the design of automated recording and stimulation protocols [1]. This is because devices can be turned off and on using TTL (transistor–transistor logic) pulses (the inputs typically enter the measuring through connections located on the back of the machine). These TTL pulses can be generated by the computer and outputted using D/A conversion. In fact, the availability of inexpensive, credit–card size Strawberry Pi computers (originally developed by Raspberry Pi to introduce computer programming to elementary school children) has made it possible to build computers that are dedicated to the performance of particular types of experiments or tasks. Another strategy is to use the computer to program standalone electronic cir- cuit to perform tasks while the main computer does something else. A com- mon example arises in the collection of data from sensors. Today’s laboratory introduces the Arduino board, an open–source electronics prototyping platform based on flexible, easy-to-use hardware and software. The uses of this board are only limited by the imagination of the user. Indeed one of our past students 1

Upload: others

Post on 15-Jul-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Lab 12: Arduino boards: Using your laptop inthe laboratory

Up to now we have used our computer to prepare documents, collect infor-mation from the Internet, analyze data and to study the dynamics of mathematicalmodels of biological processes. However, a computer can also be used to translatemathematical ideas into experimental paradigms. One way this becomes possibleis through the use of an A/D board. For example, analog data from a measuringdevice proportional to the amplitude of a time-varying signal can be inputted tothe computer (A/D conversion). The computer can then perform some necessarycalculations and output a signal in the form of a voltage (D/A conversion) as aninputted stimulus to the experimental preparation under study. In this way thecomputer can function as a feedback controller or to make it possible to mea-sure a phase resetting curve (PRC) (Laboratory 10). Another possibility is thatthe computer can use inputted information to turn on and off various measuringdevices and stimulators to make possible the design of automated recording andstimulation protocols [1]. This is because devices can be turned off and on usingTTL (transistor–transistor logic) pulses (the inputs typically enter the measuringthrough connections located on the back of the machine). These TTL pulses canbe generated by the computer and outputted using D/A conversion. In fact, theavailability of inexpensive, credit–card size Strawberry Pi computers (originallydeveloped by Raspberry Pi to introduce computer programming to elementaryschool children) has made it possible to build computers that are dedicated to theperformance of particular types of experiments or tasks.

Another strategy is to use the computer to program standalone electronic cir-cuit to perform tasks while the main computer does something else. A com-mon example arises in the collection of data from sensors. Today’s laboratoryintroduces the Arduino board, an open–source electronics prototyping platformbased on flexible, easy-to-use hardware and software. The uses of this boardare only limited by the imagination of the user. Indeed one of our past students

1

Page 2: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

used an Arduino–type board to program the amplifiers for their Alice Cooper–style band. The advantage of the Arduino board stems from its open-source plat-form: many application programs can be downloaded from the Arduino website(www.arduno.cc) and the Internet and can often be readily implemented usinginexpensive electronic components. For example, the light emitting diode (LED)we use for today’s lab cost $ 0.15 each (US) and the accelerometer cost $ 11.95each.

Browser use: All of the built-in functions for Arduino can be found on theArduino website: www.arduino.cc in the Reference section. Check it out!Data sheets for various electronic components can readily be obtained on the In-ternet, often by entering the part number. For example, in the laboratory we use anaccelerometer (MMA7361). Type the name of the accelerometer, i.e., MMA7361,into a search engine and click on links until you find it. You should download thedata sheet for MMA3761. In addition, websites that sell various are generallypretty good at supplying the data sheet as well. We bought the components usedin this laboratory from SparkFun.

Housekeeping: Today’s lab is run entirely using your own laptop. You shouldalready have installed Python (version 2.5 or higher but not versions 3+) and Mat-plotlib (version 1.1 or higher) on your personal laptop. In order to prepare fortoday’s lab you will need to install the Arduino software on your laptop: go to theArduino website www.arduino.cc or type Arduino in your web browser),click on Download tab at the top of the Home Page and follow the instructionsappropriate for your computer. Ideally you should have this software installed onyour laptop before coming to today’s lab.

1 Exercise 1: Blinking LEDs

1.1 BackgroundWe need to refresh our memories concerning electronic components and circuits.

• LED: stands for light-emitting diode. It can be turned on or off dependingthe digital signal it receives. Each has two legs, one longer than the other.The longer is the positive leg and is called the anode. The shorter is thenegative leg and called the cathode (labeled with a black stripe).

2

Page 3: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Figure 1: An Arduino board connected to a LED using a breadboard and jumperwires. See text for discussion.

• Resistor: Each carries an electrical resistance. This resistance is delineatedby the colored stripes. It does not matter which direction they are connected.Each LED requires a resistor to limit the electrical current it receives.

• Digital pins: For dealing with digital signals. For us, this means either a“HIGH” or “LOW” signal. Pins 0 through 13 on the top row of the Arduino(see Figure 1).

• Ground: Circuits need to be connected to a ground. Not literally the ground,but to a grounding pin. There are three ground pins on this Arduino and theyare labeled GND.

3

Page 4: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

1.2 The CodeThe Arduino program is called a sketch. An Arduino computer program is verysimilar to C++ code. Loops are enclosed in { } and a ; is used to end everyline. A // comments out everything after it and can be handy for making notes toyourself.

There are three basic, but required components to every Arduino sketch.

• Variable initialization: Establish the type, name, and initial value of thevariables that will be used in the sketch. The int indicates this variableis an integer. We have named it led because it will be used for the LEDexperiment described below. It is set to = 10 because we elected to usedigital pin #10 on the Arduino (Figure 1.

int led = 10;

• The setup: This program only runs once when you first upload the sketch tothe Arduino. pinMode is a built-in function that sets the pin you are usingand how you want to use it. In this sketch, we are using the led pin that weestablished as digital pin #10 in the variable initializing section.

void setup(){pinMode(led, OUTPUT);

}

• The loop: This loop will run forever as long as the Arduino has power (con-nected to your computer through the USB). digitalWrite is anotherbuilt in function that, in this case, writes either a HIGH or LOW signal to theled pin. Writing a HIGH signal passes current to the led pin and throughthe resistor and LED, lighting it up. This particular loop turns the LED on,waits 1000ms (1 second), turns off and waits 1000ms. Then the loop startsover again and the LED blinks at 1 Hz

void loop(){digitalWrite(led, HIGH); // turn the LED ondelay(1000); // wait for a seconddigitalWrite(led, LOW); // turn the LED off

4

Page 5: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Figure 2: Schematic diagram of a potentiometer. It does not matter which of thetwo connections (A, B) is ground and which is power.

delay(1000); // wait for a second}

Figure 1 shows the Arduino board set that we will use to make the LED blink:

Time to make it happen:

• open the Arduino program and a new sketch (don’t forget to “save as” andname it something)

• write the sketch (initializing variables, setup and loop)

• wire the circuit

• plug in the Arduino and upload the sketch

• watch the LED blink!

1.3 The PotentiometerWe can change the blinking rate by including a potentiometer (Figure 2) into thecircuit (Figure 3). A potentiometer is essentially a variable resistor. Each poten-tiometer has three leads for ground, power and the wiper. Since the potentiometeris basically a resistor it does not matter whether which connection, A or B, is thepower and which is the ground. By turning the dial of the potentiometer, youchange the amount of resistance on either side of the wiper which is connectedto the center pin of the potentiometer. This changes the voltage at the center pin(wiper). This voltage is the analog voltage that we read as an input.

5

Page 6: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

1.4 A few more things to know• Analog pin: An analog pin receives data from a sensor. We will use theanalogRead function in the Arduino language. Arduinos have an analog-to-digital converter which reads the voltage and converts it into a value inthe range of 0-1023. There are 210 values and hence we have a 10–byte A/Dconverter.

• 5V pin: This pin on the Arduino constantly delivers 5 volts of power towhatever is connected to it. This is not enough to hurt a person, generally,but it is enough to hurt a sensor. So... do not connect the wiper (middlelead) of a potentiometer to 5V.

• Serial Port: Used for communication between the Arduino board and a com-puter. We can use the Arduino’s built-in serial monitor to communicate withan Arduino board. Click the serial monitor button in the tool bar and selectthe same baud rate (communication speed) used in the call to begin().The default is 9600 and this is what we will use.

1.5 The CodeThe code used to read a potentiometer is as simple as the code we used to makethe LED blink:

• Initializing variables: For this sketch, two variables need to be initialized.One for the pin that we’re going to use, and one for the reading from thepotentiometer,

int pot = A0;int sensorVal = 0;

• The setup: Just like with the LED sketch, pinMode sets the pot pin as anINPUT. Serial.begin starts the connection with the Serial port so thatwe can see the readings from the potentiometer. As mentioned earlier, theArduino communicates with the serial port at a certain speed. The defaultis 9600 and this is what we will use.

void setup(){

6

Page 7: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Figure 3: The Arduino board shown in Figure 1 now includes a potentiometer.

pinMode(pot, INPUT);Serial.begin(9600);

}

• The loop: The signal from the potentiometer are read through the serial portusing the built-in analogRead function. Then, the readings are printed inthe serial monitor.

void loop(){sensorVal = analogRead(pot);Serial.println(sensorVal);

}

So, let’s hook it up and get this LED blinking! Notice how the negative, cath-ode, end of the LED is connected to the GND and the longer, positive anode is

7

Page 8: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

in series with a resistor in digital pin #10. To make this circuit, use the bread-boards and jumper wires to connect the Arduino to the bread board, as seen inthe schematic. Just remember, the bread board makes connections across the rowshorizontally. Because this potentiometer is basically a resistor, it does not matterwhich of the two outer leads goes to either power or ground. The convention isthat the red wire is for power and the black wire is for grounding. Notice a po-tentiometer is connected to an analog pin, not a digital pin. Remember the middlewiper lead CANNOT be connected to 5V.

To obtain some readings using the potentiometer:

• write the sketch

• wire the circuit

• plug in the Arduino and upload the sketch

• open the serial monitor (upper right corner)

• turn the knob of the potentiometer

• watch the readings in the serial monitor

Questions to be answered:• How would you incorporate the potentiometer into the timing of the LED

blinks? To ask it in a different way: How could you use the potentiometerto control the frequency of the blinking LED?

• How could you use the potentiometer to make a dinner and control thebrightness of the LED?

Implement your ideas and see if they works. It may not work perfectly the firsttime so keep trying! Accomplishing this task will make a complete feedback loopand help show you how these little Arduinos are actually quite powerful micro–controllers.

8

Page 9: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

2 Exercise 2: Measuring TremorRelax your hand and hold it in front of you with fingers outstretched. Have yourlab partner look at your fingertip and they will notice that your fingertips are mov-ing very, very slightly. Don’t worry, these movements are normal and are calledtremor. There are many contributions to your trembling fingertips. Physiologicaltremor refers to frequency components in the 8 − 12Hz frequency range and isthought to be related to the dynamics of the stretch reflex [2]. Evidence in supportof this hypothesis in the absence of these frequencies in some healthy individu-als and in patients with certain peripheral neuropathies and the magnitude of thelatency for the stretch reflex ([2] and this lab). However, there are many othercontributions to the fingertip tremor including those related to the beating of yourheart (the so–called ballisto–cardiogram). What would be expected frequencyrange of contributions to the tremor related to your heart beat?

Other types of tremors arise in patients with diseases of the nervous system.Examples include the pill-rolling tremor (∼ 4 − 6Hz) observed in patients withParkinson’s disease when their hand is resting and essential tremor, a familial dis-order characterized by a tremor that worsens with movement. Thus neurologistsand neuro–scientists have directed considerable attention to the movements of thefingertip.

How can we measure fingertip tremor? One solution is to spend a lot of moneyand purchase an instrument designed especially to measure tremor. A more prac-tical solution is to use an Arduino board to collect data from a triaxial accelerome-ter, an electronic component that measures acceleration in 3D. Accelerometers areinexpensive and it is likely that you can purchase the same accelerometer as in thelaboratory instrument for less than $ 50 (the accelerometer we use in this lab costs$ 11.95). An additional advantage of measuring tremor in this way is that we maybe able to readily incorporate measurements of acceleration into novel experimen-tal paradigms. For example, a colleague developed a micro–accelerometer capa-ble of measuring limb movements in the developing chicken embryo F. Valero–Cuevas, personal communication).

Now that we are motivated, let’s measure fingertip tremor!

2.1 What is an accelerometer?Just like it sounds, an accelerometer measures acceleration. The acceleration thatit measures includes gravity and when the sensor is accelerated through a motion.The accelerometer we are using is the triple axis accelerometer MMA7361. Triple

9

Page 10: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Figure 4: The MMA7361 triaxial accelerometer purchased from SparkFun. Seetext for pin identification.

axis means that it can measure accelerations in all three planes: x, y, and z. Onthe front of the accelerometer you can see the directions that each of the axes arepointing; x and y are in the plane of the breakout board and the z direction isstraight out of the board. The accelerometer is attached to a breakout board whichmakes it possible to make connections to the Arduino board so that the accelerom-eter can receive power and measurements can be recorded. The specification sheetfor MMA7361 can be readily found on the Internet. Using this information we canidentify the pins on the The different pins on the breakout board are:

• Vcc: Every sensor requires power to run. This sensor operates on relativelylow power: only 3.3V. Be careful since the MMA7361 can not handle morevoltage than that. Remember with the potentiometer we used for the LEDwe could not plug the wiper into the 5V pin on the Arduino. The same thinggoes in this lab but there are more pins to be careful about. Vcc can ONLYbe connected to 3.3V on the Arduino. It might be helpful to cover the 5Vpin with tape or put a little wire in it to remember. If you do accidentallyconnect Vcc to 5V, the sensor will get warm and then hot and soon not workat all.

• GND: Just like we saw last time, everything that needs power also must begrounded. This connects to the GND pin on the Arduino.

• Zout: This is where the measurement in the z plane comes out of the break-out board. This connects to an analog pin.

• Yout: This is where the measurement in the y plane comes out of the break-out board. This connects to an analog pin.

10

Page 11: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

• Xout: This is where the measurement in the x plane comes out of the break-out board. This connects to an analog pin.

• SLP: This is the sleep pin. It only understands a high or low signal so it willbe connected to a digital pin. Low is sleep and high is active. Its defaultposition is LOW so it must be given a HIGH signal to be able to get out anymeasurements.

• 0GD: This is a zero-g detection pin that is also a binary pin. It can detectwhen the accelerometer is falling with the acceleration of gravity and canturn off the rest of the sensor so it doesn’t get damaged when it eventuallyhits the floor. We are not going to use this today.

• GSel: This pin allows you to indicate how sensitive you want the accelerom-eter to be. It’s default is ±1.5g when given a LOW signal and ±6g whenHIGH. We may want to play around with this today.

• ST: This pin is a self-test pin used to check if the accelerometer is workingcorrectly. Hopefully we won’t need this today at all.

2.2 The Code - Writing the Sketch2.2.1 Variable Initialization

Just as we did for controlling the blinking of a LED, we need to write a sketch.The first step is to write the variable initiation section. We advise that the sketchis written to initialize the pins related to all of the variables that will be measured.This organization is useful when it is necessary to change a pin since it is onlynecessary to change one number at the top of the sketch instead of referring tothe changed pin throughout the rest of the code. Note that it does not matter whatnumber pin you assign to your pin variables, just that you get the correct type:digital or analog. Do you remember the difference?

int zAxis = A0; // analogint yAxis = A1; // analogint xAxis = A2; // analogint slp = 4; // digital

These three variables are going to be what we name the measurement comingfrom the analog pin.

11

Page 12: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

int z;int y;int x;

In addition we need to initialize two variables that will be sued for the timer(see below). They are initialized as long variables is that they could potentiallyget very large. For example we may decide to sample at 512 Hz for 10 minutes.

long currentTime = 0;long lastTime = 0;

2.2.2 The Setup

In the setup, we use pinMode to set up those pins that we will actually use (don’tforget about the Sleep pin! Go back up to where we were talking about what thispin does to figure out how to set it up.). The other thing that you need to do inthe setup is to begin the communication with the serial port. This is done usingSerial.begin. Just remember that the setup only runs once so anything thatyou only need to do once goes in the setup (hint: sleep pin).

2.2.3 The Loop

In the case of the blinking LED we used delay to make the loop. However, inthis case we’re going to use a timer. There are a number of advantages for usinga timer: 1) using a timer prevents the loop from slowly down each time it is used;2) it allows greater flexibility and speed options when printing data; and 3) it ispossible to keep track of time efficiently. All of these advantages are importantgiven that our ultimate goal is to calculate a power spectrum in order to determinethe frequency content of tremor. The biggest thing to understand is the functionmillis(). Calling this function sets that variable to how long the program hasbeen running, but not in seconds, in milliseconds. With that knowledge, take alook at this and see if it makes sense. This is not going to be your whole loop andyou don’t have to type this, just look at it to understand · · · we just want to giveyou an idea of what a timer is:

void loop(){

currentTime = millis();if ((currentTime-lastTime) > 100)

12

Page 13: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

{lastTime = currentTime;x = analogRead(xAxis);Serial.println(x);

}}

What happens if you change the 100 to a 10?

Now that we know what a timer is, we can build the rest of the loop. Try thisexample out. You can tweak it as you want:

void loop(){

currentTime = millis();if ((currentTime-lastTime) > 10){

lastTime = currentTime;z = analogRead(A0);y = analogRead(A1);x = analogRead(A2);

Serial.print("x: ");Serial.print(x);Serial.print("\ty: ");Serial.print(y);Serial.print("\tz: ");Serial.print(z);Serial.print("\n");

}}

Once you’ve made the correct connections from the accelerometer to to theArduino, upload the sketch and move the sensor around while looking at the serialmonitor. Do you see the values changing? What do they mean?

2.3 CalibrationThe first thing we need to do with these accelerometers to understand their datais to calibrate them. The data from the potentiometer in the LED experiment took

13

Page 14: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

the form of numbers that were being printed on the serial monitor that were in therange of 0 to 1023. This is not specific to potentiometers but rather to the functionanalogRead. Every time you read from an analog pin, the numbers producedwill be in this range. However, to make sense of these numbers we need to knowwhat the smallest number corresponds to? ±5V, ±1g, etc. Once we know therange we can scale the remaining numbers as fraction of the whole range. Theprocedure of determining the operating range of an accelerometer (or, in general,a sensor) is called calibration.

Calibrating the sensor to gravity is the easiest. We will do this by holdingthe sensor in different positions (i.e. the y axis pointed directly up) and taking theaverage of the data and scaling it to gravity. Here is a suggestion of how we woulddo it:

• To make it simple, just print out one variable into the serial monitor at atime. So, maybe you do just use the first loop we wrote out above.

• To begin with the easiest, hold the sensor with the y axis pointed up. Keepit in this position until you have gathered the data necessary.

• Upload the sketch onto the Arduino and open the serial monitor. Make surethe serial monitor is in auto-scroll mode.

• After a few seconds, uncheck the auto-scroll in the serial monitor and high-light all the data from where you stopped to near the top and copy it. Thereason to do this is to get the average reading for the sensor in this positionand then you can scale it to gravity.

• It is convenient to past this list of data into an Excel file and then use Excel’s=average function to find the average of the data set.

• Do this for all 6 (two for each axis) positions. Remember to print out thecorrect axis.

• Then set up your excel file to resemble that shown in Figure 5.

• The big-sized numbers in the third row are the averages of the whole columnbelow each. Notice how the larger numbers in the 400’s and 500’s are whenthe axis on the sensor is pointed up. The 1 and -1 in the cells above that areindicating how we are going to scale the numbers. Essentially, we’re goingto say that when an axis is pointing up, that reading is equivalent to 1g or9.8 m/s2

14

Page 15: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

Figure 5: Example of an Excel file setup that is useful for calibrating the ac-celerometer.

Figure 6: Triaxial accelerometer taped to index finger.

• Then we can use the Excel functions =slope and =intercept to findthe proper scaling. The x-values should be the analogRead values andthe y-values should be the 1 and−1. We’re using the simple mx+b equationto scale the Arduino readings to gravity.

• Use these values (the slope and the intercept) to do some calculations inyour Arduino sketch. Every sensor is going to be a little bit different butyou can use the one we developed in this lab as a starting point.

z = analogRead(A0);y = analogRead(A1);x = analogRead(A2);

float xx = x*.00623-2.099;float yy = y*.00600-2.170;float zz = z*.00596-1.836;

• Notice how we used the values of m and b determined using Excel for thecalculations in the Arduino loop (with a little bit of rounding).

• Once you’ve calibrated the sensor, now you can get meaningful data out ofit!

15

Page 16: Lab 12: Arduino boards: Using your laptop in the laboratoryfaculty.jsd.claremont.edu/jmilton/Math_Lab_tool/Labs/Lab12.pdf · Lab 12: Arduino boards: Using your laptop in the laboratory

2.4 Data from fingertip movementsOnce the accelerometer has been calibrated, rewrite the loop section in the sketchso that it will print out x,y and z data (and maybe even the time, if you want) oneach line. Then when you highlight and copy from the serial monitor, the data willbe organized nicely in columns. Create data showing different things. Attach theaccelerometer to your index finger being careful to also secure the cables so thatthey don’t move around (see Figure 6). Try just moving your hand back and forthat first to see how you accelerate and decelerate to change directions. Do this inone plane first and then make your movement more complicated. Finally collectdata when your hand is relaxed and fingers are outstretched. This is the data wewill analyze below.

An important question is to decide how you want to plot the data and also howyou will determine the power spectrum. Of course we are going to use a Pythonprogram to accomplish these tasks. This means that we need to save the data ina format that can be used in our Python program. PC users can paste it the datainto a plain text file (for example using Notepad) and then name it name.dat.Mac users can paste their data into TextEdit. In TextEdit, under the format tab,you can change the format to be plain text. Make a new folder and put the datasomewhere you’ll remember, like the desktop or in My Documents. This way, itwill be easier to find when you want to open it up using python.

Deliverables:Use Lab12_template.tex to prepare the lab assignment.

References[1] J. D. Hunter and J. G. Milton. Synaptic heterogeneity and stimulus–induced

modulation of despression in cnetral synapses. J. Neuroscience, 21:5781–5793, 2001.

[2] O. C. J. Lippold. Oscillation in the stretch reflex arc and the origin of therhythmical 8–12 c/s component of physiological tremor. J. Physiol., 206:359–382, 1970.

16