Saving voltage reads from sensors in queue from Arduino to an excel file?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Anshika Chourasia
2022년 6월 20일
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!