MATLAB Answers

2

Send a float number to Arduino Target (Serial Receive) using Serial Send (instrument control toolbox)

Asked by Massimiliano Curzi on 9 Apr 2012
Hi, I'm trying to use the Arduino UNO as Hardware In the Loop. I am stuck because I cannot find a way to send a float single precision number via Serial Send block (from Instrument control toolbox), with the arduino target receiving it with Serial Receive (from Arduino Target library).. After that I will need to send a float back from the target to the simulink, (always using serial communication), but that seems a bit easier.
One more thing: the Serial Receive from Arduino Target gives as an output, a int16, but only the 8LSB contain informations, I don't know why (and the Serial Send block from the Arduino Target expects an UINT8, just like it is meant to be!)
I am using Matlab 2011b, and the arduino target library compatible with the IDE 0022, which I have regularly installed. The newest Arduino Target Library, compatible with IDE 1.0 and Matlab 2012a does not work

  0 Comments

Sign in to comment.

1 Answer


For sending data from MATLAB to Arduino, take a look at the "To Instrument" block (in Instrument Control Toolbox). The "Send" tab in the block mask allows you to send 32-bit or 64-bit floats. This blog entry describes a similar approach.
> The newest Arduino Target Library, compatible with IDE 1.0 and Matlab 2012a does not work.
Can you elaborate? What problem are you having with this?

  7 Comments

Actually not,
and actually I have just started trying to work on the R2012a, but I just can't figure out how to make the arduino target receive 4 chars and merge them into a single precision variable...
I was thinking on using unions, but i think i need to write a C-function which is not that easy to implement in Matlab/Simulink, I was looking for something simpler.
4 chars into a single variable: is it really this complicated to do in Simulink?
In MATLAB it would be
typecast(The4Chars,'float')
In Simulink I suspect it would be messy to do without calling upon MATLAB.
Possibly Shankar's response will help:
http://www.mathworks.com/matlabcentral/answers/35270-s-function-for-reading-com-port

Sign in to comment.