Exponential delay in analog serial read needed

Hi there!
I need to data log analog read and the delay between each data log should increase exponentially [e.g. interval = 2^(count*0.054) with count increases only by one per data log], please help me on the code. I need to delay the data logging this way because the significant changes occur in the first 30 minutes and becoming more stable up to 24 hours. I want to limit my data point to only 300. Currently, I'm doing it per second so I have 86,400 data points in 24 hours, cumbersome for spreadsheet calculations. I want to have more or less similar spaced data points in a logscale X-axis or time in seconds like the one I attached.
Thank you very much for your help.

Capture.PNG

Capture.PNG

please help me on the code

You forgot to post it. Please don't compound the error by posting it incorrectly. Read the forum guide for advice.

Sorry, but I don't have yet the code with the exponential delays, what I have is the data logging code with one second interval using the simple delay (i.e. delay(1000)).

Fine, don't post the code. Good luck with your project.

#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  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.");
}

void loop() {
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
   delay(1000); // Here I want to increase the delay exponentially.
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

Here is my current code, the arduino is recording the voltages from A0-A2 to SD card in one second interval. I want data log it in an exponential delay. Example delays in seconds (1 2 3 6 9 15 23 37 58 91 143 225 354 556 874 1373 2158 3390 5325 8365 13140 20640 32422 50929 80000). I got these numbers from excel using the formula Delays = INT(10^(Log(80000)/300)*Count); where count is increasing each logging session from 1-300.

OK, thanks for posting your code and thanks for posting it correctly. +1 Karma

The formula in your last post looks incorrect, it will not produce the exponential series you require. I think you must have used a slightly different formula in Excel. Maybe check exactly where you have placed your brackets. The formula you posted in your first post is different, that would produce an exponential series.

Once that is corrected, your exponential delay sequence should be easy enough to achieve by amending your code. At the top of this page you should see a menu "DOCUMENTATION", which contains "REFERENCE". This will take you to a page which should help you find the functions you need to code your excel formula in Arduino language (C++).

You will also need to make a new variable to count the number of measurements so far - the "Count" in your formula above.

I just realised that there is no log() function listed on that page, I do not know why it is not shown. However, the log() function in C is natural log (log to base e, not to base 10). Fortunately there is also a log10() function.

PaulRB:
The formula in your last post looks incorrect, it will not produce the exponential series you require.

I have so may sheets and I copied the wrong formula. Here is the correct formula to get the exponential series.
Delays = INT(10^(LOG(80000)/25*Count)) -- were count is increasing every logging event (from 1-25).

PaulRB:
I just realised that there is no log() function listed on that page, I do not know why it is now shown. However, the log() function in C is natural log (log to base e, not to base 10). Fortunately there is also a log10() function.

I will check these log functions. Though, I'm not sure if I can implement it in the arduino sketch. I will try. Thank you.

I'm not sure if I can implement it in the arduino sketch

Maybe you could just stick the values you already have in an an array and increment an index to get the right one.

The array is a good suggestion. Why not try both array and formula methods, to build your coding skills!

There is no need to limit the delays to being an exact number of seconds. Doing that might even make a small difference to your earlier measurements. The delay() function runs in milliseconds, so it's easy to calculate and time the delays in milliseconds also.

microSeconds even, if you want to get carried away.
micros() and delayMicroseconds().

SOLVED!!! I used the log10() function as mentioned by PaulRB, then use the power() to raise my base. Here is the sample code I used on testing. Delays are in milliseconds.

uint32_t SDM = 0; //Sampling delay in ms
uint32_t SN = 0; // Sampling number
int SM = 300;   // maximum sampling number

void setup() { 
Serial.begin (9600);
}
 
void loop() { 
  
if (++SN > SM) { 
SN = 1; 
}
float SDMex = (log10(86400)/SM)*SN; //the exponent part --86400 is the number of sec in 1 day
SDM = pow(10,SDMex); // the sampling exponential delay
Serial.print("Sample No: "); 
Serial.print(SN);
Serial.print("\tDelay: "); 
Serial.println(SDM);
delay(SDM); 
}

Nice job!