Data reading from serial using transistor gates


I am trying to modify existing schematic for my home electric meter project. The data flow from Rj12 Serial port is being triggered when RTS pin is connected to 5V pin of RJ12 port.

What I want to do is to be able to control that triggering using GPIO1 of the NodeMCU. That is when GPIO1 goes high RTS pin gets 5V. when GPIO1 is low then RTS gets 0v.

I extended the original schematic by adding Q1, Q3, R3, R5 to be able to control RTS using GPIO1. Have I missed something, e.g. a pull down resistor? Is R3 correctly connected? I am not an expert so please bear with me :slight_smile:

What's at the other end of the RJ45 cable? Does it have a pull-down resistor on the RTS line?

That is sort of implied by you saying you want to connect 5V to RTS on the RJ45 to trigger things.

However your circuit is connecting RTS to ground and only providing a pull-up to the RTS line from
5V, never connecting it to 5V.

It's RJ12 cable which is similar to RJ45 just 6 pins.

No I am not sure if it has a pull down on RTS line. Schematic of the RJ12 side looks like this, see image. There is a resistor and photodiode and then they go to ground. Do I need to add a pull-down too? if yes where, between which points?

Whats the difference between "pull-up to the RTS line from 5V" and connecting 5V to RTS ? I think in this case it is the same. If yes then does the schematic achieve this?

Your pin 2 signal needs to be connected to +5V to turn on the opto coupler, not pulled-up
with 10k, as that won't drive the opto-coupler properly.

I don't see why you need the transistors if the other end is opto-coupled, why not directly
drive from the microcontroller pins? I guess the signal inversion for the TX pin might be
convenient, but with opto-isolation there's no issue with phantom powering so why not
connect Arduino D1 to RTS direct?

That's a great idea and I think it will work! :slight_smile:

It then eliminates the need for Q1, Q3, R3, R5. And thus the updated diagram will look like on this image.

Then I have this peace of ESPHome code which uses this header file and I need to activate RTS using D1 Output for X seconds and then sleeping for e.g. 60 sec.

This is a C code but I think it is must be based on arduino codebase. It would probably need adding some sleep loops but mainly how do one control GPIOs using code in this header file?

Lose R4, you need to actively drive RTS HIGH, not pull it HIGH.

Post code in code tags please.

Right. R4 is gone now. I Updated the diagram in the previous post.

I cannot post the code here since it exceeds 9000 chars of the message :frowning:

Could you possible look at the code using github link ?

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