File Exchange

image thumbnail

Run on Hardware

version 2.0.7 (1.29 MB) by MathWorks MATLAB Coder Team
Examples showing how to run MATLAB code on Raspberry Pi Hardware.

48 Downloads

Updated 11 Aug 2020

View Version History

View License

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:
Documentation: https://www.mathworks.com/help/supportpkg/raspberrypiio/run-on-hardware.html
Video: https://www.youtube.com/watch?v=5lkCx8-zJm0

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.

Cite As

MathWorks MATLAB Coder Team (2020). Run on Hardware (https://www.mathworks.com/matlabcentral/fileexchange/62243-run-on-hardware), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (25)

Murat Belge

@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.

Mikael Kurula

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.

Mikael Kurula

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';

ibrahim ahmethan

i am traying to download it but there is something wrong it is hanging so please help me

dgmcik

Mohith Prabhu

@Ashwini Patil: targetHardware support starts from R2018a release of MATLAB

Ashwini Patil

hi,i am using R2017b version and i get the error for creating configuration object for hardware
boaed=targetHardware(r,'myApplication')
i received error
undefined function or variable targetHardware
can i help me solve this problem

Henry Murr

Henry Murr

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?

Marion Pontier

problem of download

Jaeseon Lee

download is hanging!!

Murat Belge

@Afagh: The error message says 'unit8' not 'uint8'. You might have a typo somewhere.

afagh mohagheghi

Hello, I am using R2017b version and I get the following error:
runOnHardware(r,'myApplication')
??? 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)
codegen('-config ',cfg,fcnName,'-report');

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.

Jyot Buch

Murat Belge

For R2018a users: use "raspberrypi" object when calling runOnHardware function. That is:

>> r = raspberrypi;
>> runOnHardware(r,'myFunction')

Using "raspi" object results in runOnHardware throwing an error.

Murat Belge

@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.

michele benetti

hi, I have installed the package but when I run
runOnHardware(r,'myApplication')
I receive as error:
Trial>> runOnHardware(r,'myApplication')
Error using coder.hardware

There are no hardware support packages installed that support Processor-in-the-Loop (PIL)
simulation.
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');

Krishna

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)
coder.ceval('MW_AudioOpen',...

Error in pitchShiftDeployment (line 17)
open(capture,4410,2)
##########################################

betül zengin

Why not turn on the camera

function bet2()
%#codegen
% Copyright 2017 The MathWorks, Inc.
persistent w
persistent d
if isempty(w)
w = matlab.raspi.webcam(0,[640,480]);
d = matlab.raspi.SDLVideoDisplay;
end

for k = 1:1000

img = snapshot(w);

Rmin=25;
Rmax=35;

[centersDark, radiiDark] = imfindcircles(img, [Rmin Rmax], ...
'ObjectPolarity','dark','sensitivity',0.93);

view([centersDark, radiiDark])


for i=1:length(radiiDark)
hold on
view([centersDark, radiiDark])
hold off
RGB = insertShape(img,'circle', [centersDark(i,1),centersDark(i,2),radiiDark(i)] ,'LineWidth',5);

displayImage(d,RGB);

end
end

release(w);
release(d);

Murat Belge

@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.

Ola Olsson

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.

Ram

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.

Ram

Ram

MATLAB Release Compatibility
Created with R2018a
Compatible with R2017a to R2018a
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

Pitch_Shift_Example

Sobel_Edge_Detection