B4R Question INPUT_PULLDOWN - impossible ?

hatzisn

Expert
Licensed User
Longtime User
In Lolin D1 (ex-WeMos) which is ESP8266 there are some permanent pull up and pull down pins. I can't be sure for ESP32 but it sounds logical that there will be and you just need to find them.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
esp32 is able to use internal pulldown, but strange that B4R did not implement it according to Arduino IDE.
@Erel , forgotten, or maybe some reason ?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Probably because of this explanation Google presents:

"Yes, the Arduino Uno R3, and most other Arduino boards, support pull-down resistors. While Arduino boards often have built-in pull-up resistors, they also allow for the use of external pull-down resistors or even internal pull-down resistors on some boards."

Maybe when B4R was created there were not internal pull down resistor boards.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Maybe when B4R was created there were not internal pull down resistor boards.

Nevertheless it is still implementable with pin number and InLine C.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
 
Upvote 1

hatzisn

Expert
Licensed User
Longtime User
Sorry for the "Solution" click, it was clicked by mistake...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
implementable with pin number and InLine C.


https://wokwi.com:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(1000);
  Serial.println("Hello, ESP32!");
  Serial.print("INPUT_PULLUP = ");
  Serial.println(INPUT_PULLUP);
  Serial.print("INPUT_PULLDOWN = ");
  Serial.println(INPUT_PULLDOWN);
  Serial.print("INPUT = ");
  Serial.println(INPUT);
  Serial.print("OUTPUT = ");
  Serial.println(OUTPUT);
}

void loop() {

}

INPUT_PULLUP = 5
INPUT_PULLDOWN = 9
INPUT = 1
OUTPUT = 3

So,
B4X:
Dim p As Pin
p.Initialize(gpio_num, 9)  'PULLDOWN
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
Most processors have a built-in pull-up resistor so input is always high and you activate with minus. To have the other function you must have an external 10k resistor connected to minus and you can activate with plus.
If a pin is both in and output the built-in resistor must be activated when you initialize the input, this means that the pin is floating until the code is run. This gives you random values, so I always use external resistors on both in and output to make sure I know the state on power up.
 
Last edited:
Upvote 0

hatzisn

Expert
Licensed User
Longtime User

Hi, what board have you used in the simulator (because for ESP8266 in B4R):

(p=Pin)
p.MODE_INPUT = 0
p.MODE_OUTPUT=1
p.MODE_INPUT_PULLUP=2
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
ESP32 classic. So, it seems, each MCU has different constants in the SDK !
Google told that esp8266 does not have INPUT_PULLDOWN.

esp32-c3 also returns:

INPUT_PULLUP = 5
INPUT_PULLDOWN = 9
INPUT = 1
OUTPUT = 3

Arduino Nano board returns:

sketch.ino:9:18: error: 'INPUT_PULLDOWN' was not declared in this scope
Serial.println(INPUT_PULLDOWN);

STM32:
Hello, STM32!
INPUT_PULLUP = 2
INPUT_PULLDOWN = 3
INPUT = 0
OUTPUT = 1
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But the Arduino IDE anyway allows to input "INPUT_PULLDOWN" as a constant, but B4R has it only as a property of the pin object... that must be hardcoded ... it is the reason.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
ESP32 classic. So, it seems, each MCU has different constants in the SDK !
Google told that esp8266 does not have INPUT_PULLDOWN.

esp32-c3 also returns:



Arduino Nano board returns:



STM32:

You are right. I have just confirmed it.

B4X:
    Log(p.MODE_INPUT)
    Log(p.MODE_OUTPUT)
    Log(p.MODE_INPUT_PULLUP)

Results in the following in Lolin D32:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…