Page 1 of 1

Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Mon Oct 16, 2023 7:47 pm
by sesh
I am trying to use pin PB0 in analogRead mode on a Nucleo32 G431KB. This is the code that I am using:

Code: Select all

#include <Arduino.h>

void setup() {
    Serial.begin(9600);
    pinMode(PB0, INPUT_ANALOG);
}

void loop() {
    int analogValue = analogRead(PB0);

    Serial.println("Analog Value (PB0): " + String(analogValue));

    delay(1000);
}
When I run this code and change the voltage applied to the pin, there is no response on the serial monitor. Currently, the serial monitor outputs a value, but this value dones't change in accordance with the voltage applied.

I have tested analog read on this pin with HAL using STM32CubeIDE and it works without issues. How do I resolve this issue and make this pin work using stm32duino?

Re: Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Tue Oct 17, 2023 8:02 am
by gauthierDCC
Try with to add that in your setup()

Code: Select all

analogReadResolution(12);

Re: Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Tue Oct 17, 2023 8:50 am
by sesh
Tried that, it still doesn't work

Re: Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Wed Oct 18, 2023 7:48 am
by fpiSTM
Hi @sesh
In fact, hte PB0 has not been declared as analog pin. That's why you get this issue.
Could you file an issue on GitHub, then I will do the update.
https://github.com/stm32duino/Arduino_Core_STM32/issues

Re: Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Wed Nov 15, 2023 4:50 am
by leaderstutter
Thanks, problem solved for me. :)

Re: Issues with analogRead() for PB0 on Nucleo G431KB

Posted: Thu Nov 16, 2023 10:18 am
by fpiSTM