I am trying to get a sampling rate of over 10k Samples per second as well as send each sample over a serial line. Taking a sample and putting it on the serial line each time took too long. I am using Processing 3.3.6 for datalogging into a csv file. I am unable to achieve more than 6k samples per second even at lower prescaler value and high baudrate. What am I doing wrong? Here is my arduino code.
int val[2000];
void setup()
{
Serial.begin(250000);
//ADCSRA = 0; // clear ADCSRA register
//ADCSRB = 0; // clear ADCSRB register
ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits
//ADCSRA |= bit (ADPS0); // 2
ADCSRA |= bit (ADPS1); // 4
//ADCSRA |= bit (ADPS0) | bit (ADPS1); // 8
//ADCSRA |= bit (ADPS2); // 16
//ADCSRA |= bit (ADPS0) | bit (ADPS2); // 32
//ADCSRA |= bit (ADPS1) | bit (ADPS2); // 64
//ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2); // 128
//pinMode(A0, INPUT);
}
void loop()
{
for(int i=0; i<2000; i++) {
val[i] = analogRead(A0);
}
for(int i=0;i<2000;i++){
Serial.print(val[i]);
Serial.print('x');
}
}
P.S I am new to arduino.
--edit1>> I am using Arduino Mega 2560.