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

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

Answers (1)

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

I took a look at the "To Istrument" block, and it allows to send via serial, only to the ports 1 to 4, I know that they are the standard ones, and the other COMs >4 are just "virtual" (my arduino is at com8).
And I know that there are ways to "trick" those COMs to make them communicate (such as external software which creates virtual bridges through com ports).
Anyway I was searching for something simpler than that.
"> The newest Arduino Target Library, compatible with IDE 1.0 and Matlab 2012a does not work."
I am running matlab 2011b: the newest target libraries are not recognized by simulink, and if I try to use the arduino IDE 1.0 to build the target model, it just don't get built and downloaded into board...
My issue is also about how i read the single-precision data from the arduino via serial, the block Serial Receive (from instrument control toolbox) actually can receive that, BUT the block Serial Send of the Arduino toolbox allows sending of multiple bytes via a MUX.
For example if I want to send a UINT32 from Arduino to Simulink I
can extract 8-bits packets and then mux them in the serial Send block, and that works, but the Extract Bits block does not work with floating point numbers ... I could try to convert the float to a fixed point number but I'd rather avoit too many passages...
and by the way the Serial receive block (from instrument control toobox) does not accept fixed-poit data
Hello, even i have similar problem. I am trying to send floating point data(like 130.5 )from Serial Send block (of Matlab) but in arduino the servo.read and servo.write does not accept floating values??
Did u find a way?
Massimiliano, is there a reason not to upgrade to R2012a so you can use the new utilities?
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.

Categories

Products

Asked:

on 9 Apr 2012

Community Treasure Hunt

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

Start Hunting!