I would be driving input pins of a Lolin D1 Mini from 5V Arduino Pro Mini GPIO pins. The Lolin inputs will have pullup resistors to 3.3V enabled. It seems to me that I can switch the Pro Mini GPIOs between INPUT mode and OUTPUT mode as a form of voltage translation. INPUT would produce 3.3V on a line, and OUTPUT would produce ground. But that would depend on the IDE not doing anything funny to the output value when switching the mode. Perplexity tells me I should not rely on this because I might program it wrong. Well, yeah, but if I don't program it wrong, is there any reason I can't rely on this? If it matters, this would be for a personal hobby project, but I'd also like to know for future reference whether this is ok.
The output level (VOL, VOH) of a DPin depends on the load connected. Load shoud be such that specs of VOH and sin/source current are not violated.
I've seen a Software I2C library for AVR do that.
You can look at the source code for pinMode() to determine that. You could also bypass pinMode and use the processor's instructions to do it yourself.
Changing a GPIO pin to INPUT does not put a voltage on the pin. It makes the pin high impedance or floating with a variable voltage level.
Use a voltage divider, R1 = 2.2k, R2 = 3.3k.
3.3 / 5.5 * 5 = 3.
No, but having a pullup resistor on that GPIO does.
Here it is. Looks like for OUTPUT mode (the final 'else' ) it only changes the direction register, which is what I would expect.
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg, *out;
if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
out = portOutputRegister(port);
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out &= ~bit;
SREG = oldSREG;
} else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
}
Well, since the ESP8266 will have pullup resistors enabled, I think I would just need a diode - so the Pro Mini can bring the line low, but can't take it to 5V. But I would like to avoid using diodes or dividers if they aren't needed.
I guess one thing I need to check is whether the Pro Mini pins involved ever go high during an entire flashing process, and during boot. My memory is that some GPIO pins go high briefly. Well, D13 of course, but other than that.
Wouldn't the ESP input be seeing the diode's 0.7V barrier potential instead of zero volts?
Yes it would. Per the ESP8266 datasheet, the maximum for VIL is 0.825V at Vcc = 3.3V. So 0.7V should be detected as LOW.
Gee, I would think that after having read more than 64 thousand post here on the forum that you would know by now that connecting 5V signals to a 3.3V only processor is a big NO NO.
My memory was right. During a boot of the Pro Mini, the following pins go to 5V for about 1ms: D8 - D12, A0-A1. And D13, which drives the builtin LED, goes high for much longer, several times.
So I guess Perplexity was right. In theory this works, but only if you remember which pins it works for and which it doesn't.
Of couse I do know that. The whole point of the post was about making sure I didn't send a 5V signal to a 3.3V processor.
I Know you must have seen this response hundreds of times, "use a voltage translator or a voltage divider."
You continue to ignore my original question. Perhaps your time would be better spent helping someone else.
Yes, I'm totally misunderstanding what you are trying to do. I will let @GolamMostafa explain it all to you.
I tested that idea a while ago, results are here.
Then there is further discussion about how it could cause damage if a code error set the pin to output mode when it should be input.
I remember that, the OP wound up using a one transistor voltage translator just to be safe.
Oh sorry, ignore my last post, I'm not supposed to be provide any further help.
Does switching pinMode from INPUT to OUTPUT produce reliable output LOW?
No! It depends on what is connected to the pin, if it is just a volt meter and pull ups are on it should go high. If you have written a 1 to the pin it will go high. Conversely if you have written a low it will go low. Also important is if there is a load connected to the pin. For example if it is grounded it will not go high and if a high is written to it and it is placed in output mode you will stress or damage the port. I cannot give an exact answer as you have not posted a schematic.
I have only understood from #1 of OP that he has connected an output line of a 5V-Pro Mini with an input line (internal pull-up active) of a 3.3V-Lolin D1.
What does he want to achieve and what is the problem he is facing? Does he physically connected the two devices together?
OP needs level shifters to connect 5V-Pro Mini with 3.3V-Lolin D1; else, one or both devices might be damaged.