ESP-01 Software Serial

Hi everyone well i am looking for a solution to my problem i.e. using software serial with ESP01. here is the code i am using.

#include <SoftwareSerial.h>
SoftwareSerial Serial2(0, 2); // RX, TX ESP01 

String QPIGS = "\x51\x50\x49\x47\x53\xB7\xA9\x0D";
  String stringOne;
void setup() {
  Serial.begin(115200);
    Serial2.begin(2400);
      Serial2.setTimeout(10000);
}
void loop() {
  Serial2.print(QPIGS);
        stringOne = Serial2.readStringUntil('\r');
          Serial.println(stringOne);
            delay(100);
              stringOne = "";
}

basically this code query to solar inverter and in return print the reply from solar inverter originally copied it from "https://www.youtube.com/watch?v=Ri2HvdjnINw&list=PLDW1zKN_tjaJDp-Ukz8KApchBgA60AFC_&index=9&ab_channel=545sytes"
the code upload easily but on serial monitor i don have any print also my blue light on ESP-01 blinks very dim but if replace the pins 0,2 with hardware RX and TX the code works as desired but in this scenario i am unable to get any reply on serial monitor.

1 Like

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will apply so-called code tags which makes the code easier to read and copy and the forum software will display it correctly.

Never personally tried this, but if you want, try.
Since esp8266 has UART1 TX1 on Gpio2 and you only need to tx to serial monitor, you could use Serial (Gpio1&3) for inverter and Serial1 (Gpio2) for serial monitor.
So all without softwareserial.

1 Like

It is connected to GPIO1 (TX) so if there is any Serial output it flash a bit.

GPIO 0 & 2 as well as GPIO 1 (TX) should never be pulled 'LOW' at boot or the ESP will go into the wrong boot mode, how have you connected it all ?

As @kmin says, GPIO2 is usable as TX for UART1 (which can not be used for RX) so use that as your (debugging) output

Thanks for your reply, well i am using Rs232-ttl converter. between inverter and esp01

i am connecting the RX of ESP-01 with TX of Rs232-ttl converter. similarly TX of ESP-01 with RX of Rs232-ttl converter to send and receive the commands

Thank you for your reply i will try and update soon.

to program and monitor the reply from inverter i am using this programmer
programmer

It's not level shifter, It's Rs232-ttl converter.

To program your Esp just use it as normally. If you want to connect Serial rx0/tx0 to inverter and Serial1 tx1 to that "programmer", you need to use dupont wires.

Your life would be much easier with Esp32 devboard.

Actually i am new to these things hence have no idea about it thanks for correcting me

The programmer has GPIO 0 pulled LOW to put it in programming boot mode. After the upload it performs a soft-reset, but GPIO 0 remains pulled LOW

Connect the level shifter to the hwSerial, and connect GPIO 2 to the TX pin of the programmer (as well as GND & Vcc) using connecting wires.

Here is the rough diagram of how things physically working


i am using breadboard after programing the esp-01 . i am using just the RX TX and Power from programmer

After programming GPIO 0 should not be connected to GND anymore.
instead of connecting ESP-RX to the programmer, just connect it to the converter.
Connect TX of the programmer to GPIO 2 of the ESP.

Use Serial1 for the debug and Serial for the connection to the converter.

Please update the drawing and upload the new code, so we can see that you understand correctly or we need to improve on the explanation

Ok as far as connections are concerned here is what i have learnt from your post


but for the program i am still confused can you please guide me about code as per this diagram . i am not good at coding

Eh have you now connected ESP RX to converter RX (instead of TX) ? It's a little hard to tell because you've turned the converter over in the newest version. For the rest that looks fine.

sure

String QPIGS = "\x51\x50\x49\x47\x53\xB7\xA9\x0D";
String stringOne;

void setup() {
   Serial1.begin(115200);
   Serial.begin(2400);
   // Serial.setTimeout(10000);   // probably not needed for hwSerial
}

void loop() {
  Serial.print(QPIGS);
  stringOne = Serial.readStringUntil('\r');
  Serial1.println(stringOne);
  delay(100);
  stringOne = "";
}

would be the modification from your own code.

I would probably test for anything being in the buffer before reading and printing it, and make 'stringOne' a local variable and 'QPIGS' a constant, but if it worked like this before it should work now.

ESP RX is connected to TX of Converter yes i have changed the picture. well many thanks for the code i will try and update you as soon as i get any success. many thanks for the code again

Since RS232 converter board is just a "translator" it might be correct to connect TX to TX and RX to RX.

ok will give it a try

Please add a resistor in between pins on each line to limit the current or you may damage your ESP (and possibly the converter) something like 10K will be fine for slow speeds.

You mean 10K between every connection i.e. between ESP and Programmer as well as ESP to Converter ?

no just between esp & converter TX & RX. Particularly if you are going to start swapping them over ! if two TX lines are connected they may break otherwise. Hopefully not since there would be no reception on the RX line and so no response, but still it may happen.