# Two control signals one GPIO

**URL:** <https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080>\
**Category:** General Electronics\
**Created:** [March 3, 2024, 12:56pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080 "2024-03-03T12:56:56Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 3, 2024, 12:56pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/1 "2024-03-03T12:56:56Z")

</div>

I have two active low signals (`CHRG` and `STDBY`) from a single li-ion battery charger IC TP4056 [Datasheet](https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/TP4056.pdf).

`CHRG` is high impedance when charging is not taking place and Low when charging is taking place  
`STDBY` is high impedance when charging is not complete and low when charging is complete.

I am using this IC within an embedded circuit controlled by ESP32, but I only have one GPIO left and I want to detect whether charging is taking place and if the battery is fully charged.  
Kindly suggest some solutions  
ESP32 logic signals are 3.3V

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 3, 2024, 1:09pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/2 "2024-03-03T13:09:16Z")

</div>

> [@hrithik254](#):
>
> is high impedance

Do you really mean high impedance or are you referring to a logic level HIGH?

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 3, 2024, 1:18pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/3 "2024-03-03T13:18:25Z")

</div>

high impedance not logic high. attaching the pin description for your reference:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/d/0/c/d0c14c3a02a381116734b3c6d5272bc0a3595d3f.png)  
_Datasheet Picture above_

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 3, 2024, 1:28pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/4 "2024-03-03T13:28:06Z")

</div>

So, I have attached a pullup, this way now the `CHRG` is low when batt is charging and high otherwise, and `STDBY` is low when the battery is fully charged and high otherwise.  
So using this can anyone suggest a solution?

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [March 3, 2024, 1:40pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/5 "2024-03-03T13:40:41Z")

</div>

Please, post a picture of your ESP32 Dev Board.

---

<div class="post-metadata">

**Author:** ![hmeijdam](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hmeijdam/32/218564_2.png) [@hmeijdam](https://forum.arduino.cc/u/hmeijdam)\
**Post date:** [March 3, 2024, 3:06pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/6 "2024-03-03T15:06:30Z")

</div>

How about creating a voltage divider and connect the single GPIO pin to the ADC and sample the voltage.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/5/8/0/58025801f8ac4684c1a6fb0281a6efe9674daf2c.jpeg)

If both are at the high impedance state voltage will be VCC  
if CHRG gets low, the voltage will be pulled to 66%VCC  
if STDBY gets low the voltage will be pulled to 50% VCC

In case it's needed, if both get low it will be pulled further down, below 50% of VCC.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 3, 2024, 3:17pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/7 "2024-03-03T15:17:37Z")

</div>

so with the pull-ups that's that status of your pins

| | LOW | HIGH |
| --- | --- | --- |
| CHRG | **Charging** | Not Charging |
| STDBY | **Complete** | Not Complete |

You want to detect whether charging is taking place and if the battery is fully charged.

Another way to represent this is

| CHRG | STDBY | state |
| --- | --- | --- |
| LOW | LOW | impossible (can't be both charging and complete) |
| LOW | HIGH | Charging, not fully charged |
| HIGH | LOW | Not Charging, fully charged |
| HIGH | HIGH | impossible (can't be both not charging and not complete) |

so if the components can **never** be in the impossible situation then just looking at one of them you'll know what's the status.

eg if CHRG is LOW then you know it's Charging, not fully charged and if CHRG is HIGH then you know it's Not Charging which means fully charged

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [March 3, 2024, 3:44pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/8 "2024-03-03T15:44:51Z")

</div>

> [@J-M-L](#):
>
> Another way to represent this is
> 
> | CHRG | STDBY | state |
> | --- | --- | --- |
> | LOW | LOW | impossible (can't be both charging and complete) |
> | LOW | HIGH | Charging, not fully charged |
> | HIGH | LOW | Not Charging, fully charged |
> | HIGH | HIGH | impossible (can't be both not charging and not complete) |

Low Low is possible if the battery is not present, or (I think) if a battery protection function has kicked in.

And depending on what the pullup resistors are connected to, High High could occur if there is no, or insufficient, power coming into the charger.

I think the voltage divider suggestion would work. It would give a different result for all four possibilities.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 3, 2024, 3:46pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/9 "2024-03-03T15:46:42Z")

</div>

> [@ShermanP](#):
>
> Low Low is possible if the battery is not present, or (I think) if a battery protection function has kicked in.
> 
> And depending on what the pullup resistors are connected to, High High could occur if there is no, or insufficient, power coming into the charger.

OK if they are possible then as you can't get 4 possibilities with only 1 bit, you either need 2 bits (2 GPIOs) or indeed move to the analog representation

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [March 3, 2024, 4:01pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/10 "2024-03-03T16:01:16Z")

</div>

Yes, but it depends on what he really needs to know. Will he be doing something different depending on whether the battery is charging or is fully charged? Or does he just need to know that one or the other is true, and that no "impossible" is taking place. In that case a SN74LVC1G86 would work. But as you say, a second GPIO is really the answer if he can find one.

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 4, 2024, 5:24am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/11 "2024-03-04T05:24:02Z")

</div>

I just want to know if charging is taking place or not and if the battery if fully charged

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 4, 2024, 5:24am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/12 "2024-03-04T05:24:55Z")

</div>

This is indeed a way to know. I was trying to make out a solution with a MOSFET. I think I would need to use a PMOS. just need to figure out the configuration

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 4, 2024, 5:25am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/13 "2024-03-04T05:25:32Z")

</div>

This is helpful. Thanks.

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [March 4, 2024, 5:26am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/14 "2024-03-04T05:26:50Z")

</div>

If you have an analog pin free you can use it as a digital I/O.

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 4, 2024, 5:28am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/15 "2024-03-04T05:28:10Z")

</div>

I did not take consideration of the fact that battery not present or faulty would also be one of the states, moreover I also need to take care of low battery State. My circuit contains an LCD which would show all these status i.e.  
Charging  
Fully charged  
Battery fault/ not present  
Low battery

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 4, 2024, 5:43am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/16 "2024-03-04T05:43:54Z")

</div>

can you go for a different MCU with more pins ? Which esp32 are you using?

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [March 4, 2024, 4:05pm UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/17 "2024-03-04T16:05:53Z")

</div>

I dug out my supply of TP4056 modules, and found that when there is no battery present, the charging LED flashes, and the fully-charged LED is on solid. I suspect that behavior may vary from one manufacturer to another.

I have never tried it, but my suspicion is that if the battery discharges to the point that the protection circuit kicks in, it would behave like no battery present. That's because the protection circuit disconnects the negative battery terminal from the circuit ground. But I've never tested it.

My memory from trying to get the TP4056 to work with solar panels is that at certain intermediate voltages both LEDs may light up solid. But that should not happen if you are charging from 5V USB power.

What if you just measure the battery voltage on an ESP32 analog pin through a resistive divider, and show that number on the display. Then the user could draw his own conclusions about the state of the battery. Of course the divider would draw current, which is not ideal.

---

<div class="post-metadata">

**Author:** ![hrithik254](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hrithik254](https://forum.arduino.cc/u/hrithik254)\
**Post date:** [March 6, 2024, 8:31am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/18 "2024-03-06T08:31:02Z")

</div>

no. mcu has to remain same

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 2, 2024, 8:31am UTC](https://forum.arduino.cc/t/two-control-signals-one-gpio/1231080/19 "2024-09-02T08:31:59Z")

</div>

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