I am looking for information about how simulink connects to Arduino using the Arduino I/O library. I havent found any source code of these blocks, that provide communication from simulink to Arduino (I mean, I would like to see, what is inside of those blocks - that is my MAIN question - What do these blocks look like from inside).
My motivation is to create a simulink block, that could communicate in I2C. From the hardware side, Arduino Uno supports I2C communication, from the programming side, I2C is realy simple kind of communication.
I am a little bit afraid of what the frequency could be. I have found out, that switching digital ports, to imitate I2C is not a good idea, because simulink cant handle more than cca 10 kHz (e.g. block Digital Write caused problems with sample time above 1/10 000 sec).
P.S. - more detailed description of what I have in mind
A block, that has a single input and 2 outputs (SDA and SCL). The input would be a string, the output would be I2C. The block is executed during simulink step (lets say, that is a fixed step - 0,1 sec), during this step the input string is converted to bits/bytes and sent.
P.S. 2 - I KNOW there is simulink librabry Arduino Target, but that does not support real time control by simulink, anyway I would like to see those blocks from inside too.
Any suggestions, source codes and even possible trouble-causing-hurdles are welcomed, just let me know, I am not the only thinking about this.
martin336:
I am looking for information about how simulink connects to Arduino using the Arduino I/O library
That seems to be a question about simulink (whatever that is) rather than Arduino. In that case it would be better to ask your question on a forum that is about simulink.
Well, Matlab & Simulink .... http://www.mathworks.com/ .... (math) simulation program using graphic interface. If there is any place, where this topic would fit, please move it there
There is a new post on the MathWorks File Exchange about a package including a guide that explains how to develop device driver blocks (blocks that perform target-specific functions when executed on a target platform).
Thanks for the link, I have already seen the step by step manual. It explains a lot, but it doesnt say anything about the way, that simulink blocks communicate with target hardware (in my case - arduino). It explains the way the block are transfered to target hardware in C code - may be this is also the way, but for now, it doesnt explain the process of communication between Simulink and Arduino (i mean in real time).
I am looking for information about how simulink connects to Arduino using the Arduino I/O library.
the connection happens via serial port over usb
I havent found any source code of these blocks, that provide communication from simulink to Arduino
The source code is there as s-function in the "simulink" folder (you can do "look under mask").
All that the block do is calling the methods for an arduino object.
A block, that has a single input and 2 outputs (SDA and SCL). The input would be a string, the output would be I2C.
The block is executed during simulink step (lets say, that is a fixed step - 0,1 sec), during this step the input string
is converted to bits/bytes and sent.
If you want everything to be executed (in real time) on the board, so that, for example you can disconnect it from the computer, then you have to use the Simulink support package (see the link above from Eric), and you need to create a device driver block.
if you want a block that is executed on your computer when you run a simulation, and every time the block is executed it tells the arduino (via serial port) to perform an I2C communication, then you need to customize both the adio.pde and arduino.m files. The function "roundtrip" was provided as a starting point for such customizations.