I have two questions, one about electronic components and one about programming for this schematic here:

  1. The TX pin is the transmitter pin, so why is there this dioid(1n4148). As I know dioids are blocking current from one side, so Current can flow from the anode end to the cathode, but not the other direction. How does this work?

  2. The serial databus connection is halfduplex. So if I’m writing something with serial.write() I should block the RX pin. How can I do that since the serial library gives me no option for that?

Thanks for any help!

The TX pin of the Arduino is HIGH when not transmitting; the diode and resistor prevent conflict with the incoming data from the M365.

You can use Serial.flush after Serial.write to make sure the message goes out before reading a reply.
The RX will see the data that you transmit.
If there is a sufficient delay between the transmit by the Arduino and the reply from the M365, you can try to the data and ignore it. Next you can read the actual reply.
You can also disable the receive functionality while the transmit from the Arduino is in progress. Never tried so below might be incorrect.

// disable receive
cbi(*_ucsrb, RXEN0);
// enable receive
sbi(*_ucsrb, RXEN0);

The first line comes from the core function HardwareSerial.end() and I think that it will be sufficient; the second line does the opposite (and is used in HardwareSerial::begin()).

Did you have a look at the code at GitHub - augisbud/m365_dashboard: Xiaomi M365 Display V0.2?

First thanks for your help.

Ok I got it for the second point. In the code that you have linked, it seems like he just disables the RX pin while writing than enable the RX pin again by changing value of the UCSR0B register.

The first point still gives me headaches. How can we have high while not transmitting? If we have high while not transmitting, do we not corrupt the RX pin receiving data?

In addition, should the diode not look in the opposite way?

Moreover, if we are transmitting, what logical state do we have than, since high is used while not transmitting?

The idle state of a serial line is HIGH. Transmission starts with a start-bit which is a LOW and ends with 1/1.5/2 stop-bits which are HIGH.

The diode and resistor prevent the corruption; the M365 can still pull the line LOW.

If the diode is the other way around, the TX pin can't actively pull the TX line LOW because the diode will block the current flow.

Thanks for your help! I got it !