フィルターのクリア

How to continously read data from force sensor connected with Arduino

14 ビュー (過去 30 日間)
Thomas Wei
Thomas Wei 2019 年 4 月 4 日
コメント済み: Steven Evangelos 2021 年 8 月 26 日
Hello, everyone
I want to continously read data from a 'flexi force' sensor from arduino to Matlab, and i use the matlab script below to import data:
clc;
clear all;
close all;
a=arduino;
V=zeros(1000,1);
for i=1:1000
V(i)=readVoltage(a,'A0');
end
Here i used a for loop to load data from aduino, is this the only way to import data? The data transfering speed was too low by using this method. Is there any other method to read data from aduino to matlab.
Many thanks for you help!
Thomas
  1 件のコメント
Steven Evangelos
Steven Evangelos 2021 年 8 月 26 日
Hi Thomas,
try this...
%%
a = arduino;
%%
flexi_count = 0;
flexi_array = [ ];
while flexi_count < 100;
flexi_count = flexi_count + 1;
flexi_volt = readVoltage(a, 'A0');
flexi_array = [flexi_array; [flexi_count, flexi_volt]];
show_me_voltage = [flexi_volt];
disp(show_me_voltage);
if flexi_count == 100;
disp("This is the end of the Flexi_Force_Sensor Loop");
end
flexi_array;
flexi_table = array2table(flexi_array, 'VariableNames', {'Time (0.1s)', 'Flexi_Force_Voltage'});
* Remove " ; " as desired to see flexi_array as an array, or flexi_table as a table with column names *

サインインしてコメントする。

採用された回答

Kenny Shu
Kenny Shu 2019 年 4 月 10 日
Reading sensor values with this approach may be limited to the speed of the software for-loop. Consider reading and storing sensor values using an Arduino Sketch. Then, upon request, bring all of the values into MATLAB at once using serial read/write.
  1 件のコメント
Thomas Wei
Thomas Wei 2019 年 4 月 11 日
Hello, Kenny. Thank you for replying and the serial reading is a better way to continously reading data!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by