GIGA advancedanalog does not accept readings from analog pins except A8 and A9

Hi,

Please , could someone explain why using the advancedanalog library I can't read the analog pins except A8, A9?
It compiles and uploads, but the red LED keeps blinking

Thanks

#include <Arduino_AdvancedAnalog.h>
#define SAMPLE_RATE (96000)
#define NEXTPOTREAD (100)
AdvancedADC channelA0(A0);
AdvancedDAC dac0(A12);
uint32_t ts_nextPotRead = 0;

void setup()
{
    Serial.begin(115200);
    if (!channelA0.begin(AN_RESOLUTION_12, SAMPLE_RATE, 32, 32))
    {
        Serial.println("ADC fail...");
        while (1)
            ;
    }
    if (!dac0.begin(AN_RESOLUTION_12, SAMPLE_RATE, 32, 32))
    {
        Serial.println("Failed to initialize DAC 1");
        while (1)
            ;
    }
    Serial.println("Setup OK!");
}

void loop()
{
    if (millis() > ts_nextPotRead)
    {
        ts_nextPotRead = ts_nextPotRead + NEXTPOTREAD;
        // int read = analogRead(PIN_A3); // not working
        // int read = analogRead(A4);     // not working
        // int read = analogRead(PIN_A4); // not working
        // int read = analogRead(A5);     // not working
        // int read = analogRead(PIN_A5); // not working
        // int read = analogRead(A6);     // not working
        // int read = analogRead(PIN_A6); // not working
        // int read = analogRead(A7);     // not working
        // int read = analogRead(PIN_A7); // not working
        int read = analogRead(A8);     // OK!
        // int read = analogRead(A9);     // OK!
        // int read = analogRead(A10);    // not working
    }

    if (channelA0.available())
    {
        SampleBuffer inBuffer = channelA0.read();
        SampleBuffer outBuffer = dac0.dequeue();
        for (int i = 0; i < inBuffer.size(); i++)
        {
            outBuffer.data()[i] = inBuffer[i];
        }
        dac0.write(outBuffer);
        inBuffer.release();
    }
}

See if this helps: Analog PIN numbers - #4 by UKHeliBob

Hi @gibrancurtiss. I think it is explained (poorly) by this section of the Arduino_AdvancedAnalog library's documentation:

https://github.com/arduino-libraries/Arduino_AdvancedAnalog/tree/main/docs#adc-multichannel-giga-r1-wifi

This library supports concurrent usage of up to three ADCs (ADC1, ADC2 and ADC3). Each ADC instance can handle up to 16 channels.

Note: It's important to be aware that certain pins cannot be used across multiple ADCs or cannot share the same ADC.

This line:

causes ADC1 to be taken by the library. If you look at the table at the link above, you will see that all analog pins other than A8 and A9 are also on ADC1.

Your code seems a bit strange. Why are you using the Arduino_AdvancedAnalog library to read A0, but then trying to read other analog pins using analogRead? If you are going to use the Arduino_AdvancedAnalog library, you should just use it for all the ADC operations in your sketch instead of doing a mix and match between the two systems. If you study the documentation at the link I provided above and then change your code to use the Arduino_AdvancedAnalog library exclusively, I think you will find that solves the problem.


In order to make all relevant information available to any who are interested in this subject, I'll share a link to the formal bug report submitted by @gibrancurtiss:

" If you are going to use the Arduino_AdvancedAnalog library, you should just use it for all the ADC operations in your sketch instead of doing a mix and match between the two systems"

Thank you !

1 Like

Problem solved

#include <Arduino_AdvancedAnalog.h>
#define SOUND_SAMPLE_RATE (48000)
#define CONTROL_SAMPLE_RATE (10) 

AdvancedADC adcIn(A6);
AdvancedADC adcControls(A0, A1, A2);
AdvancedDAC dacOut(A12);

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        ;

    delay(2000);
    Serial.println("Setup begin");
    if (!adcIn.begin(AN_RESOLUTION_12, SOUND_SAMPLE_RATE, 32, 32))
    {
        Serial.println("ADC fail...");
        while (1)
            ;
    }
    if (!dacOut.begin(AN_RESOLUTION_12, SOUND_SAMPLE_RATE, 32, 32))
    {
        Serial.println("Failed to initialize DAC 1");
        while (1)
            ;
    }
    if (!adcControls.begin(AN_RESOLUTION_10, 100, 1, 3))
    {
        Serial.println("Failed to initialize controls");
        while (1)
            ;
    }
    Serial.println("Setup end");
}

void loop()
{
    if (adcControls.available())
    {
        SampleBuffer controlBuffer = adcControls.read();
        for (int i = 0; i < controlBuffer.size(); i++)
        {
            Serial.print(controlBuffer[i]);
            Serial.print(", ");
        }
        Serial.println();
        controlBuffer.release();
    }

    if (adcIn.available())
    {
        SampleBuffer inBuffer = adcIn.read();
        SampleBuffer outBuffer = dacOut.dequeue();
        for (int i = 0; i < inBuffer.size(); i++)
        {
            outBuffer.data()[i] = inBuffer[i];
        }
        dacOut.write(outBuffer);
        inBuffer.release();
    }
}

Great work on adapting your sketch to use the "Arduino_AdvancedAnalog" library exclusively for ADC. Thanks for taking the time to post an update with your solution!

Regards, Per

1 Like