User Configuration sampling rate

Hello all,

I want to control the sampling rate, can we make some GUI for controlling the sampling rate of the program.

In the given code, I want to change in sampling rate, for changing the sample rate I have change baud rate and also used the timer but still no change in sampling rate. I have use timer 3 (shown in the code ) and changed value (1e4) with a different time period. it gives the only approx 40 samples per second and the required sampling rate is 20HZ to 3KHZ.

Please provide some solution for changing the sampling rate and this sampling rate can be changed through GUI.

#include <avdweb_SAMDtimer.h>
#include <Scheduler.h>
#include <time.h>    
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BMP280.h>
#define VBATPIN A7
#define BMP_SCK  (SCL)
#define BMP_SDI (SDA)
int count = 0;
int VCC = A4;
int led = 5;
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
const int chipSelect = 4;
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
int RawMin = -11;
int RawMax = 1020;
// Take multiple samples to reduce noise
const int sampleSize = 1;
Adafruit_BMP280 bmp; // I2C
File dataFile;
char filename[15];
uint16_t fileNumber=0;

SAMDtimer mytimer1 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A0, 1e4);
SAMDtimer mytimer2 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A1, 1e4);
SAMDtimer mytimer3 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A2, 1e4);
SAMDtimer mytimer4 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, SCL, 1e4);
SAMDtimer mytimer5 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, SDA, 1e4);

void setup(){
  Serial.begin(250000);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 // pinMode(led, INPUT_PULLUP);
  Serial.println(F("BMP280 test"));
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
    bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  while (!Serial){
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
  strcpy(filename, "/LOG00000.TXT");
  for(uint16_t i = 0; i<10000; i++) {
    filename[8] = '0' + i%10;
    filename[7] = '0' + (i/10)%10;
    filename[6] = '0' + (i/100)%10;
    filename[5] = '0' + (i/1000)%10;
    filename[4] = '0' + i/10000;
    Serial.println(filename);
    if (! SD.exists(filename)){
      fileNumber=i;
      break;
    }}
 
}



uint16_t lineNum=0,lineNumLimit=1000;
uint8_t i = 0;
int count1 = 1;

void loop()
{
  count1++;
  Serial.println(count1);

  uint32_t sec = micros() / 1000000;
  uint32_t milli = millis();
  
  uint32_t mil = milli % 1000;
  //uint32_t minn60 = minn % 60;
  
  uint32_t sec60 = sec % 60;

  uint32_t minn = sec / 60;
  uint32_t minn60 = minn % 60;

  uint32_t hour = sec / 3600;
  uint32_t hour60 = hour % 60;

 //Read raw values
  int xRaw = ReadAxis(xInput);
  int yRaw = ReadAxis(yInput);
  int zRaw = ReadAxis(zInput);

  // Convert raw values to 'milli-Gs"
  long xScaled = map(xRaw, RawMin, RawMax, -200000, 200000);
  long yScaled = map(yRaw, RawMin, RawMax, -200000, 200000);
  long zScaled = map(zRaw, RawMin, RawMax, -200000, 200000);

  // re-scale to fractional Gs
  float xAccel = xScaled / -1000.0;
  float yAccel = yScaled / -1000.0;
  float zAccel = zScaled / 1000.0;

  Serial.print(F("Temperature = "));
  Serial.print(bmp.readTemperature());
  Serial.println(" *C");

  Serial.print(F("Pressure = "));
  Serial.print(bmp.readPressure());
  Serial.println(" Pa");

  Serial.print(F("Approx altitude = "));
  Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
  Serial.println(" m");
  

  Serial.print("X, Y, Z  :: ");
  Serial.print(xRaw);
  Serial.print(", ");
  Serial.print(yRaw);
  Serial.print(", ");
  Serial.print(zRaw);
  Serial.print(" :: ");
  Serial.print(xAccel,0);
  Serial.print("G, ");
  Serial.print(yAccel,0);
  Serial.print("G, ");
  Serial.print(zAccel,0);
  Serial.println("G");

if((lineNum%lineNumLimit) == 0)
{
    
  dataFile.close();
  filename[8] = '0' + fileNumber%10;
  filename[7] = '0' + (fileNumber/10)%10;
  filename[6] = '0' + (fileNumber/100)%10;
  filename[5] = '0' + (fileNumber/1000)%10;
  filename[4] = '0' + fileNumber/10000;
  Serial.print("\ncurrent filename is : ");
  Serial.println(filename);
  fileNumber++;
  
  dataFile = SD.open(filename, FILE_WRITE);
    dataFile.print("HH:MM:SS:mmmm   -   x");
    dataFile.print(",");
    dataFile.print("y");
    dataFile.print(",");
    dataFile.print("z");
    dataFile.print(",");
    dataFile.print("Temp");
    dataFile.print(",");
    dataFile.print("Press");
    dataFile.print(",");
    dataFile.println("Altitu");
}

    dataFile.print(hour60);
    dataFile.print(":");
    dataFile.print(minn60);
    dataFile.print(":");
    dataFile.print(sec60);
    dataFile.print(":");
    dataFile.print(mil);
    dataFile.print("   -   ");
    dataFile.print(xAccel,0);
    dataFile.print(",");
    dataFile.print(yAccel,0);
    dataFile.print(",");
    dataFile.print(zAccel,0);
    dataFile.print(",");
    dataFile.print(bmp.readTemperature());
    dataFile.print(",");
    dataFile.print(bmp.readPressure());
    dataFile.print(",");
    dataFile.println(bmp.readAltitude(1013.25));
   // dataFile.println(count1);
    lineNum++;

}

// Take samples and return the average
int ReadAxis(int axisPin)
{
  long reading = 0;
  analogRead(axisPin);
  delay(1);
  for (int i = 0; i < sampleSize; i++)
  {
  reading += analogRead(axisPin);
  }
  return reading/sampleSize;
}

Please provide me some solution related to my problem. how can i increase sampling rate ...

Delta_G:
I don't see any code in there that sets any time between samples. It looks like it is running as fast as it can. You need to describe the problem better. How many data points per second are you getting? How many do you want?

for increase sampling rate i have use timer but it not work. you give me some code or edit in my code how can i increase sampling rate upto 3khz.

i want sampling rate 20hz to 3khz but when i run my program it only acquired approx 45 sample per second.

Maybe you did it wrong. I don't see what you're going to do with a timer in that particular code you posted. Maybe you should talk about how you were trying to use the timer.

Sir its my first project in arduino programming. I donts know how i use timer in my code some one suggest me to use timer for increase sampling thats why i try.
<SAMDtimer mytimer1 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A0, 1e4);
SAMDtimer mytimer2 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A1, 1e4);
SAMDtimer mytimer3 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, A2, 1e4);
SAMDtimer mytimer4 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, SCL, 1e4);
SAMDtimer mytimer5 = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, SDA, 1e4);>

