필터 지우기
필터 지우기

How to plot the real time data from arduino?

조회 수: 35 (최근 30일)
Tommy Fu
Tommy Fu 2019년 6월 12일
댓글: anil simsek 2020년 5월 6일
I have an Arduino program loaded to the Arduino. I want to plot the real time data from arduino in the MATLAB too. My MATLAB program can get the data from the Arduino board and plot successfully. However, it seems the MATLAB will write something to the Arduino board to override the Arduino program. Is it true? If the answer is positive, may I have a help that how can I get the data from Arduino without affecting the Arduino program? (P.S. both Arduino program and MATLAB program will read the same pin such as A0). Many thanks!

채택된 답변

Arun Kumar
Arun Kumar 2019년 6월 12일
Hi Tommy,
Your observation is correct.
When you do a=arduino, an arduino server is built and is deployed to the hardware.
If you already have code running on arduino, I would suggest using serial read to read the data from serial port for plotting. Refer this page for details about reading data from com port.
  댓글 수: 4
Tommy Fu
Tommy Fu 2019년 6월 13일
Thank You! I tried a simple code as below. The program in Arduino can run properly right now. However, no data is obtained at Matlab. May I have a help on this?
// ---- Arduino Code ----
void setup()
{
Serial.begin(9600);
}
void read_loop()
{
if(Serial.available()>0)
{
Serial.println(sol_amps);
}
}
% ----- MATLAB Code -----
s=serial('COM14','BaudRate',9600);
fopen(s);
go = true;
while go
readData=fscanf(s);
fprintf(s,readData);
end
fclose(s);
delete(s);
anil simsek
anil simsek 2020년 5월 6일
I have Arduino code, I want to draw it instantly in matlab. Can you help me

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sylvain
Sylvain 2020년 1월 17일
With a bit of delay, the issue is in your Arduino code:
Serial.available will return the number of bytes you can read. So you are telling your arduino to scan arriving signals:

anil simsek
anil simsek 2020년 2월 24일
Hi. I have an arduino code like this. this code prints the number of passes of this object on the screen when an object passes in front of the sensor.I also have to create an instant graphical simulation in Matlab that instantly shows the total number of passes of the object.how do i do this in matlab? can you help me?
  댓글 수: 1
anil simsek
anil simsek 2020년 2월 24일
this is my arduino code;
//===============================
int ledpin=12;
bool turn=0;
int sayac=0;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(ledpin,OUTPUT);
attachInterrupt(0,kesme,RISING);
Serial.println("Started!!!");
}
void loop() {
digitalWrite(ledpin,LOW);
Serial.println(sayac);
turn =0;
}
void kesme() {
digitalWrite(ledpin,HIGH);
if(!turn)
sayac++;
while( digitalRead (2)==1){turn=1; }
Serial.println(sayac);
}
//===========================

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by