-1

I am trying to get a spectrum analyser up and running. I found the following code on Galileo GEN2 Project - Real-Time Audio Spectrum Analyzer1:

/*
 * 
 * Galileo GEN2 Project - Real-Time Audio Spectrum Analyzer
 * https://communities.intel.com/docs/DOC-23406
 * 
 * 
 * ERROR: analogReadResolution() ???
 * 
 */



#include <stdint.h>  //For New Arduino
#include "PCD8544.h"
#define pin_adc 0
#include "fix_fft.h"
char im[128];
char data[128];
int analog_value[128];
int i=0;
PCD8544 nokia = PCD8544(3, 4, 5, 7, 6);
// pin 7 - Serial clock out (SCLK) connects Dig3
// pin 6 - Serial data out (DIN) connects Dig4
// pin 5 - Data/Cmd. selct. (D/C) connects Dig5
// pin 4 - LCD reset (RST) connects Dig6
// pin 3 - LCD chip select (CS) connects Dig7
void setup() {
  nokia.init();
  nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
  nokia.clear();
  analogReadResolution(8);
}

void show_big_bars(char *spektrum) {
    int spek_for_draw;
    nokia.drawline(10, 15, 10, 39, BLACK);
    for (byte i = 1; i < 64; i++){ // Skip 0 Channel
      // Serial.print(spektrum[i],BYTE);
      spek_for_draw = 1.5*(spektrum[i]); // 0/2.5 ~ 255/2.5
      if (spek_for_draw > 39) spek_for_draw = 39;
      nokia.drawline(i+10, 39 - spek_for_draw, i+10, 39, BLACK);
    }
    //nokia.drawstring(5, 5, "0 09 22 36 49");
    nokia.drawstring(5, 5, "0");
    nokia.drawstring(21, 5, "4");
    nokia.drawstring(37, 5, "8");
    nokia.drawstring(48, 5, "12");
    nokia.drawstring(67, 5, "18");
    nokia.drawstring(5, 0, "Spectrum");
    nokia.drawstring(5, 1,"* 0.1KHz");
    nokia.display(); // Update Screen
    nokia.clear(); // Clear Screen for the animation
}
void loop(){
  static long tt;
  int val;
  if (i < 128){
      analog_value[i] = analogRead(pin_adc);
      i++;  
   }
   else{
        for (i=0; i< 128;i++){ //Prepare data for FFT
            data[i] = analog_value[i] - 128;
            im[i] = 0;
        }
   //this could be done with the fix_fftr function without the im array.
        fix_fft(data,im,7,0);
   // I am only interessted in the absolute value of the transformation
        for (i=0; i< 64;i++)
             data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
   //do something with the data values 1..64 and ignore im
        show_big_bars(data);
        i=0;
   }
}

When I attempt to compile the above code, I get the error

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Micro"

fft_galileo.ino: In function 'void setup()':
fft_galileo:31: error: 'analogReadResolution' was not declared in this scope
'analogReadResolution' was not declared in this scope

When I search for the location of analogReadResolution() on Google, I repeatedly get the information that it is only available for the Due and Zero. From Arduino - AnalogReadResolution:

analogReadResolution() is an extension of the Analog API for the Arduino Due and Zero.

I was wondering if I needed to add an #include statement but all of the code examples that I found do not have any specific #include for the Analogue library.

Also, thinking maybe it is board specific (as the video Arduino Due error: 'analogReadResolution' was not declared in this scope suggests), I selected the Duemilanove board (as the Due is not on offer in my "Board" menu), but I still get the same error. I have even tried the Arduino NG or older Board menu item, but with the same results.

So, how do I get rid of this compile time error? Or, more poignantly, how can I compile this code for my Uno or Leonardo board. Should I just comment it out? If I do comment the line out then the code does compile, so does this mean that analogReadResolution() is not required any longer?

If it isn't required, then why does this Uno specific example, How to Use ADC in Arduino Uno?, state:

As default we get the maximum board ADC resolution which is 10bits, this resolution can be changed by using instruction (“analogReadResolution(bits);”). This resolution change can come in handy for some cases.

How can the resolution be changed if the method has, indeed, been deprecated?

Also, why do I not have a "Due" in my Board menu?


1 For completeness fix_fft.h and fix_fft.cpp can be found on TJC's github and here is the PCD8544 Arduino library for Nokia 5510 LCD library. The password for decompressing Intel_Nokia5110.rar file is 406.

4
  • 1
    It's a Uno, not a UNO. It's not an acronym. Arduino is naming their boards Zero Uno Due Tre - that is Zero One Two Three.
    – Nick Gammon
    Aug 1, 2015 at 0:32
  • @NickGammon - Thanks for pointing that out. Not sure where, or why, I got the wrong idea. Feel a bit of a fool now. I have made some bad edits in that case :-( Aug 1, 2015 at 7:29
  • Don't worry about it. Your edits have been good. I've restrained myself from correcting UNO to Uno, because I wanted you to have the credit for making the edit. :)
    – Nick Gammon
    Aug 1, 2015 at 9:12
  • @NickGammon - I wish you had corrected them though, as I do appear to have sprayed UNO all over the shop. I think that I must have picked up the capitalisation of the Arduino website as they seem to put caps on everything, not sure. BTW, I think that you can make subsequent edits, when reviewing, as many of my edits get revised across SE (I'm not too sure of the procedure). Don't worry about letting me have the credit, I just want to see nice clean posts... ;-) Thx again. Aug 1, 2015 at 9:22

2 Answers 2

3

There is no point to having analogReadResolution() on AVR devices since that function only exists to provide/ensure backwards compatibility with the fixed 10-bit ADC that is found in AVR devices. If you want higher or lower resolution then you will need to perform the appropriate actions manually.

You don't have a Due entry because you haven't installed Atmel SAM support in the Board Manager.

0
2

Also, why do I not have a "Due" in my Board menu?

See:

Board manager menu item

Then:

Board manager install


I selected the Duemilanove board (as the Due is not on offer in my "Board" menu) ...

The Duemilanove and the Due are completely different boards, with different processors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.