We will use the same Arduino thermistor setup as sensor.ino this time you will use MATLAB. and the Instead of writing a C or C++ program to interface with the Arduino, Here is the starter code that you can save as amfile in MATLA s-serialport ("/dev/cu.usbserial-110", 9600); t-[]; x-[]; write a for loop that does 40 iterations and in each iteration read 480 bytes from the Arduino, calculate the average and then the temperature, and then plot fclose(s); The serialport command opens up a serial port. You will need to change the /dev/cu.usbserial-110 to whatever port your Arduino is connected to on your computer. The code creates an empty t array that represents time and an empty x array that holds the data. You will need to write a for-loop that iterates 40 times and in each loop iteration, read 480 bytes from the serial port using the following command: data-read (s, 480, "uint8"); Within the for loop, calculate the average of this data array, and from this average calculate the Fahrenheit temperature as in previous labs. Add this temperature to the end of the x array and add the time to the t array. Since you are reading 480 bytes every iteration, and the Arduino is sending data at 960 bytes/s, that means each iteration is 0.5 seconds. So, the first time value will be 0, then 0.5, 1.5, etc. until you get to 19.5s. Once you have added the values to the x and t arrays, you can plot the temperature with the following code: plot (t,x); ylim ([65 90]); xlim ([0 20]); drawnow; The ylim and xlim commands are necessary so that MATLAB doesn't continuously autoscale the figure which can be a little disconcerting. Note that the range of the temperature is from 65 to 90° Fahrenheit. So, if your temperature calculations are not correct, you may not see anything on the plot. The drawnow command ensures that the plot is drawn immediately so that you can get a real-time display of the temperature over time. Make sure that these plot commands are within the for loop. Important: You may find that if you make an error in your program and the code does not complete properly, you may not execute the fclose command which means the serial port is still open. That will cause a subsequent fopen call to fail. If you encounter this problem, just run the following command to close any open serial ports: fclose(instrfind('Status', 'open'));

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
We will use the same Arduino thermistor setup as
sensor.ino
this time you will use MATLAB.
and the
Instead of writing a C or C++ program to interface with the Arduino,
Here is the starter code that you can save as amfile in MATLA
s-serialport ("/dev/cu.usbserial-110", 9600);
t-[];
x-[];
write a for loop that does 40 iterations and in each iteration
read 480 bytes from the Arduino, calculate the average and
then the temperature, and then plot
fclose(s);
The serialport command opens up a serial port. You will need to change the
/dev/cu.usbserial-110 to whatever port your Arduino is connected to on your computer. The
code creates an empty t array that represents time and an empty x array that holds the data.
You will need to write a for-loop that iterates 40 times and in each loop iteration, read 480 bytes from the
serial port using the following command:
data-read (s, 480, "uint8");
Within the for loop, calculate the average of this data array, and from this average calculate the
Fahrenheit temperature as in previous labs. Add this temperature to the end of the x array and add the
time to the t array. Since you are reading 480 bytes every iteration, and the Arduino is sending data at
960 bytes/s, that means each iteration is 0.5 seconds. So, the first time value will be 0, then 0.5, 1.5, etc.
until you get to 19.5s.
Once you have added the values to the x and t arrays, you can plot the temperature with the following
code:
plot (t,x);
ylim ([65 90]);
xlim ([0 20]);
drawnow;
The ylim and xlim commands are necessary so that MATLAB doesn't continuously autoscale the figure
which can be a little disconcerting. Note that the range of the temperature is from 65 to 90° Fahrenheit.
So, if your temperature calculations are not correct, you may not see anything on the plot. The drawnow
command ensures that the plot is drawn immediately so that you can get a real-time display of the
temperature over time. Make sure that these plot commands are within the for loop.
Important: You may find that if you make an error in your program and the code does not complete
properly, you may not execute the fclose command which means the serial port is still open. That will
cause a subsequent fopen call to fail. If you encounter this problem, just run the following command to
close any open serial ports:
fclose(instrfind('Status', 'open'));
Transcribed Image Text:We will use the same Arduino thermistor setup as sensor.ino this time you will use MATLAB. and the Instead of writing a C or C++ program to interface with the Arduino, Here is the starter code that you can save as amfile in MATLA s-serialport ("/dev/cu.usbserial-110", 9600); t-[]; x-[]; write a for loop that does 40 iterations and in each iteration read 480 bytes from the Arduino, calculate the average and then the temperature, and then plot fclose(s); The serialport command opens up a serial port. You will need to change the /dev/cu.usbserial-110 to whatever port your Arduino is connected to on your computer. The code creates an empty t array that represents time and an empty x array that holds the data. You will need to write a for-loop that iterates 40 times and in each loop iteration, read 480 bytes from the serial port using the following command: data-read (s, 480, "uint8"); Within the for loop, calculate the average of this data array, and from this average calculate the Fahrenheit temperature as in previous labs. Add this temperature to the end of the x array and add the time to the t array. Since you are reading 480 bytes every iteration, and the Arduino is sending data at 960 bytes/s, that means each iteration is 0.5 seconds. So, the first time value will be 0, then 0.5, 1.5, etc. until you get to 19.5s. Once you have added the values to the x and t arrays, you can plot the temperature with the following code: plot (t,x); ylim ([65 90]); xlim ([0 20]); drawnow; The ylim and xlim commands are necessary so that MATLAB doesn't continuously autoscale the figure which can be a little disconcerting. Note that the range of the temperature is from 65 to 90° Fahrenheit. So, if your temperature calculations are not correct, you may not see anything on the plot. The drawnow command ensures that the plot is drawn immediately so that you can get a real-time display of the temperature over time. Make sure that these plot commands are within the for loop. Important: You may find that if you make an error in your program and the code does not complete properly, you may not execute the fclose command which means the serial port is still open. That will cause a subsequent fopen call to fail. If you encounter this problem, just run the following command to close any open serial ports: fclose(instrfind('Status', 'open'));
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education