noise measurements and analogRead with UDOO (Arduino Due)

Hi everybody,

I’m having some troubles trying to read an analog value coming from a sound sensor connected to an Arduino DUE (the arduino DUE part of an UDOO shield).

I am using the Grove Shield V2.0 (http://www.seeedstudio.com/wiki/Base_shield_v2) and the Grove sound sensor(http://www.seeedstudio.com/wiki/index.php?title=Twig_-_Sound_Sensor).

This is the code I’m using:

//Defining the ports
#define SOUND_SENSOR A0


//definition of the noise values array
#define N_SAMPLES 8000 //8K samples per second
#define N_SAMPLES_SEC 60 //one minute observation
int noiseValueArraySamples[N_SAMPLES];
int noiseValueArraySeconds[N_SAMPLES_SEC];


int c_index_sample = 0;
int c_index_sec = 0;

void setup()
{

 Serial.begin(115200); 
 pinMode(8, OUTPUT);
        PinMode(SOUND_SENSOR, INPUT)
 digitalWrite(8, 0);
 delay(1000);
 inizializeNoiseArray();
 
}

void loop()
{
 
 int actualNoiseValue = readNoise(SOUND_SENSOR);

 noiseValueArraySamples[c_index_sample] = actualNoiseValue;

 ++c_index_sample;

 if (c_index_sample == (N_SAMPLES - 1))
 {
 c_index_sample = 0;
 int secMeanNoise = array_mean(noiseValueArraySamples, N_SAMPLES);
 noiseValueArraySeconds[c_index_sec] = secMeanNoise;
 ++c_index_sec;
 Serial.print("Noise in a second  ");
 Serial.println(secMeanNoise);
 if (c_index_sec == (N_SAMPLES_SEC))
 {
 c_index_sec = 0;
 Serial.println(array_mean(noiseValueArraySeconds, N_SAMPLES_SEC));
 }
 }
 
 delayMicroseconds(125); //sample rate = 8kHz

}

//Function for inizializing the arrays at the beginning of the program
void inizializeNoiseArray(){

 for (size_t i = 0; i < N_SAMPLES; i++)
 {
 noiseValueArraySamples[i] = 0;
 
 }
 for (size_t i = 0; i < N_SAMPLES_SEC; i++)
 {
 noiseValueArraySeconds[i] = 0;
 }
 //Serial.println("Inizializzazione fatta");
}

//This function reans the instant value of noise
int readNoise(uint8_t analogpin)
{
 int noiseValue = analogRead(analogpin);
 return noiseValue;
}

//Function for compute the mean value of an array of int
int array_mean(int in_array[], int lenght)
{
 long valueSum = 0L;

 for (int i = 0; i < lenght; i++){

What happens her is that the values I’m reading kind of stabilize after a while between 480/500. If I make some noises there are some changes in the value, but after a while the values go back to the range I indicated.

I tried to change the port, but it is the same. I also tried to read the port with nothing attached and the reads are always stable around 480 (shouldn’t be 0?).

Do you find anything strange in the code?
Or, do you think there is something wrong in my UDOO?

Thank you very much!
L