Hi
Currently I use the accelerometer (Steval-mki015v1) to connect to the Arduino UNO board, and I can collect about 500 data per second using 115200 baud, but I need to increase it to 5000 data per second, how can I do it? I'd very thankful for the answer.
1.2. : Since these data will be applied to the ECG, 5000 sps is required
3. It is to use a normal laptop to read data
4. It takes about 15-20 seconds to read data each time
Edit: in removed post above OP wrote the sensor is placed 'inside the heart' of an animal. In pm he indicated this was not correct and the sensor is placed on the body.
Start with the sensor being used. A I2C sensor will give about 400Khz data rate. You cannot get any faster than 400Khz minus code overhead.
On the other hand, with a sensor using the SPI interface your data rate from the sensor goes way up. Now you've got a chance of getting the desired output rate, the rest will be up to the efficiency of the MCU and the coder.
Want it real fast use an ESP32. Put the sensor read chores on one core and the sensor processing on another core. Using the dual core scheme, I've got SPI reading of over a 1000 samples per second.
At 5000 samples per second, you have 200 microseconds to report each sample.
If you crank up the ADC to 1 MHz, and crank the baud rate to 2 million baud, and get rid of all of the floating-point math, it takes about 350 microseconds to send three two-digit integers. You need to encode the data in fewer characters.
void setup()
{
Serial.begin(2000000ul); // Two Million Baud
delay(200);
// Set ADC clock prescale to 16 (1 MSPS) instead of the default 128 (125 kSPS)
ADCSRA |= _BV(ADPS2);
ADCSRA &= ~_BV(ADPS1);
ADCSRA &= ~_BV(ADPS0);
unsigned long startTime = micros();
for (unsigned long i = 0; i < 1000; i++)
{
int ax = analogRead(A0);
int ay = analogRead(A1);
int az = analogRead(A2);
Serial.print(ax);
Serial.print("\t");
Serial.print(ay);
Serial.print("\t");
Serial.println(az);
}
unsigned long elapsedTime = micros() - startTime;
Serial.println(elapsedTime);
}
void loop() {}