Saving voltage reads from sensors in queue from Arduino to an excel file?

1 view (last 30 days)
Hi,
I am trying to collect voltage data from a sensor that is connected to an Arduino in three analog inputs (the sensor gives voltage in X direction, Y direction, Z direction)
I have written code to acquire the data such that there is a dash after each value so I know when data is read from the next analog input.
example:
voltage = "1.96_" %this is from analog input 1
voltage = "1.3_" %then this is collected from analog input 2
voltage = "1.2_" %then after the second analog input, this is read from analog input 3
I want to store these values, but "voltage" keeps getting overwritten and when I pause the code, it only provides the most recent voltage acquired.
How can I store all of the read values in a matrix and print to an excel file?
Thanks! (new to matlab here)
Here is what I have so far:
%device=serialport("COM26",9600)
param=1
while param > 0
for i = 1:3
voltage = read(device,4,"string")
pause(0.1)
writematrix(voltage)
end
flush(device);
pause(0.1);
end

Answers (1)

Anshika Chourasia
Anshika Chourasia on 20 Jun 2022
Hi Isabella,
I understand you want to store all the read values in a matrix and save it to an excel file.
You can use “writematrix” function to write data to a file and use Name-Value pair argument ('WriteMode','append') to append the data below existing data in a spreadsheet. Please refer to the following link for "writematrix” function details:
I hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by