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
The INPUT_PULLDOWN mode was introduced in Arduino IDE 1.0.1 (released in 2012), but it was not supported on all microcontrollers initially.

Details:​

  • Arduino AVR (ATmega-based boards like Uno, Nano) does not support INPUT_PULLDOWN in hardware, as these chips only have built-in pull-up resistors (INPUT_PULLUP).
  • ARM-based Arduinos (e.g., Due, Zero) and ESP8266/ESP32 support INPUT_PULLDOWN from their initial integration into Arduino IDE.
  • In Arduino SAMD Core (for boards like MKR, Nano 33 IoT) and ESP8266/ESP32 Core, this mode has been available since their first supported versions in the IDE.
 
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
Since the **ESP32** family was officially supported in Arduino IDE (around **2018**), several new **MCU-specific functions and features** have been added to the IDE to support modern microcontrollers. Here are some notable additions:

---

### **1. ESP32-Specific Features (espressif/arduino-esp32)**
- **Dual-Core Support**
- `xTaskCreatePinnedToCore()` – Run FreeRTOS tasks on a specific core.
- `ARDUINO_RUNNING_CORE` – Macro to detect the current core.
- **WiFi & Bluetooth**
- `WiFi.mode(WIFI_MODE_APSTA)` – Simultaneous AP + Station mode.
- `BT.begin()` – Bluetooth Classic & BLE support.
- **Deep Sleep & Low Power**
- `esp_sleep_enable_timer_wakeup()` – Wake up after a delay.
- `esp_deep_sleep_start()` – Ultra-low-power sleep modes.
- **Peripheral Enhancements**
- **DAC (Digital-to-Analog)** – `dacWrite()` for analog output.
- **Touch Pins** – `touchRead(pin)` for capacitive sensing.
- **Hall Effect Sensor** – `hallRead()` for built-in magnetic sensing.
- **File System & NVS (Non-Volatile Storage)**
- `SPIFFS` & `LittleFS` – File system support.
- `Preferences` – Key-value storage (replaces EEPROM).

---

### **2. RP2040 (Raspberry Pi Pico) Support**
- **Dual-Core Processing**
- `setup1()` & `loop1()` – Second core execution.
- **PIO (Programmable I/O) Support**
- Allows custom state machines for bit-banging protocols.
- **Improved ADC & PWM**
- Higher resolution (12-bit ADC, 16-bit PWM).

---

### **3. STM32 (STM32duino) Enhancements**
- **Hardware-Specific Timers**
- `HardwareTimer` – Advanced PWM & interrupt control.
- **True Analog Output**
- `analogWrite()` with real DAC on supported pins.
- **Low-Power Modes**
- `LowPower.sleep()` – Multiple sleep modes.

---

### **4. ESP8266 Updates (earlier but still evolving)**
- **WiFi Improvements**
- `WiFi.softAP()` – Better access point control.
- **Over-the-Air (OTA) Updates**
- `ArduinoOTA` – Wireless firmware flashing.

---

### **5. General Arduino IDE Improvements**
- **Better Multi-Board Support**
- **Arduino CLI** – Command-line tool for managing cores.
- **New Library Manager**
- Easier installation of MCU-specific libraries.
- **Debugging Support**
- **Arduino IDE 2.0+** – Basic debugging for some ARM & ESP32 boards.

---

### **Conclusion**
Since ESP32 support was added, Arduino IDE has expanded to include **multi-core processing, advanced wireless features (WiFi/BLE), low-power modes, and better peripheral control** for modern MCUs like ESP32, RP2040, and STM32.
 
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.
1753435778789.png


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
View attachment 165587

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() {

}



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

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
Top