MATLAB: Why cann’t i get the data on arduino?????

tranfer data on arduino

on matlab ///////////////////////////
function edit1_Callback(hObject, eventdata, handles) x =str2double(get(handles.edit1,'String'));
disp('Value entered: ')
disp(x) global s; delete(instrfind({'Port'},{'COM10'})); s=serial('COM10'); s.BaudRate=9600;
fopen(s);
disp('After OPEN')
disp(s)
fprintf(s,x);
fclose(s);
disp('After CLOSE')
disp(s)
/////////////// on arduino
const int ledpin=13; int recValue;
void setup() { Serial.begin(9600); pinMode(13, OUTPUT); }
void loop() { if(Serial.available()>0) { recValue=Serial.read();
if (recValue == 100) // If use will send value 100 from MATLAB then LED will turn ON
{
digitalWrite(ledpin, HIGH);
}
if(recValue == 101) // If use will send value 101 from MATLAB then LED will turn OFF
{
digitalWrite(ledpin, LOW);
}
}
}

Best Answer

you converted x from string to double. You fprintf(s, x) . The default format for fprintf for serial is '%s\n' which assumes that your data is string but it is double instead.
Related Question