1
\$\begingroup\$

I want to use a digital input pin of a NodeMCU board (ESP8266) to read a digital signal. The signal line idles at 24V DC. The logic levels are 24V and 16V. The signal speed is 500 Baud (each signal sample is approx. 2 ms long). How do I convert the signal for the NodeMCU board?

EDIT:

Unfortunately I do not have an oscilloscope. What I already did is: I connected the bus lines to the microphone port of an USB sound card using a voltage divider with 1MOhm and 1kOhm and used the software Soundcard Scope. Does this tell you something about how the bus works?

Soundcard Scope screenshot

24V high, 16V low. No 24V supply available near the NodeMCU board. Not sure about the maximum transmitter load. It is the 2-wire communication bus of a door intercom system (TCS, https://www.tcsag.de/).

BTW, in TCS:BUS documentation I found the hint that bus messages are either 16 or 32 bit long.

EDIT:

Soundcard Scope screenshot with Windows Automatic Gain Control (AGC) turned off for the microphone input:

Soundcard Scope screenshot #2

EDIT:

This diagram is the result of capturing bus voltages with analogRead():

Voltage plot

Any idea how this protocol could be working?

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you mean 24V high/16V low, or is that the voltage range that should be considered high? Do you have a 24V supply near the NodeMCU board? What kind of load can the transmitter handle? It would be useful to know the protocol/signaling standard if there is one. \$\endgroup\$ – Caleb Reister Sep 18 at 7:26
  • \$\begingroup\$ It's difficult to say, but TCS:BUS may actually be a current-output differential protocol. If this is the case, measuring voltage levels may be unreliable. \$\endgroup\$ – Caleb Reister Sep 18 at 17:44
  • \$\begingroup\$ How could I find out? \$\endgroup\$ – x-ray Sep 18 at 18:55
  • \$\begingroup\$ You should be able to tell if it is differential by probing both of the wires on the bus with an oscilloscope. Post a screenshot of you can. \$\endgroup\$ – Caleb Reister Sep 18 at 18:59
  • 1
    \$\begingroup\$ A significant portion of the waveforms you provided are likely due to limitations of your computer's soundcard. \$\endgroup\$ – Caleb Reister Sep 18 at 20:11
2
\$\begingroup\$

The simplest thing to do from a hardware perspective would be to use a pair of resistors to scale the voltage to a range acceptable to an analog input on the NodeMCU and do the rest in software.

If you want to do more in hardware, add a voltage comparator that compares the scaled voltage to an appropriate threshold and then feed the output of the comparator to a digital input on the NodeMCU. For example, if you scale the 24V input down to 3.3V, the lower level will be at 2.2V. A threshold voltage of 2.75V would be appropriate.


The following circuit made only with discrete transistors might do an adequate job. The input divider scales the 16V/24V input to 2.2V/3.3V. The B-E junction of the PNP creates a threshold at about 3.3V - 0.65V = 2.65V. When the input is at 16V (actually, anything less than about 19V), both transistors are switched on, and the digital output is pulled to ground.

schematic

simulate this circuit – Schematic created using CircuitLab

When the input is 16V, this is equivalent to connecting the base of Q1 to 2.2V through a 3700Ω resistor (Thévenin equivalent source). This puts about 0.45 volts across R5, allowing about 100 µA of current to flow out Q1's collector. Most of this current flows through Q2's base, driving it into saturation and sinking about 3 mA through R4.

R3 prevents leakage current through Q1 from turning on Q2. It sinks about 30 µA @ 0.65 V, so anything less than that keeps Q2 cut off, while anything more than that switches it on.

\$\endgroup\$
  • \$\begingroup\$ Could I also use a transistor and resistors instead of a voltage comparator IC? I have BC327 and BC337 lying around... \$\endgroup\$ – x-ray Sep 17 at 22:51
  • 1
    \$\begingroup\$ See edit above. \$\endgroup\$ – Dave Tweed Sep 18 at 3:25
  • \$\begingroup\$ Thank you, I built the circuit and it seems to be working well! \$\endgroup\$ – x-ray Sep 18 at 16:11
  • \$\begingroup\$ Is this a Sziklai Darlington Transistor Configuration? If not, how does this circuit work? \$\endgroup\$ – x-ray Sep 19 at 9:19
  • 1
    \$\begingroup\$ No, it isn't a Sziklai pair. I'll add a description to the answer. \$\endgroup\$ – Dave Tweed Sep 19 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.