How to access RaspberryPi I2c in Simulink
    12 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Is there a way to access the i2c bus on a Raspberry Pi with the new support package in Simulink? I dont see any straightforward way of doing it.
0 comentarios
Respuestas (4)
  Murat Belge
    
 el 2 de Abr. de 2013
        There are no Simulink blocks to access I2C bus in the Raspberry Pi support package. However, that does not mean you can't do it. Using MATLAB function blocks, you can call Linux command line utilities i2cset and i2cget to read and write to the I2C bus. Someone used this approach to access the GPIO pins back when GPIO was not supported. Here is the link to the MATLAB FEX entry: http://www.mathworks.com/matlabcentral/fileexchange/38508-access-gpio-pins-on-beagleboard-from-simulink.
There is a multitude of references in Internet on how to use i2cset and i2cget functions. Before being able to use these, you need to install i2c-tools package on Raspbian Wheezy (run "sudo apt-get update; sudo apt-get install i2c-tools" on Linux shell to install). Here is a tutorial: https://www.ridgerun.com/developer/wiki/index.php/Developing_a_Linux_driver_for_a_chip_with_I2C_registers
0 comentarios
  utya
 el 19 de Abr. de 2013
        hello. So i use i2cset and i2cget functions to recieva data from IMU. I use this code http://www.mathworks.com/matlabcentral/fileexchange/38508-access-gpio-pins-on-beagleboard-from-simulink
function y = fcn() 
%#codegen 
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(coder.target, '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));
end 
end 
function str = c_string(str) 
% Convert MATLAB string to C-string by adding a string termination 
% character 
str = [str, 0]; 
end
But i dont know how to send data to Scope. Please help me.
0 comentarios
  Lennart
 el 3 de Mayo de 2013
        Hi there,
I was wondering whether anyone might know something like the i2cset and i2cget functin for I2S. Is there anything like that for a linux on a chip? Can't really find anything in combination with simulink :/
0 comentarios
  Mirko
 el 23 de Mayo de 2014
        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?
0 comentarios
Ver también
Categorías
				Más información sobre Run on Target Hardware en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!