Get only one value from Arduino to Matlab using fscanf

3 ビュー (過去 30 日間)
Han Son Go
Han Son Go 2017 年 4 月 20 日
Hello everyone, I want to send data from Arduino to Matlab and Matlab back to Arduino. Because I use interrupt so I have to use Serial seperately in Arduino and Matlab There are code I learn from the Internet to send data from Arduino to Matlab In Matlab:
arduino=serial('COM4','BaudRate',9600);
fopen(arduino);
y=fscanf(arduino,'%f');
fclose(arduino);
And in Arduino:
float temperature=9.100;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(temperature);
}
But when I run the program in Matlab, I saw that y had many different values, sometimes y was a char array. I just want to get one value, so how can I do that? Thank you very much!

回答 (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