aviborg / esp-smart-meter

A reliable ESP8266 application to read out data from (swedish) COSEM/DLMS based smart meters using OBIS code/structure.
Apache License 2.0
46 stars 6 forks source link

Is Q1 in your design needed? #10

Closed ArnieO closed 3 years ago

ArnieO commented 3 years ago

Thank you for this project showing how to connect to a Swedish AMS meter with RJ12 HAN interface.

One question: What is the purpose of the Q1 transistor? My understanding is that the data output is Open collector, so a pullup to 3,3V should be sufficient. Are you using Q1 just to invert the data signal?

aviborg commented 3 years ago

The purpose is to lower the voltage to 3.3V and invert the signal. The P1 port outputs 5 V. I found the design on some dutch forum so I just stole it 😃 It might be other ways to do it.

ArnieO commented 3 years ago

Thank you for the clarification, but this sounds like a misunderstanding of what an Open collector (OC) output is and how it is used. Such an output does not output a voltage at all, instead it pulls down an external pullup resistor to GND. This is the beauty of an OC output: You can easily connect it to a system with an alternative voltage as long as you respect the sink current specification. (Page 5 of https://www.skekraft.se/wp-content/uploads/2021/03/Aidon_Feature_Description_RJ12_HAN_Interface_EN.pdf says: "The output low voltage level is max. 1,0V with max. sinking current of 30 mA.").

In this design the 5V to Q1 comes from the pullup resistor R2 that is connected to 5V. When the OC output transistor is off, R2 pulls Q1 base up to 5V. When the OC output transistor is on, it pulls the Q1 base to GND. Then on the transistor output there is the same type of conversion to 3,3V by R1 being connected to 3,3V. In the process the signal is inverted.

If your software allows for inverting the input data signal, you could simplify this by removing R2 and Q1, keeping the R1 pullup to 3,3V and connect the data output directly to a GPIO (it looks like you use the UART0 Rx input).

aviborg commented 3 years ago

Ok, I guess you're right. Haven't done much electronics so I figured copying an existing design was the easiest way.

ArnieO commented 3 years ago

If in doubt - copy something that works! ;-)

tedenda commented 3 years ago

@ArnieO Like in the schematic on this page?: smartyReader P1

tedenda commented 3 years ago

You can then use:

Serial.begin(115200, SERIAL_8N1, SERIAL_FULL, 1, true);

To setup the serial, the last parameter tells if signal is inverted.

ArnieO commented 3 years ago

@tedenda: Yes, that's exactly what I mean: image