calculating frequency from analog samples

I have a buffer of 318 analog read samples which are spaced apart by 10us. How can i calculate the frequency from these samples? im making and oscilloscope.

void print_wave(){
  
  uint8_t pixel_buffer[320][2];
  uint16_t i = 0;
  Serial1.flush();
  while(digitalRead(b1)==HIGH){
    i = 0;
    digitalWrite(f2,HIGH);
    while((digitalRead(f1)==LOW)&&(digitalRead(b1)==HIGH)){}
    while(i<318){
      if((Serial1.available() > 0)&&(digitalRead(b1)==HIGH)){
        pixel_buffer[i][2] = Serial1.read();
        i++;
      }
    }
    digitalWrite(f2,LOW);
    i=1;
    while((i<318)&&(digitalRead(b1)==HIGH)){
      tft.drawFastVLine(i, 240-pixel_buffer[i][1]*0.7, 1, BLACK);
      tft.drawFastVLine(i, 240-pixel_buffer[i][2]*0.7, 1, YELLOW);
      pixel_buffer[i][1] = pixel_buffer[i][2];
      i++;
    }
    i = 0;
  }
}

The sample rate needs to be at least twice as fast as the frequency that you are trying to measure.
To calculate the frequency you need to run through the samples looking for readings rising and then falling i.e. you detect the peaks. From that you then calculate the frequency.

ardly:
The sample rate needs to be at least twice as fast as the frequency that you are trying to measure.
To calculate the frequency you need to run through the samples looking for readings rising and then falling i.e. you detect the peaks. From that you then calculate the frequency.

Yes, according to the sampling theory. If OP can sample at a singificantly higher frequency it could work to set a trigger level for the readings, recorded together with the time stamp of the data and then take the difference between the 2 sample times when the threshold is reached and invert it.

Calculating the peaks is easy enough and calculating how many times it crosses the half way point ((vmax-vmin)/2)+vmin should give me the frequency however i am lost on how to implement it with the loop.

    uint8_t vmin = 0;
    uint8_t vmax = 255;
    while((i<318)&&(digitalRead(b1)==HIGH)){
      if (vmax < pixel_buffer[i][2])
        vmin = pixel_buffer[i][2];
      if (vmin > pixel_buffer[i][2])
        vmin = pixel_buffer[i][2];
    }
    
    while((i<318)&&(digitalRead(b1)==HIGH)){
      
    }

Please attach the entire code. Your snipp of code shows undeclared variables…..

Ok i didnt really want to share teh code as alot of it is irrelevant to the problem, however this part is within the function print_wave() and b1 can be assumed to be always high.

#include <Elegoo_GFX.h>    // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
const int b1 = 36;
const int b2 = 50;
const int b3 = 48;
const int b4 = 46;
const int b5 = 44;
const int b6 = 42;
const int b7 = 40;
const int b8 = 38;
const int f1 = 34;
const int f2 = 30;

Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

void setup(void) {
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(b3, INPUT);
  pinMode(b4, INPUT);
  pinMode(b5, INPUT);
  pinMode(b6, INPUT);
  pinMode(b7, INPUT);
  pinMode(b8, INPUT);
  pinMode(f1, INPUT);
  pinMode(f2, OUTPUT);
  Serial.begin(115200);
  Serial1.begin(115200);
  Serial.println("boot");
  tft.reset();
  tft.begin(37697);
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  draw_text();
}

const uint16_t width = 320;
const uint8_t height = 240;

void loop(void){
  //draw_grid();
  if(digitalRead(b1)==HIGH)
    print_wave();
}

void print_wave(){
  
  uint8_t pixel_buffer[320][2];
  uint16_t i = 0;
  Serial1.flush();
  while(digitalRead(b1)==HIGH){
    i = 0;
    digitalWrite(f2,HIGH);
    while((digitalRead(f1)==LOW)&&(digitalRead(b1)==HIGH)){}
    while((i<318)&&(digitalRead(b1)==HIGH)){
      if((Serial1.available() > 0)&&(digitalRead(b1)==HIGH)){
        pixel_buffer[i][2] = Serial1.read();
        i++;
      }
    }
    digitalWrite(f2,LOW);
    
    uint8_t vmin = 0;
    uint8_t vmax = 255;
    while((i<318)&&(digitalRead(b1)==HIGH)){
      if (vmax < pixel_buffer[i][2])
        vmax = pixel_buffer[i][2];
      if (vmin < pixel_buffer[i][2])
        vmin = pixel_buffer[i][2];
    }
    
    while((i<318)&&(digitalRead(b1)==HIGH)){
      
    }

    
    
    i=1;
    while((i<318)&&(digitalRead(b1)==HIGH)){
      tft.drawFastVLine(i, 240-pixel_buffer[i][1]*0.7, 1, BLACK);
      tft.drawFastVLine(i, 240-pixel_buffer[i][2]*0.7, 1, YELLOW);
      pixel_buffer[i][1] = pixel_buffer[i][2];
      i++;
    }
    i = 0;
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

void draw_text(){
  
  tft.setTextColor(WHITE);  
  tft.setCursor(0, 0);
  tft.setTextSize(1);
  tft.println("Time div   10ms");
  tft.setCursor(0, 10);  
  tft.setTextSize(1);
  tft.println("Volt div  0.13V");
  tft.setCursor(0, 20);  
  tft.setTextSize(1);
  tft.println("Frequency 300Hz");
  tft.setCursor(0, 30);  
  tft.setTextSize(1);
  tft.println("Volt max   2.3V");
  tft.setCursor(0, 40);  
  tft.setTextSize(1);
  tft.println("Volt min   1.3V");
  
}


void draw_grid(){
  
                            tft.drawFastVLine(0, 60, height, RED);
                            tft.drawFastVLine(width-1, 60, height-40, RED);
  for(int i = 1; i<10; i++){tft.drawFastVLine(i*32, 60, height-40, RED);}
  for(int i = 1; i<65; i++){tft.drawFastVLine(i*5, 60+90-3, 7, RED);}
  for(int i = 1; i<36; i++){tft.drawFastHLine(160-3, i*5+60, 7, RED);}
                            tft.drawFastHLine(0,60, width, RED);
  for(int i = 1; i<6; i++){ tft.drawFastHLine(0,60+i*30, width, RED);}
                            tft.drawFastHLine(0, height-1, width, RED);
}