I am reading analog sensor data using Arduino nano, and the required sampling rate is around 1kHz. I am using the AnalogReadSerial example provided by Arduino with a delay of 1ms, so I am expecting to get around 1000 samples per second or slightly less due to the ADC conversion delay. However, the maximum number of samples I am able to get in my laptop a little bit less than 200 samples per seconds. I have tried increasing the baud rate to 115200 but that was not helpful. Am I missing something here, or is there something I need to do to get my data at the required sampling rate?
Below is AnalogReadSerial code I used for reference:
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
millis()
before and afterint sensorValue = analogRead(A0);
... then print the two valuesssty
because the default was 9600. Right now, I am getting data at a rate similar to yours @Edgar Bonet, which is better but still a little bit shy of the required rate. @PMF your calculations make sense and this baudrate should be within my laptop's and Arduino nano's limits, which is still confusing to me. I will remove the delay and check if that makes any difference.