Sending blocks of data to excel

Hi,

I'm getting my sensor readings from my microphone every 50ms (20 times a second. I understand how to print into excel, but is it possible store them in blocks like this?:

(1) Second block (2) Second block (3) second block 0.3 8.7 1.6 3.2 etc 4.7 5.2 3.5 7.5 2.5 3.6 1.4 2.7 0.4 2.4 6.7 7.4 3.4 3.4 3.4 6.7 7.8 3.5 1.2 1.3 3.7 0.6 6.5 8.9 4.1 9.2 1.7 3.8 5.6 5.7 4.9 3.7 4.1 8.6 2.3 8.6

Or better yet, add all of them together and store it into excel e.g (1) second - 69.8, (2) second - 104.7, (3) second - etc

Is this an Arduino or an Excel programming question?

What ever works best.

Ideally in the arduino, i would like the code will add up 20 readings per second and then send them to excel…

#include <math.h>
#define PI 3.1415926535897932384626433832795
 
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
 
void setup() 
{
   Serial.begin(9600);
}
 
void loop() 
{
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1023;
 
   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
   {
      sample = analogRead(A0);
      if (sample < 1023)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   double volts = (peakToPeak * 5.0) / 1023.0;  // convert to volts
   
   double watts = volts * 0.001; // volts times amps
   
   double soundPower = 10.0 * log10(watts/10e-12);
   
   double soundPressure = soundPower + (10.0 * log10(1.0/(4.0*PI*pow(2,2))));

//--------------------------------------------------------------
// Add up and send every 1 second (20 samples per second)
//--------------------------------------------------------------


                             Need Code :(


----------------------------------------------------------------
   
   Serial.print("sound pressure: ");
   Serial.println(soundPressure);
#include <math.h>
#define PI 3.1415926535897932384626433832795

Both of these defines are included by default by the IDE.

Why do you consider 1023 a spurious reading?

Also, you are already collecting min/max samples per 50ms. Why not just change the sample calculation rate to 1 Hz?

aarg: Why do you consider 1023 a spurious reading?

I took half of this code off of the adafruit website and that was on it. https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels

I tried to delete it a couple of days ago but it caused errors in my code so i just left it. Its not hurting anyone.

I wish i could just take 1 reading a second, that would make my life a lot easier. But i need to get 20 readings a second, add them up, store them in excel, divide by 20 to get the average, then i'm sorted. But one step at a time!

Any ideas on how to accomplish this?

Your help would be greatly appreciated

I'm puzzled. You already have code to take an average. Why can't you use the same code?

I don’t have the code to take an average?

quote - “But i need to get 20 readings a second, add them up, store them in excel, divide by 20 to get the average, then i’m sorted.”

That is my game plan, i haven’t accomplished this yet!

i don’t know how to average the readings that i am getting in my serial

mrears92: That is my game plan, i haven't accomplished this yet! i don't know how to average the readings that i am getting in my serial

Well, that is the source of my puzzlement because you were shown averaging code in your other recent threads.

The averaging just took a random number from the data, i need the MEAN.

Averaging is not what i’m asking at the moment though, my first question is the one i need answers to?