ESP32 sending serial data with RS485 AND Access Point?

From my previous question, it worked out that I seemed to be using a pin that could not be used.

For this new question, the access point somehow causes the receiving program not to receive anything when the RS485 circuit is between them. It is odd. It receives in one case, but not the other.

For all cases this is the receive program:

int receivedInt = 0;

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600);
}

void loop() {
  if (Serial2.available() > 0) {
    receivedInt = Serial2.read();
    Serial.println("Received integer:");
    Serial.println(receivedInt);
  }
}

Case 1 - testing if the Access Point program sends integers ESP to ESP:

#include <WiFi.h>
#include <WebServer.h>

/* Put your SSID & Password */
const char* ssid = "ESP32";  // Enter SSID here
const char* password = "12345678";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600); // Initialize Serial2 for communication

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
  
  server.on("/", handle_OnConnect);
  server.on("/option1", handle_Option1); // Map URL to handle_Option1 function
  server.on("/option2", handle_Option2); // Map URL to handle_Option2 function
  server.on("/option3", handle_Option3); // Map URL to handle_Option3 function
  server.on("/option4", handle_Option4); // Map URL to handle_Option4 function
  server.onNotFound(handle_NotFound);
  
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}

void handle_OnConnect() {
  server.send(200, "text/html", SendHTML()); 
}

void handle_Option1() {
  Serial2.write(1); // Send integer 1 via Serial2
  server.send(200, "text/html", SendHTML()); 
}

void handle_Option2() {
  Serial2.write(2); // Send integer 2 via Serial2
  server.send(200, "text/html", SendHTML()); 
}

void handle_Option3() {
  Serial2.write(3); // Send integer 3 via Serial2
  server.send(200, "text/html", SendHTML()); 
}

void handle_Option4() {
  Serial2.write(4); // Send integer 4 via Serial2
  server.send(200, "text/html", SendHTML()); 
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>Options Control</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #3498db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #3498db;}\n";
  ptr +=".button-on:active {background-color: #2980b9;}\n";
  ptr +=".button-off {background-color: #34495e;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";

  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  
  ptr +="<a class=\"button\" href=\"/option1\">Option 1</a>\n";
  ptr +="<a class=\"button\" href=\"/option2\">Option 2</a>\n";
  ptr +="<a class=\"button\" href=\"/option3\">Option 3</a>\n";
  ptr +="<a class=\"button\" href=\"/option4\">Option 4</a>\n";

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

Connect to the ESP32 with the 12345678 password. Go in any web browser and type in the URL: 192.168.1.1

Select options 1-4 and you should see the receiving ESP32's serial monitor set to 115200 baud print each number you press.

Ok, so that all is hunky dory.

Case 2 - testing RS485 circuit:

Same program is uploaded to each ESP32. Nothing is received.

So then I changed it to this minimal master/sender program:

#define RXD2 16
#define TXD2 17

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

void loop() {
  Serial2.write(3);
  delay(1000);
  Serial2.write(2);
  delay(1000);
  Serial2.write(1);
  delay(1000);
}

Then it receives 3, 2, 1 continuously as it should. So I think that's safe to say the RS485 circuit works. (Aside, I didn't design the transmit circuit, but I think that's the schematic for it.)

Any ideas on why the Access Point doesn't work with the RS485 circuit? Because they both work independently.

Hold on. Maybe the RS485 circuits are not working. I thought I tested them with 3,2,1 but maybe my receive circuit isn't working...

Ok, the receiving circuit is iterated four times (four circuits of the same thing). I just found out one of them doesn't work. Another one works and all the programs I gave work as well.

Although, there is some issue with the bigger (not minimal) program not shown. I will continue troubleshooting and try to give a new minimal program if I can't figure it out...

3/4 identical communication circuits were not working

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.