How to address Rasperry Pi conection when usin Simulink in Connected IO mode?

2 views (last 30 days)
Hi,
Normally, to connect the raspberry to Matlab/Simulink you need to use the raspi command, e.g.:
mypi=raspi(ipaddress,name,pw);
Once the connection is made, you just have to use mypi to address the Raspberry board.
On the other hand, if you want to use Simulink in Connected IO mode, you have to clear your connection with the Raspberry, and when running the model Simulink will make a connection with the Raspberry.
If I try run mypi=raspi once Simulink is running it says that a connection already exits, so there is no variable in the workspace addressing the Raspberry.
My question: While running Simulink in Connected IO mode how can I address that connection (mypi), for example, to use readDigitalPin(mypi,pinNumber) on an App Designer application? Is it even possible?
Thanks in advance.

Answers (1)

Prasanth Sunkara
Prasanth Sunkara on 16 Dec 2021
Hi Jon,
You can only have one connection to the Pi, either from MATLAB Connected I/O(through r = raspi()) or Simulink Connected I/O. But not both at the same time. If you attempt to make connection to the same Pi from MATLAB while Simulink IO is running, you would see the error you mentioned above. Vice-versa would also cause an error.
Under the hood both MATLAB and Simulink Connected I/O, communicate with Pi using same technology. The communication channel allows only one connection at a time to avoid any conflicting commands send to Pi from two different places. Hence it is not possbile to do both.
If you want to control your Pi through MATLAB simultaneously, please use a Simulink workflow that does not use the same communication channel as that of Connected I/O. You can use either Simulink Monitor & Tune workflow(aka external mode) or a complete model deployment.
-Prasanth
  1 Comment
Jon Remen
Jon Remen on 16 Dec 2021
Hi Prasanth,
First of all, thank you for answering.
I may have explained myself wrong, but understanding that you can't make multiple connections to the same board I wanted to know if there was a way to make a communication object of the existing connection, created when using Simulinc in Connected IO mode.
I looked further and finally found that instead of the raspi command, you can use the raspberrypi (r = raspberrypi()) command to address the existing connection.
Still, thank you for your time.
-Jon

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by