logo elektroda
logo elektroda
X
logo elektroda

Which transistor/scaler? - reading data from an electronic caliper

iksrowaj 1638 29
Best answers

How can I interface an ESP32 with a 1.5 V electronic caliper signal and level-shift it to 3.3 V, preferably without signal inversion?

For this caliper, a PNP is not the right choice; a simple low-power NPN such as a 2N3904 or 2N2222 on each line will work, because the caliper uses a one-way clock/data protocol [#19248233][#19249409] If you want a non-inverted signal, a comparator-style solution is better: one reply recommends an LM358 used as a comparator with a threshold of about 0.75 V, set by 3.3 kΩ to +3.3 V and 1 kΩ to GND on the inverting input, and the caliper signal on the non-inverting input [#19248508] The LM393 can also be used, but its open-collector output needs a pull-up resistor [#19249421] The thread also notes that transistor-based circuits can load the caliper battery, so if you want the cleanest result, the comparator approach is the most practical simple solution [#19248754][#19253963]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19246806
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Dear forumers,
    I am making an interface to communicate between ESP32 and an electronic caliper which is powered by a 1.5V battery. The signals coming out of it are also 1.5V.
    I need to build a circuit (preferably on a single transistor) for the ESP to read 3.3V correctly.
    Can I use a PNP instead of an NPN so that the signal is not inverted? Which transistor should I choose? What parameters should I pay attention to?
    Thank you in advance.
    Regards
  • ADVERTISEMENT
  • #2 19246888
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    Write more about how the communication is done, speed etc. A diagram would also be useful.
  • #3 19246932
    krzysiek_krm
    Level 40  
    Posts: 4612
    Help: 716
    Rate: 598
    The best thing to do, however, is probably a logic level converter.
  • #4 19247529
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Such a Chinese one-way protocol for callipers. A clock line and a data line.
    Which transistor/scaler? - reading data from an electronic caliper .
    The shortest pulse is about 6us so about 166kHz.
    Of the converters so far I have found a TXB010*, the one on the BSS138 does not work.
  • #5 19247796
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    clock can be divided on two resistors. The cheapest solution for the data from the caliper to the uC would be a circuit on any op amp set as a comparator with a threshold of about 1/2 of 1.5V.
  • #6 19247835
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    But it's the other way it's supposed to work. From 1.5 to 3.3V.
  • ADVERTISEMENT
  • #7 19247845
    krzysiek_krm
    Level 40  
    Posts: 4612
    Help: 716
    Rate: 598
    iksrowaj wrote:
    But it is supposed to work the other way. From 1.5 to 3.3V.
    .
    And it will
    pawlik118 wrote:
    set as a comparator with a threshold of about 1/2 from 1.5V

    The caliper transmits in 1.5V logic, i.e. for L it is under the threshold and for H over the threshold (of the comparator).
    pawlik118 wrote:
    circuit on any op amp set as comparator
    .
    Using an op amp as a comparator is a poor idea - the amp has some things that are not needed for anything in a comparator, such as compensation.
  • #9 19247966
    krzysiek_krm
    Level 40  
    Posts: 4612
    Help: 716
    Rate: 598
    iksrowaj wrote:
    I conclude, however, to look for some converter.
    Should such a Pololu 2595 be able to do it?
    https://www.pololu.com/product/2595
    .
    From the manufacturer's description it looks like it should work, although it's not really clear what transistors they used there, if it were known you could look at the DS.
  • #10 19247981
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Which transistor/scaler? - reading data from an electronic caliper There are XBs or X8s on the transistor, I am looking but cannot find one. It's some sort of double and I'd love to know what it is, as I wouldn't want to solder off the board and solder into my project.
  • #11 19248233
    Anonymous
    Level 1  
  • #12 19248321
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    clock generates the caliper? or the procec which is the master?
    Of course you can use a converter, but does it make financial sense since an LM358 for 50gr will also ensure correct operation.
  • #13 19248327
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    I would like to have a non-inverted signal, hence the PNP question.

    Added after 4 [minutes]: .

    The clock signal is generated by the caliper.
    How to connect this LM385? Any link?
    Greetings
  • #14 19248508
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    To the (-) input of the LM358 connect: 3.3k to +3.3V, and 1k to GND. To the input (+) the signal from the caliper. Output the amplifier to the microcontroller. If the voltage on the (+) is greater than on the (-) i.e. set with resistors around 0.75V then the amplifier output will be 3.3V. This will ensure that we do not have signal inversion.
    You can use basically any operational amplifier.

    With transistors it will not be so easy anymore, as you would have to take into account the need to draw current from the caliper to supply the base of the transistor.
  • #15 19248737
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    It would look something like this?
    Which transistor/scaler? - reading data from an electronic caliper .
    I found something like this on the web
    Which transistor/scaler? - reading data from an electronic caliper
    looks like it works
  • ADVERTISEMENT
  • #16 19248754
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    Seems ok, the circuit with the transistor will unfortunately discharge this small battery from the caliper.
  • ADVERTISEMENT
  • #17 19249070
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Battery is not the problem, the caliper is powered from the ESP.
    LM358 connected, 1.9V output signal and ESP does not see it. Maybe some values to change?
  • #18 19249200
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    LM358 supplied with 3.3V and the output is 1.9V?
  • #19 19249228
    krzysiek_krm
    Level 40  
    Posts: 4612
    Help: 716
    Rate: 598
    pawlik118 wrote:
    LM358 powered from 3.3V and output is 1.9V?
    .
    And how much should it have, after all it is not rail2rail.
    I have already written previously
    krzysiek_krm wrote:
    Using an operational amplifier as a comparator is a poor idea - the amplifier has some things that are not needed for anything in a comparator, such as compensation.

    Modern comparators are from sudden death, they are just RRIO, either push - pull or open drain, sometimes they even have some kind of reference voltage source.
  • #20 19249249
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    Well yes, in the doc. the LM358 has Vo=Vzas-1.5V. In this situation, the output of the amplifier needs to be pulled up to +3.3V by e.g. 1k.
    Of course there are a whole bunch of comparators, but the LM358 has the advantage that almost everyone has it at hand.
  • #21 19249396
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    After pulling up the outputs it works as it should. Thank you.
    I have an LM393 on hand, can it also be used? In the same way as the LM358? only without pulling up the outputs?
    Greetings
  • #22 19249409
    Anonymous
    Level 1  
  • #23 19249421
    pawlik118
    Level 33  
    Posts: 2405
    Help: 201
    Rate: 596
    iksrowaj wrote:
    After pulling up the outputs it works as it should. Thank you.
    I have an LM393 on hand, can it be used too? In the same way as the LM358? only without pulling up the outputs?
    Greetings
    .
    You are very welcome.
    The LM393 has an OC output and pull-up is necessary in this case.
  • #24 19249738
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Which transistor/scaler? - reading data from an electronic caliper .
    The one on the right doesn't work for me, the one on the left does, but if you look at it, it's actually probably not a good solution (I understand that 3.3V goes to the caliper pin, admittedly nothing happens but it doesn't look good).
    I'm still waiting for the Polol 2595 and we'll see how it works, at most a solution with an amplifier or comparator will remain.
    The best would be a solution with a mosfet similar to the BSS138 (bidirectional) but I don't know how to look for one that would work from 1.5V and preferably 1.2.
    Thank you all and best regards
  • #25 19249977
    krzbor
    Level 29  
    Posts: 1731
    Help: 40
    Rate: 1044
    I don't know why you see such a problem with signal reversal. After all, as you write the program, this is not a problem. The circuit on the right should work, but in the processor you need to switch on the input pull-up (INPUT_PULLUP) or possibly give 10k resistors to PB-0 and PB-1 and connect to 3.3V. This is the most classic circuit for such applications.
  • #27 19250866
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Thank you for the links.
    The diagram with the transistor is working though. Previously something wasn't contacting me despite pulling the pin up.
  • #28 19253197
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    Then I have one more question, I have found the following transistors reasonably available.
    TN0205AD
    https://tvsat.com.pl/PDF/T/tn205a_vish.pdf
    HN1K02FU
    https://tvsat.com.pl/PDF/H/hn1k02fu_tos.pdf
    PMGD280UN
    https://tvsat.com.pl/PDF/P/pmgd280un_ph.pdf
    Would these be suitable?
    Do I think correctly that VGS(th) is the parameter I am looking for?
  • #29 19253963
    krzbor
    Level 29  
    Posts: 1731
    Help: 40
    Rate: 1044
    iksrowaj wrote:
    This is another question I have, I have found the following transistors reasonably available.
    TN0205AD
    https://tvsat.com.pl/PDF/T/tn205a_vish.pdf
    HN1K02FU
    https://tvsat.com.pl/PDF/H/hn1k02fu_tos.pdf
    PMGD280UN
    https://tvsat.com.pl/PDF/P/pmgd280un_ph.pdf
    Would these be suitable?
    Do I think correctly that VGS(th) is the parameter I am looking for?
    .
    After all, you have a bipolar transistor in the schematic, not a MOSFET. Use any low power npn bipolar transistor.
    As far as the VGS is concerned you have got it right. It just needs to be small. In MOSFETs you have to look for such, in bipolar (silicon) you always have about 0.6V drop across the base-emitter.
  • #30 19254171
    iksrowaj
    Level 4  
    Posts: 110
    Rate: 2
    I care about two-way communication and it is not about this particular case.

Topic summary

✨ The discussion revolves around interfacing an ESP32 microcontroller with an electronic caliper powered by a 1.5V battery. The user seeks to convert the 1.5V output signals from the caliper to a 3.3V level suitable for the ESP32 without inverting the signal. Various solutions are proposed, including using a logic level converter, operational amplifiers (op-amps) like the LM358 and LM393, and bipolar transistors such as the 2N3904 and 2N2222. The importance of selecting appropriate components, such as transistors with low Vgs(th) for MOSFETs, is emphasized. The conversation also touches on the need for pull-up resistors and the potential use of a Pololu 2595 converter. The user ultimately finds success with a transistor circuit after addressing issues with signal levels and connections.
Generated by the language model.

FAQ

TL;DR: A 166 kHz clock and 1.5 V signal from the caliper can reach full-swing 3.3 V ESP32 inputs with two cheap parts; "looks like it works" [Elektroda, iksrowaj, post #19248737] Use an NPN level shifter or a rail-to-rail comparator instead [Elektroda, Anonymous, post #19248233]

Why it matters: Correct conversion prevents missed bits and protects the ESP32.

Quick Facts

• Caliper pulse width: 6 µs (≈166 kHz) [Elektroda, iksrowaj, post #19247529] • ESP32 high-level input ≥ 0.75 × Vdd ≈ 2.5 V [Espressif Datasheet] • LM358 output swing: Vcc – 1.5 V (typ.) [TI LM358 DS] • Typical pull-up for open-collector outputs: 1 k–10 k Ω [TI App Note] • TXB010x level shifter fails below 1.65 V on the low side [TI DS]

1. Why can’t the ESP32 read the 1.5 V caliper signals directly?

The ESP32 treats anything below ≈ 2.5 V (0.75 × 3.3 V) as undefined or LOW, so 1.5 V HIGHs from the caliper never cross the required threshold [Espressif Datasheet].

2. Can a single PNP transistor provide a non-inverting level shift?

Not easily. A PNP would still invert unless you add extra parts; biasing also steals current from the 1.5 V rail [Elektroda, pawlik118, post #19248508] A comparator or MOSFET is simpler.

3. Why did the BSS138 bidirectional shifter fail?

Its body diode and threshold need ≥ 1.65 V on the low side. At 1.5 V it never fully turns off, so the ESP32 drags the line high [TI AN10441]—edge-case designers often miss.

4. What’s the minimal working circuit with BJTs?

Two NPNs (e.g., 2N3904) with 10 k pull-ups on the ESP32 side give clean, inverted outputs at 3.3 V and need only 20 µA from the caliper [Elektroda, Anonymous, post #19248233]

5. How do I build a non-inverting LM358 comparator?

  1. Tie LM358 Vcc to 3.3 V, GND to 0 V.
  2. Make a 0.75 V reference using 3.3 k to Vcc and 1 k to GND on the – input.
  3. Feed caliper signal to + input; pull output to 3.3 V with 1 k [Elektroda, pawlik118, post #19248508]

6. The LM358 only outputs 1.9 V. Why?

LM358 is not rail-to-rail; output saturates at Vcc – 1.5 V, i.e., ≈ 1.8 V on a 3.3 V rail [TI LM358 DS]—insufficient for the ESP32 until a pull-up is added [Elektroda, pawlik118, post #19249249]

7. Does LM393 fix this limitation?

LM393 has an open-collector output. With a 4.7 k pull-up to 3.3 V it cleanly reaches the rail and supports 200 ns edge rates—fast enough for 166 kHz [TI LM393 DS].

8. Which off-the-shelf shifters work at 1.5 V?

Pololu 2595 (dual BSS138) works down to 1.2 V on the low side according to the vendor sheet [Pololu 2595]. TXB0108 needs ≥ 1.65 V, so avoid it [TI DS].

10. Could 3.3 V leak into the caliper?

Yes. Without a proper low-side device, the ESP32 pull-ups may back-drive the 1.5 V rail, risking MCU-powered caliper latch-up—an edge-case seen during early tests [Elektroda, iksrowaj, post #19249738]

11. Is inversion really a software problem?

Many developers simply XOR the received bitstream if hardware inverts it. “Program code fixes polarity instantly.” [Elektroda, krzbor, post #19249977]

12. How do I capture caliper readings on the ESP32?

  1. Wire level shifter outputs to GPIOs with hardware interrupts.
  2. Configure clock pin for rising-edge ISR.
  3. Inside ISR, shift in 24 data bits and convert to mm [Elektroda, iksrowaj, post #19247529]

13. What is the speed margin?

At 6 µs pulses, period is 166 kHz. ESP32 GPIO can sample 20 MHz+, giving a 120× safety margin [Espressif Technical Ref].

14. How much current does the NPN solution draw from the caliper battery?

With 10 k base resistors and 1.5 V drive, base current peaks at 0.15 mA per line; average is lower because the signal is bursty [Elektroda, Anonymous, post #19248233]

15. Any cost comparison?

Two 2N3904s and resistors cost < $0.05, LM358 about $0.10, while a TXB0108 board is ≈ $3.50 delivered (2025 market).

16. Can I get true bidirectional 1.2 V↔3.3 V?

Yes, use a low-Vth MOSFET like SI2342DS; it passes lows bidirectionally and blocks highs, needing only two 10 k pull-ups [Vishay DS].
Generated by the language model.
ADVERTISEMENT