Simulate wired momentary switch functions using ESP32 DEV KIT

Hello,

I have a micro controller device with 6 buttons (momentary switches showing HIGH state) wired through RJ45 with 6 pins active (actually 7 including LED wire).

I want to simulate the physical switches using ESP32 DEV KIT GPIOpins wired to the RJ45 port of the micro controller device and issue commands through serial bluetooth.

For instance when I press button0 or button1 a 2.4v signal goes LOW until released. I found it interesting that all the other button fuctions read 3.4V before going LOW. 4 of the buttons have dual functions depending on duration button is pressed for a total 10 functions for all 6 buttons. For example press <=1sec for ON, >=2 sec for OFF

My concerns are 1) I don’t want to short GPIO pins destroy my ESP32 and 2) I don’t want to set the pin as OUTPUT and cause voltage spike to my parastep micro controller??

Any chance someone could please take a glance at my code and tell me if I am on the right track?

HERE IS MY CODE SO FAR…

// assign variables
// BLUETOOTH 
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;


// *** PARASTEP PINS -> ESP32 GPIO PINS ***
// bluePin1 = unused
int orangePin2 = 25;
int blackPin3 = 26;
// redPin4 = unassigned (LED)
int greenPin5 = 22;
int yellowPin6 = 21;
int brownPin7 = 17;
int grayPin8 = 16; 

// *** BUTTON DEFINITIONS FOR BLUETOOTH COMMAND STRING ***
int button0 = 0; // parastep sit/OFF 2,3 (orangePin2,blackPin3) <=> 2 sec pulse
int button1 = 1; // parastep stand/ON 2,3 (orangePin2,blackPin3) <= 1 sec pulse

int button2 = 2; // parastep left step 5,8 (greenPin5,grayPin8) <= 1 sec pulse
int button3 = 3; // parastep right step 3,8 (blackPin3,grayPin8) <= 1 sec pulse

int button4 = 4; // parastep increase +left quad 5,6 (greenPin5,yellowPin6) <= 1 sec pulse
int button5 = 5; // parastep increase +right quad 3,6 (blackPin3,yellowPin6) <= 1 sec pulse 

int button6 = 6; // parastep increase +left glute 5,6 (greenPin5,yellowPin6) <=> 3 sec pulse
int button7 = 7; // parastep increase +right glute 3,6 (blackPin3,yellowPin6) <=> 3 sec pulse

int button8 = 8; // parastep decrease -left and -right quad 7,8 (brownPin7,grayPin8) <= 1 sec pulse
int button9 = 9; // parastep decrease -left and -right glute 7,8 (brownPin7,grayPin8) <=> 3 sec pulse


int buttonCmd = 999; // used to store string from bluetooth app (0-9)

void setup() {
// put your setup code here, to run once:

//*** Bluetooth ***
 Serial.begin(115200);
 SerialBT.begin("ESP32test"); //Bluetooth device name
 Serial.println("The device started, now you can pair it with bluetooth!");

//*** set pins as inputs ***
 pinMode(orangePin2, INPUT_PULLUP);
 pinMode(blackPin3, INPUT_PULLUP); 
 pinMode(greenPin5, INPUT_PULLUP);
 pinMode(yellowPin6, INPUT_PULLUP);
 pinMode(brownPin7, INPUT_PULLUP);
 pinMode(grayPin8, INPUT_PULLUP);


}
void loop() {
 // put your main code here, to run repeatedly:

 // get string from bluetooth serial

 if (Serial.available()) {
   SerialBT.write(Serial.read());
   buttonCmd = SerialBT.read();
 }

 switch (buttonCmd) {
   case 0:
     // statements
     // parastep sit/OFF 2,3 (orangePin2,blackPin3) <=> 2 sec pulse
     if(digitalRead(orangePin2) == HIGH and digitalRead(blackPin3) == HIGH){

      digitalWrite(orangePin2, LOW);
      digitalWrite(blackPin3, LOW);
      
//       delay (2sec);  // 2 sec pulse 

      digitalWrite(orangePin2, HIGH);
      digitalWrite(blackPin3, HIGH);    
 
     }
     break;
  case 1:
  // parastep stand/ON 2,3 (orangePin2,blackPin3) <= 1 sec pulse
  if(digitalRead(orangePin2) == HIGH and digitalRead(blackPin3) == HIGH){

      // set pins LOW to simulate pushing button
      digitalWrite(orangePin2, LOW);
      digitalWrite(blackPin3, LOW);
      
//       delay (1sec);  // 1 sec pulse

      digitalWrite(orangePin2, HIGH);
      digitalWrite(blackPin3, HIGH);    
 
   }
   
   break;
   // .. switch case continued for all remaining buttons
   
 default:
   // statements
   break;
}

buttonCmd = 999;

} //end main loop
 pinMode = (orangePin2, INPUT);
 pinMode = (blackPin3, INPUT);
 pinMode = (greenPin5, INPUT);
 pinMode = (yellowPin6, INPUT);
 pinMode = (brownPin7, INPUT);
 pinMode = (grayPin8, INPUT);

Right track?
No.
But the compiler already told you that.

Take a look at some of the examples provided in the IDE

Please remember to use code tags when posting code.

I’m very new and need to understand the general concept of using GPIO pins. I know it won’t compile. I’ve searched for examples with no success so please enlighten me if this following is even possible? The delay # sec was just for an example

switch (buttonCmd) {
  case 0:
    // statements
    // parastep sit/OFF 2,3 (orangePin2,blackPin3) <=> 2 sec pulse
    if(digitalRead(orangePin2) == HIGH and digitalRead(blackPin3) == HIGH){

     digitalWrite(orangePin2, LOW);
     digitalWrite(blackPin3, LOW);
    
     delay (2sec);  // 2 sec pulse

     digitalWrite(orangePin2, HIGH)
     digitalWrite(blackPin3, HIGH)    

    }

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select “more” and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.

The code compiles now after I removed “=” from pinmode function and removed NULL. Thanks for setting me straight on code tag.

I still am unsure about logic I used to simulate switch?

TheMemberFormerlyKnownAsAWOL:

 pinMode = (orangePin2, INPUT);

pinMode = (blackPin3, INPUT);
pinMode = (greenPin5, INPUT);
pinMode = (yellowPin6, INPUT);
pinMode = (brownPin7, INPUT);
pinMode = (grayPin8, INPUT);



Right track?
No.
But the compiler already told you that.

Take a look at some of the examples provided in the IDE

Please remember to use code tags when posting code.
[/quote I was asking about logic not syntax

I was asking about logic not syntax

That was not mentioned.

TheMemberFormerlyKnownAsAWOL:
That was not mentioned.

My concerns are 1) I don't want to short GPIO pins destroy my ESP32 and 2) I don't want to set the pin as OUTPUT and cause voltage spike to my parastep micro controller??