Seriously, did you not read my last reply?
OK, 45 Hz is right in the range you ask for. Sounds like your problem is solved.

sir i read your last post. my problem not solved 45hz is very less sampling rate i want maximum 3khz sampling rate.

If you want more specific help then you're going to have to ask more specific questions. What kind of sensor are you reading? What is this program supposed to do? Will the sensor you have work at that rate? You've given us very little to go on here.

i have use 1 accelerator sensor ADXL377 and 1 temperature and humidity sensor BMP280 and i have use Feather M0 Adalogger board for connection accelerator sensor i connected analog pin A0 to A2 and Temperature sensor SDA and SCL pin of board . i want store both sensor data in SD card in Text file with Time. for programming read my first post(starting post) stump. But when i run my program it data acquired limit is very less.

What part of that sentence do you not understand? So unless your next post is to show me what determines the time between samples in your current code, then you are wasting both of our time.

Sir i already read your post and i have also explain my problem to you. My problem is simple i just want increase sampling rate upto 3khz so what can i change in my program. if it running as fast as it can, so any chance to increase its data acquiring speed.

Delta_G:
And you didn't show that. So I'm done here. Best of luck to you.

I understand that you want it to go faster. But you won't answer my question so I can't help you.

sir actual you have not the solution of my problem each time you give just explanation i already wrote my problem with the code. how to i increase the sampling rate i just want some code which i add in my program to increase the sampling rate.

and thank for you given your valuable time for me.

Hello All

Reply to my post. I am new in the Arduino platform and I think its a common problem.

Rather demanding and unwilling to answer question. Nope.

Delta_G:
I did reply. I asked you a question. You ignored it. You are rude. When you stop being rude and decide to answer, maybe someone will help you.

sir i just simply say how can increase sampling rate or what can i change in my program for getting maximum sampling rate up to 3khz. because i don't no how i increase the sampling rate

What in your current code determines the time between samples?

sir current code acquired 40 samples per second means so simply 1000ms/40= 25ms. so the time between sample approx 25ms.

Delta_G:
I think it doesn't. I think there's nothing in there. And if that is the case then you can't make it any faster. You've hit the limit. But until you stop being rude and simply answer the question I am asking I cannot know.

Do you just not understand the question? Maybe you need to get some help to read English? I don't know why you aren't answering.

First of all, i am not being rude why you say that again and again. I don't know Arduino coding first time i have used Arduino i am doing mostly project in LabVIEW. so i don't know the code for a time between sample. i postcode in beginning u check that code.

Delta_G:
What in your current code determines the time between samples?

Sir, In my code i havent defined anything which could be used to control the sampling rate, i think its using its default sampling rate to capture data. could you please elaborate on how to do that.

SAMD+Labview. Unfamiliar terrain for most of us.

Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

That might add 500ms between samples.
According to the library, you can reduce that to 1.

delay(1); // dunno, might be needed for the slow BMP280.
Datasheet states a max measurement rate of 157 Hz.

Why the need for this high sample rate for a static pressure sensor.
Leo..

Wawa:
SAMD+Labview. Unfamiliar terrain for most of us.

Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

Sir, In this code should i try to control the sampling rate.

Why the need for this high sample rate for a static pressure sensor.
Leo..

Sir, i m a student trying to learn for my upcoming final year project.

Sir i have also use Adafruit ADXL377 and Feather M0 adalogger with BMP280.

amitshishodia:
Sir, i m a student...

Then you should ask the teacher, because they are getting paid for what they are supposed to do.
Leo..

Wawa:
Then you should ask the teacher, because they are getting paid for what they are supposed to do.
Leo..

Even they don't know. if you can help please then help me

Did you first write code for each individual sensor, before combining the two.
Which one was the slowest one. My guess is the BMP280 (157Hz max).
Did you try that out before trying to write that to an SD card.
How much extra time dit that logging take.

Building a working system is taking little steps towards your goal.
Can't be done in one go, and can't be done without basic knowledge.
Using a SAMD processor seems like jumping in the deep without having learned to swim.
Good luck.

Oh, and try to get that teacher fired.
A teacher should know waaay more than it's students.
Leo..