I am trying to read and show in Serial Monitor the CO2 measurements of a sensor MH-Z19C in a custom made PCB with chip ESP8266.
The RX/TX pins of the sensor are connected to the RX/TX pins of the microchip ESP8266, which makes it difficult to get the readings in the computer through the FTDI.
Some assumptions:
We cannot change the connection pins between sensor and the ESP8266
The board was working previously and the measurements were correctly read in the computer through Serial Monitor. However, the working code was lost...
In your code you define the softserial pins as D3(RX) (GPIO 0) and D1 (TX)(GPIO5). #define RX_PIN D3 #define TX_PIN D1
Then read the sensor data through the native serial:
" incomingByte = Serial.read(); "
and prints by native serial.
The FTDI must be connected to RX (D9)(GPIO 3) and TX (D10)(GPIO 1).
The sensor must be connected to D1(GPIO 5) and D3(GPIO 0),
and this line of code: "incomingByte = Serial.read(); "
should be: " incomingByte = mySerial.read();"
FTDI RXI and TXO are directly connected to the ESP8266 TXD and RXD. Also sensor RX and TX are connected to the same RXD and TXD. This is why I am having those issues to receive data through Serial Monitor, but I know it is possible because I have seen it working before with no modifications on the wiring
PS:
My suggestion to use both devices on the same serial,
is you make sure that one of them stopped using the serial and then use the serial with the other.
@ruilviana I am very new to Arduino and I was trying to use software serial as a solution for baudrates difference, as the Serial baudrate should be 115200 and the sensor baudarate 9600. But I do not know how to have different baudrates in one single Serial
Making it simple and taking one only baudrate of 9600, the following code gives a constant -1:
EDIT: I finally made it work with the above code. One of the pins was not making proper contact.... Now the question is: is there a way to use the tow different baudrates (115200 and 9600), one for the normal serial communication and one for the sensor?