INPUT_PULLUP not working?

im having some trouble with a code, I suspect its because of an analog read not doing what i expect it to .
are the pullups weak on the h7?
the follwoing code give the following output in terminal.

void setup() {
  // put your setup code here, to run once:
pinMode(A0,INPUT_PULLUP);
analogReadResolution(10);
}

void loop() {
  // put your main code here, to run repeatedly:
int resistor=analogRead(A0);
Serial.print("resistor : ");
Serial.println(resistor);
delay(100);
}
resistor : 60
resistor : 62
resistor : 60
resistor : 60
resistor : 62
resistor : 63
resistor : 61
resistor : 61
resistor : 62
resistor : 61
resistor : 59
resistor : 61

this seems very very low considering it should be pulled high.
any ideas on what may be going on ?

on another board, the exact same code gives the following:

resistor : 37
resistor : 37
resistor : 41
resistor : 45
resistor : 49
resistor : 60
resistor : 69
resistor : 78
resistor : 88
resistor : 96
resistor : 103
resistor : 107
resistor : 109
resistor : 106
resistor : 98
resistor : 96
resistor : 83
resistor : 74
resistor : 63
resistor : 54
resistor : 46
resistor : 38
resistor : 36

What are you trying to do, measure a resistor? Built-in pullup resistor is far too imprecise for that.

do analog inputs even HAVE pullups? if so, WHY?

@spruce_m00se , INPUT_PULLUP is applicable only to digitalRead(), not to analogRead()

im trying to measure a resistor connected between the analog pin and gnd within a range of a couple 100 points. to determine between several resistors and workout which is connected, the technique works reliably on the UNO.

is this in general or specific to the portenta?

as far I know - it general.
If you need pull-ups for analog pins - you should use external resistors

roger that, I will add an external resistor . thanks,

Note that external resistor will affect the value, readed from the pin

From the documentation:

Source:

It could be useful when an analog signal can switch to high impedance I suppose.

yes, i just had a play around, but thats not too important, i will just ajust the threshold in code accoordingly.
strange that it worked well with the UNO.

see the post 11, I was wrong, it works on Uno

That documentation relates to the "generic" arduino family - eg the uno.
The portenta is a different animal altogether, you need to look at the documentation specific to that board.

If they DO have pull-ups you certainly can not rely on the value of resistance as a "standard" against which to measure an external resistance.

2 Likes

May I disagree, analogread for portenta will setup the GPIO pin from the STM32H747 in Analog mode and the datasheet is clear on the fact that the pull up and down resistors are disabled in analog mode (see picture below)


And the Arduino PCB for the Portenta let me believes that no additional resistors were setup. So I don't think this documentation applies to the Portenta?

2 Likes

can you give the link please?

[

RM0399 Reference manual - STMicroelectronics

https://www.st.com › resource › reference_manual
](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwiLiYb_wN_5AhWxzYUKHblsCQEQFnoECBIQAQ&url=https%3A%2F%2Fwww.st.com%2Fresource%2Fen%2Freference_manual%2Frm0399-stm32h745755-and-stm32h747757-advanced-armbased-32bit-mcus-stmicroelectronics.pdf&usg=AOvVaw2zPe-BwFieZ6iJWIE9dDw4)

Or just write RM0399 on google you should get it, it s quite the datasheet so good luck reading it ^^

well from what im seeing today, the pullups are also junk on the digital pins, ive got digital 10 set as INPUT_PULLUP and its still reading low on digitalRead.

pffff

guys, this portenta is driving me insane. Im working through some errors which were solved with pullups as mentioned above.
now with the following test code, i get the following result.

void setup() {
  // put your setup code here, to run once:
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  pinMode(A0, INPUT_PULLUP);

  analogReadResolution(10);
}

void loop() {
  // put your main code here, to run repeatedly:
  int a1 = digitalRead(A1);
  Serial.print("A1 : ");
  Serial.println(a1);
  delay(1000);
  int a2 = digitalRead(A2);
  Serial.print("A2 : ");
  Serial.println(a2);
  delay(1000);
  int a3 = digitalRead(A3);
  Serial.print("A3 : ");
  Serial.println(a3);
  delay(1000);
  int a0 = digitalRead(A0);
  Serial.print("A0 : ");
  Serial.println(a0);
  delay(1000);
}

A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0
A2 : 1
A3 : 1
A0 : 1
A1 : 0

the pins are all on a naked portenta, nothing connected, pullups, albeit weak activated.  the output from terminal is stable, never fluctuates. ive given plenty of time for the ADC to recover between reads. 

it doesnt matter what read order i put the pins in, its always A1 giving the error. 

even if I give it a 100k pullup to the 5V pin of the portenta, it does exactly the same,  I am considering flushing the portentas I have down the toilet . 

can anyone help me not waste a couple of hundred dollars?

can anyone confirm the info given in the answer in this link RE: not using a1-3 as digital inputs?