- #1
lcr2139
- 62
- 1
Hello, I am trying to hook up MATLAB to my arduino. I am trying to write a number to the serial port in the arduino IDE and retrieving the same number in the MATLAB IDE. My arduino code is:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
if (Serial.available()){
Serial.println(3);
delay(100); // delay in between reads for stability
}
}
And my MATLAB code looks like:
%s = serial('COM9');
s = serial ( 'COM9' , 'BaudRate' , 9600, 'terminator' , 'CR' );
%set(s,'BaudRate',4800);
fopen(s);
fprintf(s,'*IDN?')
fread(s)
disp(s)
out = fscanf(s);
fclose(s)
delete(s)
clear s
and the MATLAB output looks like:
10
51
13
10
51
13
10
51
13
How can I change this so only "3" comes out?
Thanks!
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
if (Serial.available()){
Serial.println(3);
delay(100); // delay in between reads for stability
}
}
And my MATLAB code looks like:
%s = serial('COM9');
s = serial ( 'COM9' , 'BaudRate' , 9600, 'terminator' , 'CR' );
%set(s,'BaudRate',4800);
fopen(s);
fprintf(s,'*IDN?')
fread(s)
disp(s)
out = fscanf(s);
fclose(s)
delete(s)
clear s
and the MATLAB output looks like:
10
51
13
10
51
13
10
51
13
How can I change this so only "3" comes out?
Thanks!