NOTE: MATLAB release R2018b onwards, the functionality provided in this File Exchange submission is now a part of the MATLAB Support Package for Raspberry Pi Hardware.
For more information, please visit the following links:
This package includes examples from image processing and audio signal processing domains that demonstrate the workflow of generating C code from a MATLAB algorithm and running it on hardware as a stand-alone application using MATLAB Coder. A MATLAB function, called runOnHardware, is provided for deploying a MATLAB algorithm for prototyping on a Raspberry Pi hardware board.
The Sobel Edge detection example includes the system objects for capturing images from a USB webcam and for displaying images on the Raspberry Pi desktop.
MathWorks MATLAB Coder Team (2020). Run on Hardware (https://www.mathworks.com/matlabcentral/fileexchange/62243-run-on-hardware), MATLAB Central File Exchange. Retrieved .
@Mikael Kurula: All of the functionality provided in this File Exhange submission is now part of MATLAB Support Package for Raspberry Pi Hardware. If you have MATLAB R2019a or later, you can use raspi interface to deploy your MATLAB code to Raspberry Pi. Check out the demos: https://www.mathworks.com/help/supportpkg/raspberrypiio/examples.html?category=run-on-hardware&s_tid=CRUX_lftnav_example_connection-to-raspberry-pi-hardware.
In order to be able to deploy the pitch shift example to the rpi, I had to remove ".internal" on line 3 of the file /home/mkurula/MATLAB Add-Ons/Toolboxes/Run on Hardware/+matlab/raspi/AudioCapture.m.
When I tried to deploy the edge detect example to the Raspberry Pi, I got some error message complaining about not finding main.c, and indeed there is no such file where it is supposed to be. The solution is to comment out lines 50-51 and add one line directly after to the file /home/mkurula/MATLAB Add-Ons/Toolboxes/Run on Hardware/runOnHardware.m:
%cfg.CustomInclude = fullfile('codegen','exe',fcnName,'example');
%cfg.CustomSource = fullfile('codegen','exe',fcnName,'examples','main.c');
cfg.GenerateExampleMain = 'GenerateCodeAndCompile';
i am traying to download it but there is something wrong it is hanging so please help me
@Ashwini Patil: targetHardware support starts from R2018a release of MATLAB
hi,i am using R2017b version and i get the error for creating configuration object for hardware
i received error
undefined function or variable targetHardware
can i help me solve this problem
The function automatically saves as a log file on the raspberry pi when it needs to be an elf file. Can anyone help me fix this problem?
problem of download
download is hanging!!
@Afagh: The error message says 'unit8' not 'uint8'. You might have a typo somewhere.
Hello, I am using R2017b version and I get the following error:
??? Undefined function or variable 'unit8'.
Error in ==> myApplication Line: 11 Column: 13
Code generation failed: View Error Report
Error using codegen
Error in runOnHardware (line 52)
which does not make any sense because I use the uint8 right there in the command prompt and it works perfectly. Would anyone have an idea why this is happening? Thanks in advance for your help.
For R2018a users: use "raspberrypi" object when calling runOnHardware function. That is:
>> r = raspberrypi;
Using "raspi" object results in runOnHardware throwing an error.
@michele benetti: This example requires Embedded Coder license in addition to MATLAB Coder for R2018a and earlier. This dependency was stated in the overview section. I'll update the description accordingly. The error message you are seeing is due to the Embedded Coder requirement.
hi, I have installed the package but when I run
I receive as error:
Error using coder.hardware
There are no hardware support packages installed that support Processor-in-the-Loop (PIL)
The following support packages provide support for PIL simulation with MATLAB coder:
Embedded Coder Support Package for BeagleBone Black Hardware
Embedded Coder Support Package for Xilinx Zynq-7000 Platform
Embedded Coder Support Package for Altera SoC Platform
Embedded Coder Support Package for ARM Cortex-A Processors
Embedded Coder Support Package for ARM Cortex-M Processors
Embedded Coder Support Package for STMicroelectronics Discovery Boards
Error in runOnHardware (line 41)
hw = coder.hardware('Raspberry Pi');
Hi, I am not sure why I am receiving this error.
Error using coder.ceval (line 48)
The coder.ceval function is not supported in MATLAB.
Error in AudioCapture/open (line 57)
Error in pitchShiftDeployment (line 17)
Why not turn on the camera
% Copyright 2017 The MathWorks, Inc.
w = matlab.raspi.webcam(0,[640,480]);
d = matlab.raspi.SDLVideoDisplay;
for k = 1:1000
img = snapshot(w);
[centersDark, radiiDark] = imfindcircles(img, [Rmin Rmax], ...
RGB = insertShape(img,'circle', [centersDark(i,1),centersDark(i,2),radiiDark(i)] ,'LineWidth',5);
@Ola Olsson: The output of fprintf goes to stdout. In the runOnHardware function, I direct the output to a *.log file. For example, if your M-file is called myApplication.m and you compile and generate code out of it, the output of the application myApplication.elf goes to myApplication.log file. And by default the *.log file is generated in the same directory where you launch the application. So check the *.log file for output.
There is a way to send the output to a file of your choice. This is illustrated in raspberrypi_motion_sensor_camera.slx. There is a MATLAB function block in this Simulink demo where we save an image to disk. Take a look at that for details.
Really great example. Thanks for providing this! I am about to try to develop a little computer vision tool, and this is a very good start. Now, in that I also want to save some numbers to a text file on disk on the Raspberry Pi, using fprintf. However, it seems that either it does not do anything with it, or it puts the file in place where I am unable to find it. The code generation report is not complaining (as it was when I tried to fprintf an array instead of scalars), so there is no guidance there.
Add your comments on the example and the proposed workflow in the comment section and let us know if you would like to have a more detailed discussion.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!