Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pins from A8 to A11 cannot be used on Arduino Giga R1 #81

Open
mzap-bit opened this issue Oct 1, 2024 · 7 comments
Open

Pins from A8 to A11 cannot be used on Arduino Giga R1 #81

mzap-bit opened this issue Oct 1, 2024 · 7 comments
Labels
topic: code Related to content of the project itself topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project

Comments

@mzap-bit
Copy link

mzap-bit commented Oct 1, 2024

Hello guys,

I am struggling to acquire a signal using A8,A9,A10, A11 pins of Arduino Giga R1.

Here's the modified example code I am using:

#include <Arduino_AdvancedAnalog.h>

AdvancedADC adc(A8.get()); // I must use this method to avoid compiler error
// AdvancedADC adc(PC_2C); // this doesn't wok as well I assume AdvancedAnalog relies on pins_arduino.h definitions (where the PureAnalogPins are not defined)
uint64_t last_millis = 0;

void setup() {
    Serial.begin(9600);

    // Resolution, sample rate, number of samples per channel, queue depth.
    if (!adc.begin(AN_RESOLUTION_16, 16000, 32, 128)) {
        Serial.println("Failed to start analog acquisition!");
        while (1);
    }
}

void loop() {
    if (adc.available()) {
        SampleBuffer buf = adc.read();
        // Process the buffer.
        if ((millis() - last_millis) > 20) {
          Serial.println(buf[0]);   // Sample from first channel
          Serial.println(buf[1]);   // Sample from second channel
          last_millis = millis();
        }
        // Release the buffer to return it to the pool.
        buf.release();
    }
}

The code compiles, but the serial values are showing values as if the pin is floating (despite I have placed a 1k resistor to 3.3V).

@leonardocavagnis
Copy link
Contributor

Hi @mzap-bit,

Currently, the library does not support PureAnalogPin on the Arduino GIGA R1 (A8, A9, A10, and A11).
We will address this issue in the next release.

Thank you for reporting it.

@leonardocavagnis leonardocavagnis added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Oct 1, 2024
@leonardocavagnis leonardocavagnis changed the title [Bug] Pins from A8 to A11 cannot be used on Arduino Giga R1 Pins from A8 to A11 cannot be used on Arduino Giga R1 Oct 1, 2024
@mzap-bit
Copy link
Author

mzap-bit commented Oct 1, 2024

Hi @leonardocavagnis ,

You're welcome! Thank you for your great work! :)

Just a small hint for the API doc: currently it is mentioned the Pins from A8 to A11 are actually supported, I've spent some time wondering what was wrong with my code trusting this info! A slight update might help other users!

@BenLesArd
Copy link

Hi,
Thank you for your work.
Do you have an idea when you might work on this topic?
I also spend some hours before reading this post.
Same issue with my project, I need all the Analog ADC input for my project.
This is not to stress you.
May I help you? I am retired and have time to spend on this.
Does adding A8, A9, A10, A11 define u value might help (these are missing in the pin description .h) ?
Merry Xmas,
Ben

@leonardocavagnis
Copy link
Contributor

Hi @BenLesArd,

Unfortunately, solving this issue isn’t as simple as adding the missing define statements.
The core of the problem lies in the way the AdvancedADC class is designed. Specifically, its constructor would need to be modified to handle PureAnalogPin types.

The definitions for these pins (A8, A9, A10, A11) are found in the GIGA variant of the ArduinoCore-mbed, specifically in pure_analog_pins.cpp.

One straightforward approach would be to create a dedicated constructor that handles only PureAnalogPin types. However, this solution has its drawbacks because it wouldn’t allow a mix of “normal” pins and PureAnalogPin types during initialization.

We won’t be able to work on this in the short term, but your help would be greatly appreciated!
If you’re interested in contributing, feel free to try this approach as a starting point or propose any other feasible solution. 🙂

Thank you for your interest and Merry Christmas! 🎄

@BenLesArd
Copy link

Hi Leonardo,

I had some time to go deeper in the code.

I have found analogPinToPinName (p) in mbed. (ArduinoCore-mbed/variants/GIGA/pins_arduino.h)

I have read PureAnalogPin which are defined in mbed/variants/GIGA/pure_analog_pins.h and declared in ../pure_analog_pins.cpp.
I also found that in mbed, we have 2 versions of the function AnalogRead: one for the classic AnalogPin and one for PureAnalogPin. (in mbed/.../pure_analog_pins.cpp)
At the end to read the adc, these 2 functions use new mbed::AnalogIn(pin) were pin has a type of PinName.

So far, I think that it would be better to be able to accept the both types of AnalogPin in the list of the constructor of AdvanceADC.
To do that I think the best would be to create a class for the all the Analog Pin (like AdvanceAnalogPin...).
That class should be similar to the PureAnalogPin but adding a type (Analog or PureAnalog) and should be used
to instantiate the class for A_A0,.. A_A13 by using the existing A0...A7, A12, A13 or A8.get()... A11.get() to set their pins.
(N.B. In ArduinoCore-mbed/variants/GIGA/pins_arduino.h: we found, ... const uint8_t A0 = PIN_A0... which makes it difficult to replace and, the same for the PureAnalogPin objects A8...A11 that are also declared in mbed )
When creating an instance of AdvanceAdc, the constructor will receive a list of objects and then use the right approach (code) to get the PinName(s) by checking the type of the object. The constructor can use: analogPinToPinName(p.get()) for the classic AnalogPin or use ??? g_pureAAnalogPinDescription[p.get()].name for the PureAnalogPin.

What do you think?

I still have to check what is that g_pureAAnalogPinDescription... (i have found the extern declaration in Arduino.h but I don't find where this is set...)

Regards,

Ben

@per1234 per1234 added the topic: documentation Related to documentation for the project label Dec 27, 2024
@leonardocavagnis
Copy link
Contributor

Hi @leonardocavagnis ,

You're welcome! Thank you for your great work! :)

Just a small hint for the API doc: currently it is mentioned the Pins from A8 to A11 are actually supported, I've spent some time wondering what was wrong with my code trusting this info! A slight update might help other users!

Done :) #86
Thanks for pointing out!

Hope to fix it soon in the next release

@leonardocavagnis
Copy link
Contributor

I still have to check what is that g_pureAAnalogPinDescription... (i have found the extern declaration in Arduino.h but I don't find where this is set...)

Here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants