Author Topic: [Solved] High Impedance GPIO Input With Level Shifting  (Read 577 times)

Giaime and 1 Guest are viewing this topic.

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 16
  • Country: il
[Solved] High Impedance GPIO Input With Level Shifting
« on: June 25, 2024, 08:17:41 pm »
Hey all,

I hope I'm using the correct terminology in the title...
I'm working on a project for remotely controlling my home AC by intercepting the IR signals from the remote control, parsing it to understand the current settings, and retransmitting a signal to the AC so the setting will be applied.
My current issue is that the power button of the remote is only to toggle the AC power and so I don't know, at a given point in time, if the AC is surely on or not.

I was thinking of checking the LEDs of the control board to figure that out. It has two LEDs, one red for off and another green for on. The LEDs are connected to a 5v rail and are sink-driven by the existing controller. I want to read the level of this line taking in consideration that my MCU is 3.3v while the existing controller is 5v. My initial thought was to use a voltage divider to bring the 5v (when the LED is off) to 3.3v and read that from a GPIO but that would essentially mean I'm pulling down the line, no?
Would just using high resistor values be good enough here or is there a better solution to get the logic level?

Thanks in advance!
« Last Edit: June 29, 2024, 09:00:40 pm by shmuelzon »
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: ca
Re: High Impedance GPIO Input With Level Shifting
« Reply #1 on: June 25, 2024, 08:55:24 pm »
You should be fine with just the voltage divider. Temporarily tack one onto one of the existing LED IO lines to be 100% sure.

Another idea worth exploring: Some remote protocols also include "power-on" and "power-off" codes in addition to the "power toggle" code even though they're unused by the remote.
« Last Edit: June 25, 2024, 09:00:26 pm by Kim Christensen »
 

Online ArdWar

  • Frequent Contributor
  • **
  • Posts: 529
  • Country: sc
Re: High Impedance GPIO Input With Level Shifting
« Reply #2 on: June 26, 2024, 12:30:29 am »
Divider is fine. Assuming the LED is only indicator and not a cursed multiplexing of input functions. You just need themt to be large enough values not to visibly turn on the LED.
Depending on your MCU and its input structure, it might even be 5V tolerant and will be fine with only a single resistor.
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 16
  • Country: il
Re: High Impedance GPIO Input With Level Shifting
« Reply #3 on: June 29, 2024, 09:00:02 pm »
Thank you both! I ended up using a voltage divider with 10k+15k resistors and it seems to do the job just fine.

My MCU is an ESP32 and, AFAIK, isn't 5v tolerant so I needed to take this approach.

The only odd thing I noticed is that when the LED is off, that rail is indeed 5v (before the divider) but, when it's on it's at ~3v and not the zero/GND I was expecting. It's still below the logic high minimum voltage threshold of my GPIO so it works OK (using an internal pull-down). I just hope it stays OK :)
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: ca
Re: High Impedance GPIO Input With Level Shifting
« Reply #4 on: June 29, 2024, 09:43:03 pm »
The only odd thing I noticed is that when the LED is off, that rail is indeed 5v (before the divider) but, when it's on it's at ~3v and not the zero/GND I was expecting.

 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6071
  • Country: es
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #5 on: June 29, 2024, 10:26:26 pm »
Or just a diode:
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 16
  • Country: il
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #6 on: June 30, 2024, 07:32:19 am »
Hey,

Please see attached where I connected my line to detect the LED status.
The lower trace is the 5V line which I also use to power the ESP32 and the wire in blue is connected to the voltage divider.

I think I have it connected correctly...

Thanks!
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: ca
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #7 on: June 30, 2024, 03:26:30 pm »
Connect the blue wire to the other side of R13 after verifying that point toggles between 0V & 5V when the LED goes off/on.
 

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 16
  • Country: il
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #8 on: July 01, 2024, 08:13:54 pm »
I think R12 is the resistor for the LED I'm connecting to. R13 is for the other LED color in that dual LED thing. The controller is already installed so I can only try this if/when something fails and I need to take it down.
Could you please explain why I would see a different voltage before and after the resistor in this case? I'm especially confused by the fact that when it's off, I measure 5v but when it's on I measure 3v and not the zero I expected. Why would that be different before the resistor?

Thanks for putting up with my ignorance :)
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: ca
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #9 on: July 01, 2024, 08:43:26 pm »
I think R12 is the resistor for the LED I'm connecting to. R13 is for the other LED color in that dual LED thing.

Ah yes, you are correct. I see it now.
Connect the blue wire to the other side of R12 after verifying that point toggles between 0V & 5V when the LED goes off/on.

Thanks for putting up with my ignorance  ;D

Quote
Why would that be different before the resistor?

Because the resistor drops voltage across it when current flows through it. That's how the LED current is limited.
 
The following users thanked this post: shmuelzon

Offline shmuelzonTopic starter

  • Contributor
  • Posts: 16
  • Country: il
Re: [Solved] High Impedance GPIO Input With Level Shifting
« Reply #10 on: July 08, 2024, 11:50:05 am »
Hey,

I finally got around to dismantling it and probe the point after the resistor and can confirm what you've described. It measured at 0.1v which, I guess, is expected and close enough.

Thanks again!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf