Go Down

Topic: Simple ESP to ESP reading blink program not reading input voltage (Read 89 times) previous topic - next topic

adamelli

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.

Code: [Select]
/*
 * 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?

Deva_Rishi

To 'Correct' you have to be Correct. (and not be condescending..)

adamelli

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).

cattledog

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

Code: [Select]
digitalWrite(LED, !digitalRead(inPin));

adamelli

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.

cattledog

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


adamelli

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


Yes.

Idahowalker

1/18/2018, got my first Arduino Uno.

Idahowalker

Code: [Select]
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
Code: [Select]

 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.
1/18/2018, got my first Arduino Uno.

adamelli

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

Deva_Rishi

Cattledog has a good point
Code: [Select]
  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' 
Quote
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
To 'Correct' you have to be Correct. (and not be condescending..)

adamelli

Very confused now.

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

Deva_Rishi

Very confused now.

I put   
pinMode(26, INPUT_PULLUP);
in setup(). Always "1" or high now.
Until you connect the pin to GND.
To 'Correct' you have to be Correct. (and not be condescending..)

Idahowalker

Arduino GPIO automatically set as inputs, so I assume the same is true for ESP32.
I've not read that in the ESP32 API.

1/18/2018, got my first Arduino Uno.

adamelli

I've not read that in the ESP32 API.
That was it. Thanks.

Code: [Select]

#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));
}

Go Up