Hi,
I’m trying to read some sensor data from my arduino due through serial communication into matlab. This works sometimes, other times I read strange signs.
I’m not using the library from arduino in matlab because I made some changes in the register of the mcu. The reason here is that I want a quicker ADC. Now I’m sure this isn’t the problem. I tried allready without changing the register, but is was still the same.
This is my arduino code:
void setup() {
Serial.begin(9600);
ADC->ADC_MR |= 0x80; //set free running mode on ADC
ADC->ADC_CHER = 0x80; //enable ADC on pin A0
}
void loop()
{
Serial.println(analogRead(A0));
}
and this is my matlab code :
close all
clear all
clc;
delete(instrfindall)
samples = 300;
comPort = 'COM1';
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
s = serial('COM1', 'BaudRate',9600, 'DataBits' , 8, 'StopBits', 1);
%line1 = line(nan, nan, 'color', 'red');
fopen(s);
i = 1;
while (i<samples)
value = fscanf(s,'%d');
x(i) = value;
plot(x, 'r')
grid on;
hold on;
i = i+1;
end
Does anybody have an idea why I read sometimes those strange signs?