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'));
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'));
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.4: Character Manipulation Functions
Problem 3E
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,