ARDUINO CODE PROBLEM!

Rebecca:

See the part on parsing data.....

Maybe you want to send the whole line of six values as text separated by commas ... or something -- with just a terminator...
Matlab looks versatile enough for you to chose the method and then implement it on the Arduino... The advantage of using text is that you don't have to worry about byte order. The disadvantage is that it's slower.

If you don't understand the comment about byte order -- send a string and sort out binary data later... (trust me)

Here is what I was trying to say: Assemble the 6 variables into a string, separate the variables with commas or semi-colons or whatever MATLAB likes, add a terminator (CR or LF, \n or whatever), send them to Matlab and let it turn them into values that are acceptable -- with a bit of math...

http://www.mathworks.com/help/techdoc/matlab_external/f62852.html#f123662

This is a coordination problem -- not a programming problem as such....

Both ends have to agree on a "data format" or protocol.... Note that their example accepts "," or ";" as the delimiter for the multiple values.


Example — Parsing Input Data Using textscan
This example illustrates how to use the textscan function to parse and format data that you read from a device. textscan is particularly useful when you want to parse a string into one or more variables, where each variable has its own specified format.
The instrument is a Tektronix TDS 210 two-channel oscilloscope connected to the serial port COM1.

  • 1.*
  • Create a serial port object — Create the serial port object s associated with serial port COM1.*
  • s = serial('COM1');*
  • 2.*
  • Connect to the device — Connect s to the oscilloscope. Because the default value for the ReadAsyncMode property is continuous, data is asynchronously returned to the input buffer as soon as it is available from the instrument.*
  • fopen(s)*
  • 3.*
  • Write and read data — Write the RS232? command to the instrument using fprintf, and then read back the result of the command using fscanf. RS232? queries the RS-232 settings and returns the baud rate, the software flow control setting, the hardware flow control setting, the parity type, and the terminator.*
  • fprintf(s,'RS232?')*
  • data = fscanf(s)*
  • data =*
  • 9600;0;0;NONE;LF*
  • Use the textscan function to parse and format the data variable into five new variables.*
  • C = textscan(a, '%d%d%d%s%s','delimiter',';');*
  • [br, sfc, hfc, par, tm] = deal(C{:});*
  • br =*
  • 9600*
  • sfc =*
  • 0*
  • hfc =*
  • 0*
  • par =*
  • 'NONE'*
  • tm =*
  • 'LF'*
  • 4.*
  • Disconnect and clean up — When you no longer need s, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.*
  • fclose(s)*
  • delete(s)*
  • clear s*

PS: Did your mother warn you about men that say "trust me"? She didn't -- ah well...