0

I am using the Arduino IDE version 1.8.8 I am trying to control an ESP32-wroom. The gpios for pins 16 and 17 are working. I have some relays on GPIO's 18 and 19 that I'd also like to be able to control. I also have no control over GPIO's that are over 17 I've tried 18 through 27 and I can't toggle them.

#define relayPin3 18
#define relayPin4 19


int relayflag = 0;
void loop() {
  delay(1000);
  if (relayflag == 0){
    digitalWrite(relayPin3, LOW);
    digitalWrite(relayPin4, HIGH);   
    relayflag =1;
  }
  else
  {
    digitalWrite(relayPin3, HIGH);
    digitalWrite(relayPin4, LOW);
    relayflag = 0;
  }

}

I noticed that GPIO's 18 and 19 are also shared with spi ports.

Does the digitalWrite command work for any GPIO or is it in use by another library? Is there some other command to get access to the GPIO's I need to use? Some library I need to modify.

enter image description here

3

Found the answer, albeit a simple one. This is my first go around with arudino so it will look ridiculous to those who program microprocessors (including myself)

You need to declare the pin to be an output before use. The inconsistent thing is, this only happens sometimes. For some of the pins you don't need to use pinMode for them to work.

  pinMode(relayPin1, OUTPUT);
| improve this answer | |
  • We all have to start somewhere in learning new things. Well done posting your solution. – Duncan C Mar 4 '19 at 12:05
  • If you don’t set a pin’s mode, the results are undefined. It might already be in the mode you want, and might not. – Duncan C Mar 4 '19 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.