sending serial data from Arduino to simulink

조회 수: 3 (최근 30일)
elham modaresi
elham modaresi 2019년 10월 20일
댓글: Xiaohui Zhang 2022년 9월 4일
Hi Every one
I am trying to send data from arduino to simulink through a serial receive block in simulink. I have written a simple code in arduin and created a simple simulink code for receiving serial data. I am using two arduino boards. First, I deployed the arduino code on the first one and then run the simulink code in external mode on the second one. The baud rate of port 1 which is used as transmitter in board 1 and as receiver in board 2, is 115200 and the time step is fixed to 0.01 in simulink code.
This is my arduino code:
void setup() {
Serial1.begin(115200);
}
void loop() {
Serial1 .write('2');
Serial.print('\n');
delay(10);
}
and bellow is a photo of the simulink code and the configuratin windws.
d1.png
what I gt after running this coded is that no data is shoen in dispaly windows. Both displat data nd status are zero.
I also tried it by changing the baud rate and sample time but the same result.
I would really appreciate if any one could help me to understand what I have done wrong!

답변 (1개)

Arun Kumar
Arun Kumar 2019년 10월 22일
편집: Arun Kumar 2019년 10월 22일
Hi,
Can you try putting the display block in enabled subsytem triggered by Status output of Serial Receive block. I think the data is being received but you are not able to see because the Serial Receive block outputs 0 when no data is available to read. Since your data is coming every 100mS, most of the time, Serial receive block will output 0.
  댓글 수: 2
elham modaresi
elham modaresi 2019년 10월 22일
Dear Arun
Thanks for trying to help me. I put an enabled block like the below photo. but again nothing changed.
The step time is 0.1. I changed the baud rate to 9600. I also checked the baud rate of the corresponding com in my device manager to be 9600. It seems every thing is correct. I am really wondering what the problem is.
One thing more is that I used a usb2ttl cable to check if the board which is deployed by the arduino code is sending the data or not. I did received the data in HTerminal. So the first board is sending the data correctly. but the second one which is deployed by the simulink code seems not to receive it .
d1.png
Xiaohui Zhang
Xiaohui Zhang 2022년 9월 4일
Hi, did you solve it? I have the same problem

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by