Issue in Reading serial data from the Arduino Uno in Simulink using Serial receive block

조회 수: 7 (최근 30일)
I'm using an Arduino Uno with Simulink and trying to read serial data using the Serial Receive block. The Arduino is printing voltage values from an analog sensor as follows:
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
However, I'm facing a conflict because the Serial Receive block and External Mode are trying to use Serial Port 0, which is the only hardware serial port available on the Arduino Uno.
My Setup:
  • Hardware: Arduino Uno
  • Simulink Blocks:
  • Serial Receive block to capture the data sent from Arduino
  • Mode: I attempted to use both Connected I/O and External mode (Run on board), but as the simulation doesn't allow to change the the serial port from 0 in either mode, nor can I change the pin number in the Serial Receive block.
Problem:
When I run the model, I receive the following errors:
Run with I/O
Caused by: Serial Port 0 used by the Serial Receive block, is also used for Connected I/O. Change the port number used by the block in your model.
Run on baord
Serial Port 0 used by the Serial Receive block is also used for External mode. Change the port number used by the block.
However, the Arduino Uno only has one hardware serial port, and there's no option to change the serial port in the Serial Receive block or in the hardware setting in the Simulink.
How can I resolve this conflict and successfully read serial data from the Arduino Uno in Simulink?
  댓글 수: 5
Danaish
Danaish 2024년 8월 26일
Yes, I have treid it closing the IDE, even though it didn't work.
Monalisha
Monalisha 2024년 8월 27일
Using Serial Receive Block with port 0 and External Mode at Port 0 is not possible.
External mode by deafuolts works on Serial 0.
Another workaround that you can try is using Build deploy anmd Start workflow, to flash your model in the Target Hardware. Post that you can use putty or Arduino IDE to open serial at the same port 0.
This limitation is there as Arduino Uno just has one single Serial Port available.

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

답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by