Physics 37100 Advanced Physics Laboratory I

Lab #4

(PART II:  Simple oscilloscope)

 

1)          Using the code and circuit from part I and lab 3-II, create a sketch to:

a.      establish communication with matlab using ‘?’ and ‘K’;

b.      wait to receive the character ‘g’ (for go);

c.      make one loop to take 512 points of time series data from photoresistor on A0 measuring the PWM pin 9 LED set to 128;

d.      make a second loop to send the data to matlab using Serial.println();

e.      at the end of the second loop send the total acquisition time;

f.        loop back to part b.

2)          Modify (part I) matlab script to:

a.      establish communication with arduino using ‘?’ and ‘K’;

b.      send the character ‘g’ (for go);

c.      loop over the serial data using fgetl() and str2double() to store the data in an array;

 

V=zeros(1,N);

t=(0:N-1)/N;

for m=1:N

  str=fgetl(s);

  V(m)=str2double(str);

end

 

d.      read the acquisition time using fgetl() and str2double();

e.      plot the data using a time axis in μs;

f.        drawnow; 

g.      Loop back to part b.

3)          Move the wire connected to A0 to other points in the circuit while the script is running to see the data update.

4)          Change the plotting to display the FFT of the data.

a.      The horizontal axis should be in Hz.  Include a nice plot of the FFT with x and y axis labels in the report.

b.      What is the frequency of the PWM light?

c.      Is it consistent with the value in the description of analogWrite on the arduino site: https://www.arduino.cc/en/Reference/AnalogWrite.

d.      Measure the frequency directly using the time series data to measure the time from one peak to the next.  Is it consistent?

5)          (Extra credit) modify to allow matlab to set the value of the LED output on each loop.