Get only one value from Arduino to Matlab using fscanf

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 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