View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Access GPIO pins on BeagleBoard from Simulink

5.0 | 2 ratings Rate this file 15 Downloads (last 30 days) File Size: 23.7 KB File ID: #38508 Version: 1.0
image thumbnail

Access GPIO pins on BeagleBoard from Simulink



This example shows how to access GPIO pins on the BeagleBoard using Simulink.

| Watch this File

File Information

This submission contains two Simulink models showing how to access GPIO pins on the BeagleBoard. I developed the models using R2012a BeagleBoard Support Package. I used MATLAB Function Block to implement GPIO Read and GPIO Write functionality. The MATLAB Function Blocks are basically used to make GPIO related Linux system calls.

One can do a great deal using the same paradigm to call into Linux shell. This example showcases "system" and "popen" calls.

While the examples were developed in R2012a, they should work in R2012b as well.

NOTE: GPIO pins on the BeagleBoard use 1.8 V logic levels. Do not connect devices using +5V or +3.3V logic levels to the GPIO pins or you risk frying your board.

Required Products Simulink
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
23 May 2014 Mirko

Mirko (view profile)

Hi, I am a new user of Matlab/Simulink, for the first time, I would like to make a connection between a raspberry pi I2C and an Arduino using simulink. Someone could explain how this code and where do I pick up the data read?

There is a place in simulink Sfunction that creates a connection with I2C read and write?

Comment only
29 Apr 2013 Murat Belge

Use external mode to see the data on a Simulink scope. Open Tools > Run on Target Hardware > Options menu from your Simulink model and check "Enable External mode" box. Build and run your model. If you connect the output port of your MATLAB function block to a Simulink scope, you will see the data on your host computer when you run your model. I recommend reading the "Getting started" demo.

Comment only
19 Apr 2013 utya

utya (view profile)

hello. So i use i2cset and i2cget functions to recieva data from IMU. I use this code

function y = fcn()
persistent pf;
pf = coder.opaque('FILE *');
y = coder.nullcopy(uint8(0));
res = coder.nullcopy(uint8(zeros(1, 10)));
readOnly = c_string('r');
readCmd = c_string(['i2cget -y 1 0x53 0x32']);
if isequal(, 'rtw')
pf = coder.ceval('popen', coder.rref(readCmd), coder.rref(readOnly));
coder.ceval('fgets', coder.wref(res), 10, pf);
coder.ceval('printf', c_string('%s'), c_string(res));
function str = c_string(str)
% Convert MATLAB string to C-string by adding a string termination
% character
str = [str, 0];
But i dont know how to send data to Scope. Please help me.

Comment only
12 Feb 2013 Ufuk Irmak

08 Oct 2012 Murat Belge

Contact us