Hi ...
I´ve got problems connecting my mbed with Matlab (PC). I loaded my program into mbed. This is summarized in several lines like those shown below:
- include "mbed.h"
Serial pc(USBTX, USBRX);
AnalogIn Sensor_3(p17);
DigitalOut LED_micro_1(LED1);
float mean_S1;
int i;
int main() {
pc.baud(9600);
while(1) {
mean_S1 = 0;
LED_micro_1 = 1;
for(i=0; i<1000; i++){
mean_S1 = mean_S1 + 4.1*Sensor_3.read();
}
mean_S1 = mean_S1/i;
if (pc.readable()) {
pc.printf("%f", mean_S1);
}
LED_micro_1 = 0;
wait (0.2);
}
}
First question ... if I want to connect my mbed with Matlab, is this program correct? Apparently, it is OK because checking with an oscilloscope the data is transferred via USB.
Now in Matlab, the commands are the following:
mbed = serial('COM9', ...
'BaudRate', 9600, ...
'Parity', 'none', ...
'DataBits', 8, ...
'StopBits', 1);
fopen(mbed);
values = fscanf(mbed, '%f');
Nevertheless, when I check the variable 'values', no data appear. In fact, there is nothing in the Matlab buffer so I can not see the result.
Is there anything wrong?
Thanks for your help in advance.
Chema.
Hi ...
I´ve got problems connecting my mbed with Matlab (PC). I loaded my program into mbed. This is summarized in several lines like those shown below:
Serial pc(USBTX, USBRX);
AnalogIn Sensor_3(p17); DigitalOut LED_micro_1(LED1);
float mean_S1; int i;
int main() {
pc.baud(9600);
while(1) {
mean_S1 = 0;
LED_micro_1 = 1;
for(i=0; i<1000; i++){ mean_S1 = mean_S1 + 4.1*Sensor_3.read(); }
mean_S1 = mean_S1/i;
if (pc.readable()) { pc.printf("%f", mean_S1); }
LED_micro_1 = 0; wait (0.2); } }
First question ... if I want to connect my mbed with Matlab, is this program correct? Apparently, it is OK because checking with an oscilloscope the data is transferred via USB.
Now in Matlab, the commands are the following:
mbed = serial('COM9', ... 'BaudRate', 9600, ... 'Parity', 'none', ... 'DataBits', 8, ... 'StopBits', 1);
fopen(mbed); values = fscanf(mbed, '%f');
Nevertheless, when I check the variable 'values', no data appear. In fact, there is nothing in the Matlab buffer so I can not see the result.
Is there anything wrong?
Thanks for your help in advance.
Chema.