Clear Filters
Clear Filters

Simulink - Send and receive float over serial port

35 views (last 30 days)
Hi, I had spent some time on this issue. Want to ask if anyone would help?
I have a robot running on an Arduino Mega controlled by a Simulink model. Both internal and external mode works fine. The model controls the motors, reads the quadrature encoders, receives data from an IMU sensor, etc. All are OK.
I want to send some parameters to the robot over serial interface which is basicly an xbee pair, but have a fundamental problem with it.
Here is the basic block diagram of the system:
USB-to-Serial0 connection is just for monitoring the signals and uploading the model. It's not needed when the model was deployed to the robot.
I have prepared two example models to clarify the problem. Here is the model to send 4 numbers each are 4 byte single values over /dev/ttyUSB0 (Xbee connected to computer)
This model works fine and sends all 4 numbers in a 4-bytes data type.
Then, on the Arduino side, I want to recreate those 4 numbers using the bytes received. Here is the Arduino-side model:
I have a big problem with what I receive in this side. I cannot recreate the numbers back. There is a very good explanation in this page. But I couldn't make it possible in my case. The xbee part would seem making things more complicated. If so, you can just assume the serial port was directly connected to arduino serial port 3.
Long story short, I couldn't receive multiple 4-byte numeric values over serial port and recreate them on arduino using Simulink. I will appreciate it if someone helps. Thanks.

Answers (1)

Pranav Murali
Pranav Murali on 27 Mar 2020
I can understand that you are trying to send some data through a serial port which however is getting lost after transmission. I’m not quite sure whether the Zero-Order Hold block is required in the receiver side. If you are trying to sync the TX/RX pair using the Zero-Order Hold block, I would suggest you try the Rate Transition block. It can ensure data integrity during the transfer.

Community Treasure Hunt

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

Start Hunting!