Simple ESP to ESP reading blink program not reading input voltage

One ESP32's 3v3 is connected to GPIO 26 of another ESP32. The program is uploaded. The built-in LED lights for two seconds as expected. Then, it turns off. No matter what GPIO pin the 3v3 is connected to (besides 2), the LED remains off.

/*
 * ON Board LED GPIO 2
 */

#define LED 2
#define inPin 26

void setup()
{
  Serial.begin(9600);
  // Pins 34, 35, 36, 39 are input only
  pinMode(LED, OUTPUT);

  // Sanity check LED works
  digitalWrite(LED, HIGH);
  delay(2000);
}

void loop()
{
  Serial.println(digitalRead(inPin));
  digitalWrite(LED, digitalRead(inPin));
}

Any reason this is happening?

And the GND's of these ESP32's are connected ?

Deva_Rishi:
And the GND's of these ESP32's are connected ?

Yes.

Simply trying to turn LED on/off if external voltage occurs at any GPIO pin (e.g., 26).

I think that the built in led on pin 2 turns on when set LOW.

digitalWrite(LED, !digitalRead(inPin));

cattledog:
I think that the built in led on pin 2 turns on when set LOW.

It always reads low no matter what.

With that not-statement, it is just always on.

Are you saying that the digitalRead() of the inPin is always LOW even when 3.3V is applied?

cattledog:
Are you saying that the digitalRead() of the inPin is always LOW even when 3.3V is applied?

Yes.

Where is inPin set as input?

 gpio_config_t io_cfg = {}; // initialize the gpio configuration structure
  io_cfg.mode = GPIO_MODE_INPUT; // set gpio mode. GPIO_NUM_0 input from water level sensor
  io_cfg.pin_bit_mask = ( (1ULL << GPIO_NUM_26)); //bit mask of the pins to set, assign gpio number to be configured

would set pin 26 to input

and

 io_cfg = {};
  io_cfg.mode = GPIO_MODE_OUTPUT;
  io_cfg.pin_bit_mask = ( 1ULL << GPIO_NUM_2 ); //bit mask of the pins to set, assign gpio number to be configured
  gpio_config(&io_cfg);
  gpio_set_level( GPIO_NUM_4, LOW); // deenergize relay module

and this will set gpio 2 as output.

Idahowalker:
Where is inPin set as input?

Arduino GPIO automatically set as inputs, so I assume the same is true for ESP32.

Cattledog has a good point

  pinMode(LED, OUTPUT);

  // Sanity check LED works
  digitalWrite(LED, HIGH);
  delay(2000);

This switches the output on and turns off the LED straight away. Then it should stay off as-long as you apply 3.3v, and once you ground the pin, the LED should turn 'on' The builtin LED is 'active-low'

Arduino GPIO automatically set as inputs, so I assume the same is true for ESP32.

Yes it is, but you actually would want to set it INPUT and with have a pulldown resistor, since you want to test if it responds to 3.3v

Very confused now.

I put
pinMode(26, INPUT_PULLUP);
in setup(). Always "1" or high now.

adamelli:
Very confused now.

I put
pinMode(26, INPUT_PULLUP);
in setup(). Always "1" or high now.

Until you connect the pin to GND.

adamelli:
Arduino GPIO automatically set as inputs, so I assume the same is true for ESP32.

I've not read that in the ESP32 API.

Idahowalker:
I've not read that in the ESP32 API.

That was it. Thanks.

#define LED 2 // ON Board LED GPIO 2
#define inPin 26

void setup()
{
  Serial.begin(9600);
  // Pins 34, 35, 36, 39 are input only
  pinMode(LED, OUTPUT);
  pinMode(inPin, INPUT); // <----------
}

void loop()
{
  Serial.println(digitalRead(inPin));
  digitalWrite(LED, digitalRead(inPin));
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.