MATLAB Answers

How to communicate between Arduino and RasPi using Simulink Serial Read/Write blocks?

22 views (last 30 days)
Cormac O'Neill
Cormac O'Neill on 22 Jan 2021
Commented: Prasanth Sunkara on 11 Mar 2021
I'm attempting to send data from my Arduino to a connected Raspberry Pi, with both using deployed Real-Time Simulink code. The approach I've been trying is to connect them via the USB port (port 0 for the Arduino, and /dev/ttyACM0 for the Pi in this case). I am able to read the data using the Arduino IDE serial monitor in the RasPi's interface as well as through PySerial. However, the Serial Read block is returning a Data Unavailable (Status 32) error.
What could be causing this? I may be mis-formatting my data for what Simulink is expecting (I have tried doubles sent using 'write' as well as ASCII with 'println'), but my understanding is that I'd just get junk rather that 'Data Unavabilable'. Is there potentially some other way that I could get around this problem? Perhaps by reading the data with PySerial and then somehow sending it to the realtime Simulink program?
Cheers for any help!
Blocks on the Arduino:
Blocks on the RasPi:

Answers (1)

Milan Padhiyar
Milan Padhiyar on 28 Jan 2021
Hello,
As per my understanding you are facing issue with the real time communcation between Arduino and Raspberry Pi using Simulink.
Please refer to the below links as this might help you in your workflow.
Thanks
  1 Comment
Cormac O'Neill
Cormac O'Neill on 4 Feb 2021
Thank you for the response! I don't think the ROS approach is necessary in my case, since the SerialRead and SerialWrite blocks should be handling the communication instead of anything with the ROS Toolbox?
I'd ideally like to implement something as in the second link that you posted, however I noticed that the author connected the Arduino and Pi using the GPIO pins. Is there any reason that a connection over the UART-USB ports would not work? I have successfully used these ports and the Serial blocks in Simulink to communicate with my PC as the host machine in the past, but I can't seem to get it to function when the Pi is the host.
Cheers!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by