Issues with analogRead() for PB0 on Nucleo G431KB

Post Reply
sesh
Posts: 2
Joined: Mon Oct 16, 2023 7:38 pm

Issues with analogRead() for PB0 on Nucleo G431KB

Post 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?
by fpiSTM » Thu Nov 16, 2023 10:18 am Go to full post
gauthierDCC
Posts: 6
Joined: Tue Oct 10, 2023 2:50 pm

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

Post by gauthierDCC »

Try with to add that in your setup()

Code: Select all

analogReadResolution(12);
sesh
Posts: 2
Joined: Mon Oct 16, 2023 7:38 pm

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

Post by sesh »

Tried that, it still doesn't work
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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
leaderstutter
Posts: 1
Joined: Wed Nov 15, 2023 4:46 am

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

Post by leaderstutter »

Thanks, problem solved for me. :)
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post by fpiSTM »

Post Reply

Return to “PR's bugs and enhancements”