matlab and arduino serial connection

when i transmit integers from the arduino to matlab it is able to understand them but not transmitting from matlab to the arduino. i think the problem is transferring numbers greater than 9, the arduino takes each number to be a separate character and prints the corresponding ASCII.

my questions are: 1. how do i get around the arduino converting the numbers to ascii values? 2. i want to transmit a float every minute to the arduino and have the arduino store these values how do i do this? 3. can you keep track of time with the arduino? what other programs can create a serial connection to send values regularly to the arduino?

below is some code i have been using: arduino code int rx_confirmation;

// Initialize Robot void setup () {

/* Initialize pins here */

//Initialize Serial Serial.begin(9600); Serial.flush();

//Initialize hazard_reading array

rx_confirmation = 0;

}

boolean must_send = false; float rx_stuff; // Run Robot void loop () { if (must_send == true) { Serial.println(rx_stuff,BYTE); //i've tried BYTE, DEC, and CHAR must_send = false; }else { if (Serial.available() > 0) { //serial.flush(); rx_stuff = Serial.read(); must_send = true; }else { // Throw HTML stuff here } } }

matlab code clc; close all; clear all;

delete(instrfind({'Port'},{'COM6'}));

% Create a connection object serial_connect = serial('COM6','BaudRate',9600); % Set timeout of fscanf to be as long as one round set(serial_connect,'Timeout',5);

% Attempt to connect to Arduino board try fopen(serial_connect); catch err display(err.message); end display('OPEN SUCCESS!!!!!!');

% Keep reading until signal from arduino board pause(2) fwrite(serial_connect,'2.0','float'); %i've tried transmitting integers and floats with some success with integers rx_rec = fscanf(serial_connect,'%f'); rx_rec

fwrite(serial_connect,'3.0','float'); rx_rec = fscanf(serial_connect,'%f'); rx_rec

% Close connection fclose(serial_connect); delete(serial_connect); clear serial_connect;

i think the problem is transferring numbers greater than 9, the arduino takes each number to be a separate character and prints the corresponding ASCII.

serialRead() can only receive a single 8 bit character for each call to it. Depending on how matlab is sending numbers you must 'rebuild' them in your sketch. If matlab is sending an integer in ascii that can have up to six characters, example "-21222" would be received as six single ascii byte characters in the arduino taking six serialReads and you would have to assemble those and convert to a single int variable in the arduino. At least that's best how I can explain it.

Lefty