2
votes

I'm new to Matlab and Simulink and I need to get a simulation run on the Raspberry PI. For interaction I use the Raspberry PI Support Package of Matlab. I use the following code to open the connection to the Raspberry PI and read the internal temperature sensor:

mypi = raspi('hostname','username','password','port');
temperature = system(mypi,'command_to_read_temperature')

If I run this code separately in the Matlab command line everythink works fine but if I try to run it in a Matlab function block in Simulink it gives me back an error:

Base class 'matlab.mixin.CustomDisplay' cannot be loaded. 

Function 'raspi.m' (#29.3176.7592), line 102, column 9:
"function obj = raspi(hostname, username, password, port)"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder Error

Is there any way to run code with functions for Raspberry PI in a Matlab function block? I tried with S-functions, but it is way to complicated and complex and didn't work out very well.

1
The problem seems to manifest itself while creating the mypi object in Simulink. Did you try to create the object on the MATLAB workspace, and then just use it directly in Simulink? I think you should have access to MATLAB's workspace variables from there. I know it's not ideal, but maybe a step forward if it works.mikkola
Thanks for your reply! I tried to use the created object inside the function but there was an error: undefined function or variable rpi. I think you can't access the variable inside the function is it possible to pass a variable as parameter to an matlab function?user4947869

1 Answers

1
votes

While I do not understand what exactly causes the error, I can explain why it can't work that way.

The Raspberry support package for MATLAB is designed to use the Raspberry as an IO-Board, having the sensors and actuators available in MATLAB. The application itself runs on your PC. The command mypi = raspi('hostname','username','password','port'); sets up this connection.

You attempt to do something else, having an application running on the raspberry. For this use case Simulink and the support-package for simulink is the right choice. These blocks support both, simulating the application on your PC using a network connection to access the sensors and actuators or running the application on the raspberry, directly building the IO into your application.