so here is what i am trying to do:
i have a doppler sensor, from that i want to read a data with my uno and send it via usb cable to my computer to process it with matlab or python.
this is my arduino code:
int in = A0; // the pin i am using to analog read
int v=0; // the voltage value i am trying to send to matlab/python
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
v = analogRead(in);
Serial.println(v);
}
this simple code is how i am trying to communicate with my pc. if you guys have a better aproch, please let me know.
this is my code in matlab to read from uno:
clear;clc;
ser = serialport("com3",9600); % arduino doesnt send anything with 115200 so i didnt update this part. it is normally 115200
configureTerminator(ser,"CR");
n=10000; % number of samples i am trying to read
v=zeros(n,1);
readline(ser); % since i am getting the first reading a ???, i try to use this so the first reading goes
% vein
disp("ready");
pause(2);
disp("go");
tic()
for i=1:n
v(i)=readline(ser);
end
rt=toc() % so-called runtime (it runs for about 50 secs to collect 10k samples with 9600 baud rate
v = v.* 0.004887585532746823; % 5/1023
so guys,
-
i cant read data with baudrate of 115200 and i see some forum topics that i normally should be able to run uno with baud rate of 115200.
-
when i try to use baud rate of 9600 it works normally, but i gate 10k samples in about 50 seconds thus my sampling frequency is abut 200, i am trying to increase this number.
so guys,
i am in need of your help, you can either offer me a better version of coding, or a better understanding..
thanks to you all for support
edit:
for example, i found this code online:
void setup()
{
Serial.begin(115200);
pinMode(A0, INPUT);
}
void loop()
{
long t0, t;
t0 = micros();
for(int i=0; i<1000; i++) {
analogRead(A0);
}
t = micros()-t0; // calculate elapsed time
Serial.print("Time per sample: ");
Serial.println((float)t/1000);
Serial.print("Frequency: ");
Serial.println((float)1000*1000000/t);
Serial.println();
delay(2000);
}
and it simply doesnt work when i upload it to my uno. serial monitor only shows ????
thanks