Serial goes one way, not the other.

I have an ESP-12E and an Uno communicating via the Rx and Tx ports on each. I had to swap Rx and Tx to get data from the Uno out to the ESP, however, data still does go from ESP to Uno whether it’s typed in or Serial.printed. I tried using a logic level shifter to no avail, in fact it seemed to not work. I’m not pulling either line low or high.

It seems there are two Grounds on the logic level shifter, do both have to be connected? I figured not.

Please see attachments:

Uno Relevant Code:

void beepRead(char strRead[32]) {
  Serial.print("<");
  Serial.println(strRead);
  int serRead;
  String serReadS;
  char serReadPrefix[5], serReadA[10];
  if (strRead == "0") {
    serRead = 0;
    if (Serial.available() > 0) {
      serReadS = Serial.readString();
    }
    else {
      return;
    }
    if (serReadS == "") return;
    serReadS.toCharArray(serReadA, 10);
    serRead = atoi(serReadA);
  }
  else {
    serRead = atoi(strRead);
  }
  switch (serRead) {
    case 1:
      eventName = "Bolting.";
      break;
    case 2:
      eventName = "Door Closed.";
      break;
    case 3:
      eventName = "Doorbell";
      break;
    case 4:
      eventName = "Key In";
      break;
    case 5:
      eventName = "Door Ajar!";
      break;
    case 6:
      eventName = "Magnet Break!";
      break;
    case 7:
      eventName = "Node 7 - Init.";
      break;
    case 8:
      eventName = "NoKeys Unlock";
      break;
    case 9:
      eventName = "Please Close Door!";
      break;
    case 10:
      eventName = "Reed 8";
      break;
    case 11:
      eventName = "UnBolting";
      break;
    case 12:
      eventName = "Warning";
      break;
    case 13:
      eventName = "Window Alarm!";
      break;
    case 14:
      break;
    case 9106:
      eventName = "Door Ajar!";
      beep(1);
      eventName = "BlueIris Down";
      break;
    case 9103:
      eventName = "remote doorUnlock";
      digitalWrite(PX7, HIGH);
      delay(100);
      sp(7103);
      digitalWrite(PX7, LOW);
      break;
    case 9107: //Flash beacons motion at night
      al7MS = millis();
      digitalWrite(AL7, LOW);
      break;
    case 99: //If recieve corrupt packet, retransmit number via serial
      sp(number);
      return;
    case 999:
      sp(number);
      return;
    case 9999:
      sp(number);
      return;
  }
  if (serRead > 0) {
    lcd.print(eventName);
    Serial.print("Now playing: "); Serial.println(eventName);
    eventTime = millis();
    beep(1);
  }
}

new53.ino (24.5 KB)

node7b3.ino (2.72 KB)

Are you using hardware or software serial on the Uno? (I wouldn’t have to ask this if you’d posted the whole code as per forum guidelines.)
Do you have the grounds of both devices connected?

Hardware Serial on both devices. I have few other pins to use. The grounds were tied together.

BTW: My whole code for the uno (new53.ino) is 24kB, so it was attached instead of copied in-line. I guess I should of told you which attachment was which. The top couple lines reference A1,... so you know that was an Uno.

mattlogue:
BTW: My whole code for the uno (new53.ino) is 24kB, so it was attached instead of copied in-line. I guess I should of told you which attachment was which.

Was the serial communication ever working, or did you just write such a big sketch without ever testing it? The next step would be to start with a troubleshooting sketch which is just the minimum to send serial data from one board to another, to see if the problem is in hardware or software. Given that you're using hardware serial my money is on that being the problem.

What USB-Serial chip does your Uno use? Or is it a genuine or clone? If it is a genuine Uno I would put the onboard 16U2 into reset while I was trying to communicate between the two. Obviously you'll need to use some sort of echo back to the ESP while you do that since you can't use the hardware serial to communicate with both a computer serial monitor and the ESP at the same time.

Which direction is working?

I would expect data from Uno to get to ESP no problem, but I would not expect data to go the other way, because then the ESP's TX line would be fighting the TX line of the serial adapter, which likely has stronger drivers and will win the contest.

The official board has a 1k (or was it 2.2k?) resistor in series with the TX line from the serial adapter, which I would think would let the ESP overpower the serial adapter - but I don't think all the clones do that.

The solution is using a chip with 2 serial ports (328pb with MiniCore/1284p with MightyCore*, or the 2560 (ie arduino mega2560, or one of the ARM-based boards), or a board like the Pro Mini where you can just unplug the serial adapter when not programming it.

  • There are other AVR's with 2 serial ports, but the 328pb and 1284p are probably the best for a large sketch as it sounds like you're working with, are well supported, and widely used. For smaller applications, the attiny841 or 1634 might be appropriate, for example.

DrAzzy: I have an elegoo clone. I have Tx and Rx crossed. The serial works from Uno to ESP fine, just as you surmised. Maybe using a logic-level converter will help, as it will bring the 3.3V ttl signal from ESP to 5v?...

What if I were to use Software Serial? Shouldn't that overcome the issue with the serial adapter overpowering the ESPs weaker-driven signal?

mattlogue:
What if I were to use Software Serial? Shouldn't that overcome the issue with the serial adapter overpowering the ESPs weaker-driven signal?

Yes. Using SoftwareSerial on the Uno allows you to make the connection to the ESP8266 using pins other than 0 and 1 (which the serial adapter is connected to).

Thanks. I'll try swapping what I got on A2 and A3, put them on 0 and 1 - not enabling Serial... and see if it works.