How to upload Matlab program to Raspberry Pi 2 and execute it in the Raspberry Pi directly ? is it even possible ?

I am currently doing my final year project and I have been asked to develop a program in Matlab simulink and then upload the program into the Raspberry Pi 2 so It would be acting as a standalone device. The nature of my program is image processing.

 Accepted Answer

With the R2018b release of MATLAB, you can deploy your MATLAB code on Raspberry Pi as a standalone executable.
Refer the Deploying MATLAB functions on Raspberry Pi for more information.

17 Comments

Hi Mohith, is it possble to run the deployed MATLAB code again on Raspberry Pi itself? I couldn't find the standalone executable on Raspberry Pi after deploying the code. Thanks!
Oh i found it. It is the .elf file :D
Hi Chne Wuen Tsai!
How do we run the .elf file in the Mathworks/Raspbian OS?
Thank you very much!
I think just simply do a ./<program-name>.elf if I'm not wrong
If it's not working, maybe enter chmod +x <program-name>.elf before that and try again.
The executable generated for your MATLAB function is loacted at the following location on your raspberry pi
<buildroot>/MATLAB_WS/<releaseNum>/<pwdPath>
<buildroot> - the build root that you have set in the targetHardware object.[Default : /home/pi ]
<releaseNum> - Version of MATLAB that you used to create the executable [Example: R2020a]
<pwdPath> - The path of the present working directory on your host machine where you invoked the deploy method on your MATLAB function.
To launch a elf, use sudo ./<name of the elf>
Hope this helps.
Thanks,
Mohith Prabhu
Hi Mohith
I have been using MatLab to flash .m into Rpi4 (purpose of standalone processing) so could you please tell me that do I need Simulink coder or Matlab coder or Embaded coder as I been using home MatLab so I can not buy any of these so how would I make standalone code for Raspberry pi4 or any Android device. It would be great that If you can explain me using example of MatLab_Simulink_Barcode_reader(I purchased MatLab,Image processing, computer visionig tools, Simulink).
Look forward to hearing from you
Regards,
Darsh
If I understand correctly, just Simulink alone and the appropriate support packages should be enough to generate code for Arduino or Raspberry Pi.
Hi Walter
Thanks for your reply, somehow I manage to deploy on my Android device but not sure how I can deploy my train mode into the raspberry pi (as standalone) and use it to train detector into the raspberry pi. if this you might help, would be appreciated
Deploying training is not possible up to R2019b. I would need to recheck whether it became available after that.
I think delpoing is available but I do not know that I can or can not deploy training data, because after importing training data I want to use them as a standalone code. let me make more clear, can I create a Simulink model block of object detecting (which will include the training data as well), and then I can deploy to the raspberry pi with USB camera block and display block (in Simulink), not sure this is the right way.
thanks for the help in advance
Once you have trained, you can save the training information to a .mat file. You can then construct a program that loads that .mat file and uses it to classify information. Even if your version does not permit you to deploy the training process itself, your version will permit you to deploy classifying based on existing training information.
well I been using R2020a at this stage so I think I been making mistake I think so let me find my mistake, and thanks for you help.
THanks you very much for this help.
Here,I try this out but asking me to install MATLAB Coder or GPU Coder. I really want to know that How can I bring my Decoder.mat file into Simulink (as a Simulink block) I been doing object detection and I have to use the Video labeler app then save it as gTruth and from that I have created Decoder.mat file. When I do real-time processing (Object detection) then I simply load this decoder to the main code and use it. so how can do this through Simulink? Well, I planning to use it as an android application and on raspberry pi 4 as well. Moreover I also have some Images as a training data too (Not sure that I will need thos in pi or Mobile, if so then How can I do).
Thanks in advance, Walter
by DP
GPU Coder will not be of any use for deploying to Raspberry Pi.
MATLAB Coder is, if I recall correctly, not used when you create Simulink models to deploy to Raspberry.
I can not buy MATLAB Coder or not even GPU Coder (I know tGPU coder wont help for RPi) so what are the othere option. Can I deploy direclt .mat file into the RPi?
I have a vague memory (that would need to be cross-checked) that for Raspberry Pi (but not arduino) it is possible to copy .mat files over and to read from them on the Pi, but only variables that are purely numeric (possibly restricted further to double.) I have never tried to deploy anything at all to the Pi (I have one here, but I have been busy trying to get Arduino to work.)
Hi Walter
I just found the problem that why I was not able to deploy code in RPi, because I was using standard Image of Linux rather I should use the MatLab one(when we download RPi from Adds-on).
Thanks for your kind responce.
DP

Sign in to comment.

More Answers (4)

Hi. I have a Matlab code that I want to run on raspberry pi. However, I saw here that matlab doesn't run on raspberry pi. I have the pedestrian detection code, how can that be run real time on a micro-controller? Can you please recommend another microcontroller if possible? Thank you
hi is it possible With the R2018a not R2018b , to deploy your MATLAB code on Raspberry Pi as i saw answererd that it is possible with R2018b as a standalone executable?

1 Comment

No. Before R2018b you had to either use Simulink with Raspberry as the target, or else use MATLAB Coder with generic "C" target, and write your own code to interface to any operating system functions or devices such as the display.

Sign in to comment.

Hi there. I'm working on a space detection project in a parking lot, I wrote a matlab code to do it and it works perfectly on my machine but it is supposed to be deployed on Raspberry Pi 3, how do I do it please?

Categories

Community Treasure Hunt

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

Start Hunting!