Reading and sending data - sram buffer


I’m trying to build a PC-based spectrum analyzer. My idea is that the arduino reads the input voltage and sends serial data to a PC where a Python script logs and does all the fancy stuff.

It seems to work but I’m limited to have a good number of FFT bins by the number of samples that I can buffer on the arduino, the number of samples being limited by the sram of the board.
One obvious solution is to move to an arduino board with higher RAM (I’ve seen the ATmega1284 and the Mighty Core), but is there any way to increase the number of samples that I’m buffering without changing board? Can my code be optimized? Any other ways of doing it?


int last_us= 0;
int n = 0;
int nSamples = 850;
int ai0_volts[850];

void setup() {
  pinMode(led, OUTPUT);

void read_wf(){
    digitalWrite(led, HIGH);
    Serial.println("reading started");
    while ( n < nSamples) {
      if (micros () - last_us > 500){
        ai0_volts[n] = analogRead(A0);
        n= n+1;
        last_us += 500;
    Serial.println("reading finished");
    digitalWrite(led, LOW); 

void send_data(){
  Serial.println("sending started");
  for(int i = 0; i < nSamples; i++)
  Serial.println("sending finished");


void loop() {

Do you really need 10 bit data? You could record more 8 bit samples.

Do you really need 10 bit data? You could record more 8 bit samples.

Unfortunately, yes, I do. Actually, I'm planning to use at some point an external ADC with higher resolution.

Why do you need to buffer a full chunk first before you send it ? You should be reading the pin using a timer interrupt and a pointer to the next 2 bytes in a ring buffer. And send smaller chunks to the PC depending on how much fresh data there is available in the buffer. Then you should buffer the rest at the PC end.
Before you start increasing the bit resolution i think you should kick up the sample rate first, 2000hz is not enough a spectrum analyzer.
One more idea, although i don't think is the way to go, is to store 4 10-bit values in 5 bytes.

For frequency analysis you probably don't need 10 bits. Try it with 8 bits. The increased temporal resolution will offset the loss.

Additionally, setting the analog core to 8 bits will dramatically increase the speed of analogRead. (I don't remember if analogReadResolution() does this or it just discards the extra bits.)