Hi,
I am one of the author's of this example. It is definitely possible to achieve 1500 Hz sampling rate with Arduino Uno and transfer real-time data to MATLAB, without any slowdown, by following a couple of rules.
(1) You have to set the prescaler of the ADC converter to speed up analog to digital conversions. This requires a few lines of low-level Arduino Uno code as follows:
// ADC Prescaler set to 64. Default was 128.
ADCSRA |= (1 << ADPS2) | (1 << ADPS1);
ADCSRA &= ~(1 << ADPS0);
(2) In order to transfer data sampled at 1500 Hz to MATLAB in real time, you also need to set the serial communication speed to 250 kbaud:
(3) You have to set a 666 usec loop for 1500 Hz sampling rate, something like
// Variables for the timed loop
constexpr uint32_t sample_time = 666; // microseconds for 1.5 kHz loop
uint32_t previous_time = 0;
// Compact binary data buffer
constexpr uint8_t sz = 5;
uint8_t buffer[sz];
void loop() {
// Run main event at constant rate of sample_time
uint32_t current_time = micros();
uint32_t delta = current_time - previous_time;
if (delta >= sample_time) {
previous_time = current_time;
// Read using analogRead
// Send data using Serial.write and the buffer
}
}
Depending on the size of the data you want to acquire, you might also save the data in an array first and send it later after the data acquisition is complete.
0 Comments
Sign in to comment.