How to set GPIO as a input and output

To what?
What does the application do?
What are its inputs and outputs?
Please be more specific.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

This time around, I'm out for good. You're on my ignore list.

2 Likes

To digitalize legacy machines

  1. What legacy engines and why do you need the pin to be INPUT and OUTPUT, change mode?
  2. What sort of output do the "Legacy machine provide?
  3. Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

no

long way ahead until it will really work

If you want to use a GPIO as input and as output at the same time you have to
open the plastic covering of the ESP32-chip
and connect the input-gate with a 5ยตm thin goldwire with the source of the output MOSFET.
:wink: :slightly_smiling_face: :grinning: :smiley: :smile: :grin: :laughing: :rofl:

A post was split to a new topic: Digitalize legacy machine

It's possible but dangerous. The AVR PINx registers show the (external) pin state, while PORTx registers show the intended output state. If both differ and the output is enabled then either end of the line may release the magic smoke.

1 Like

FYR,
Arduino UNO
The tricky thing is not programming. It is how to do the circuit design, read and write in the same pin, and consider leak current when pressing the button switch.

Concept

  1. Input mode is "INPUT."
    When we press the button switch, the controller can still drive the final element to continue controlling output.
  2. Read the input value at intervals
    referring to my example, a controller keeps reading input every 10 microseconds.
  3. Loop drives the output
    Coding design depends on the application. Maybe we need to continue running, toggling, ramping, etc.

Project: InOutInOun (IOIO) project
The objective is to see the led status when pressing the pushbutton on the ON and OFF states I call hold last value.

STATE: ON

STATE: OFF

What the controller work is toggle LED on/off every second,

  1. when led ON, IF I press the push button, the led will stay ON.

  1. when led OFF, IF I press the push button, the led will stay OFF.

Result

The above picture shows the current leak's result of 10-20 ฮผA (300-350 mV) when pressing a button. It is only done on a tinkercad simulator :sweat_smile:.

The below code for reference,

#define ioPin 12                            // Define Input/Output Pin

MicroBeaut_Trigger trigger;                 // Read Input Trigger Function
const float intervalReadInput = 0.010;      // Read Input Interval = 10 milliseconds
bool inputState;                            // Input State

MicroBeaut_Blink  blinkOutput;	            // Blink Function for RED and Green LEDs
bool outputState = false;                   // Output State

MicroBeaut_Blink  ledBuiltin;               // Blink Function for LED_BUILTIN
bool builtinState;                          // State for LED_BUILTIN

const float blinkDelay = 1.0;               // Time Delay 1.0 second

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);             // Set Pin to OUTPUT Mode
  pinMode(ioPin, OUTPUT);                   // Set Pins to Output Mode
  digitalWrite(ioPin, outputState);         // ON/OFF LEDs
  trigger.SetTimeDelay(intervalReadInput);  // Initial Trigger Time
}

void loop() {
  if (trigger.Trigger(true)) {
    pinMode(ioPin, INPUT);                  // Set Pins to Input Mode
    inputState = digitalRead(ioPin);        // Read Input State (1 = Press, 0 = Release)
    pinMode(ioPin, OUTPUT);                 // Set Pins to Output Mode
  }

  outputState = blinkOutput.Blink(!inputState, blinkDelay); // Get State from Blink Function
  digitalWrite(ioPin, outputState);                         // ON/OFF LEDs

  builtinState = ledBuiltin.Blink(true, blinkDelay);        // Get State from Blink Function
  digitalWrite(LED_BUILTIN, builtinState);                  // ON/OFF LED_BUILTIN
}

Please do not attach your request to an existing thread, it is considered "hijacking". Please start a new one.

1 Like

Thanks, I'll be careful about this. :sweat_smile:

Thanks. What is your programming question?

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