0

I am sending data from an ESP8266 to an Uno (I need to use the Uno because it has more inputs than the ESP and I need those for my project.) The ESP8266 is connected to the Uno's Serial pins 0/1 RX/TX (communicating on BAUD rate of 9600), and then I have a SoftwareSerial out from the Uno (on a BAUD rate of 57600) for debugging. Something weird is happening though. The transfer works a couple times and then I get this in the log:

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (0):
epc1=0x40239ba1 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffebd0 end: 3fffffb0 offset: 0190
3fffed60:  40239b2e 3feffe00 3fffd9d0 00000050  
3fffed70:  000005e0 00000000 40103501 3ffed4d0  
3fffed80:  0000003c 00000000 00000022 401049e6  
3fffed90:  401049c8 3fffc100 3ffef2a0 00000000  
3fffeda0:  00000000 4022279f 00000020 40100198  
3fffedb0:  400005e1 150cc636 00000005 4010144c  
3fffedc0:  4022279f 00000030 00000010 3ffefdcc  
3fffedd0:  40221007 3fff051a 00000014 00000000  
3fffede0:  00000000 00000061 00000061 00000001  
3fffedf0:  3ffecdb8 00000006 00000000 3fff04fc  
3fffee00:  3fff051a 3ffef2a0 00000061 00000000  
3fffee10:  3ffe9be8 7fffffff 50800000 00000001  
3fffee20:  00000001 00004a08 00000142 401006d7  

Any ideas what could be causing this? Here is the code that the Uno uses for receiving from the ESP and printing to the SoftwareSerial (Serial is the RX/TX and mySerial is the SoftwareSerial). It uses a couple helper functions I haven't included here but let me know if you need them:

void receiveFromESP() {
  if (Serial.available() > 0   ) {
    endofTransmission == 0;
    alreadyZeroed = 0 ;
    receivedChar = Serial.read();
    mySerial.print(receivedChar);
    if (receivedChar == '[' ) {
      lastNum = 0 ;
      commaNumber = 0 ;
      lastWasNum = 0 ;
    }
    if (receivedChar == '*' ) {
      lastNum = 0 ;
      commaNumber = 0 ;
      lastWasNum = 0 ;
      createArray[0] = 4;
      createArray[1] = 4;
      createArray[2] = 4;
      createArray[3] = 4;
    }
    if (receivedChar == 'A'
        || receivedChar == 'B'
        || receivedChar == 'C'
        || receivedChar == 'D'
        || receivedChar == 'E'
        || receivedChar == 'F'
        || receivedChar == 'G'
        || receivedChar == 'H'
        || receivedChar == 'I'
        || receivedChar == 'J'
        || receivedChar == ','
       ) {
      if (lastWasNum == 1) {
        createArray[commaNumber] = lastNum;
        commaNumber++;
      }
      lastWasNum = 0 ;
      createArray[commaNumber] = charToNumber(receivedChar);
      commaNumber++;
      lastNum = 0 ;
    }
    if (receivedChar == ']') {
      lastWasNum = 0 ;
      endofTransmission = 1 ;
      for (int i = 0; i < 50; i++) {
        mySerial.print(createArray[i]);
        mySerial.print(':');
      }
    }
    if (
      receivedChar == '0'
      ||  receivedChar == '1'
      ||  receivedChar == '2'
      ||  receivedChar == '3'
      ||  receivedChar == '4'
      ||  receivedChar == '5'
      ||  receivedChar == '6'
      ||  receivedChar == '7'
      ||  receivedChar == '8'
      ||  receivedChar == '9'
    ) {
      lastWasNum = 1;
      receivedCharInt = (int)receivedChar - 48;
      lastNum = lastNum * 10 + receivedCharInt;
    }
    t = millis();
  }
};

As requested, here is the full ESP code:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic

#define SERIAL_BUFFER_SIZE 256

void setup() {

  Serial.begin(9600);
  for (uint8_t t = 4; t > 0; t--) {
    Serial.printf("*WIFISETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }
  WiFiManager wifiManager;
  wifiManager.setConfigPortalTimeout(120);
  //first parameter is name of access point, second is the password
  wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");
}

void loop() {
    WiFiClient client;
    HTTPClient http;
    if (http.begin(client, "[URL]")) {  // HTTP
      // start connection and send HTTP header
      http.addHeader("Content-Type", "text/plain");
      http.addHeader("Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
      int httpCode = http.GET();

      if (httpCode == 200 ) {  // HTTP header has been sent and Server response header has been handled
        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();
          Serial.println(payload);
        }
      } else{
        if (httpCode > 0 ){
          //website problem
          Serial.printf("[2,1,1,1]");
        } 
        if (httpCode == -1 ){
          //wifi problem
          Serial.printf("[4,1,1,1]");
          ESP.reset();
        }
      }
      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  delay(10000);
}
8
  • use stack decoder IDE plugin to decode the stack. the crash is in esp code, so Uno code is not what we need to see
    – Juraj
    Commented Nov 30, 2020 at 5:58
  • 1
    I am connecting just the ESP to my computer to watch the log. The ESP sends data every 30 seconds so I assume I will see the crash happening there too and will check out the stack decoder IDE plugin too. (The ESP is sending on 9600 and the SoftwareSerial is on 57600.)
    – garson
    Commented Nov 30, 2020 at 16:20
  • 1
    "The ESP is sending on 9600 and the SoftwareSerial is on 57600." ???
    – Juraj
    Commented Nov 30, 2020 at 16:25
  • 1
    I added clarification about the BAUD rates to the question text.
    – garson
    Commented Nov 30, 2020 at 16:49
  • 1
    Post your ESP code, you are likely has a buffer overflow somewhere in your ESP. BTW, use if (receivedChar >= '0' && receivedChar <='9') would be much simpler for your Arduino code.
    – hcheung
    Commented Dec 1, 2020 at 8:52

1 Answer 1

-1

Why not use a PCF8574 I2C expansion board, they work great on 3V3. If you need more inputs or outputs use the PCF8575. There are a lot of I2C expansion boards you can select from. They will also be faster and less convoluted then your existing solution.

4
  • The answer to "why not" is "I have never heard of I2C boards before." Please forgive my lack of knowledge, and my convoluted solutions, as I am new to this. I would appreciate your help in addressing the problem that I took time to lay out in this post. Thank you.
    – garson
    Commented Dec 1, 2020 at 23:17
  • Try going to ebay and search for "I2C modules" I got over 7,000 hits. The exception you are getting is from the ESP8266. Eliminate the Delay() and your crashing should go away. There are lots of posts on the web telling you why not to use it. By the way you did not clearly lay out your problem you just posted a lot of code. I googled ESP8266 Exception (0): and got this as the first hit: espressif.com/sites/default/files/documentation/…
    – Gil
    Commented Dec 2, 2020 at 22:03
  • I have reconfigured the code to use millis() instead of delay(). I am still facing the same error message. Please let me know if there are problems I could explain better in my post - I am trying to be helpful and provide all the information that I can.
    – garson
    Commented Dec 3, 2020 at 19:31
  • How about showing a schematic. Be sure to show the ground connections as you have them connected. You might go into a little more detail about the baud rates and how do you get the serial debugger to work with softwareserial.
    – Gil
    Commented Dec 4, 2020 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.