1
votes

I decided to use Arduino IDE for ESP8266 to program on my ESP8266, targeting to read data (bytes array from a TTL camera). ESP8266-01 (8Mbits Flash ROM) has 8 pins so I decided to use GPIO16 (TXD) and GPIO2 (RXD) as SoftwareSerial pins to achieve this. But the ESP8266 printed an exception and I am not sure what happened to it.

The crash report

So I have a few question about this crash.

  1. I want to know whether I can run SoftwareSerial on ESP8266 (ESP8266 has 2 UARTs, Serial0 for Serial print and we could not send data through Serial1), so I decided to use SoftwareSerial.

  2. I don't know what the exception info means for I can't understand assembly language.

  3. I read documents on Github for Arduino IDE for ESP8266, but I don't understand well about the pin definitions on ESP8266 when programming with Arduino IDE. For example, when using GPIO16 (TXD) and GPIO2 (RXD) as SoftwareSerial, we might use Constructor SoftwareSerial Camera(int Pin1, int Pin2). I want to know what the corresponding Pin1 and Pin2 for GPIO2 and GPIO16) is. The document really confused me.

Here is my key code.

#include <Arduino.h>
#include "camera_VC0706.h"
#include <SoftwareSerial.h>
HTTPClient httpClient;
//define camera and bytes array, I am not sure whether the pins are correct or not
int rxPin=2;
int txPin=16;
SoftwareSerial cameraSerial(rxPin,txPin); //RX,TX
camera_VC0706 Camera = camera_VC0706(&cameraSerial);
//take photo
bool takePhoto() {
  byte time=0;
  writeRawSerial(F("<STATUS>WAITING</STATUS>"),true);
  while(!Camera.begin(115200)) {
    if(+time<=5){//try 5 times
      writeRawSerial(F("."),false);
    } else {
      writeRawSerial("",true);
      writeSerial(F("<STATUS>NO_CAMERA</STATUS>"));
      return false;
    }
  }
  writeRawSerial(F("<STATUS>CAMERA_ON</STATUS>"), false);
  writeRawSerial(F("<VERSION>"), false);
  writeRawSerial(Camera.getVersion(), false);
  writeSerial(F("</VERSION>"));
  Camera.setImageSize(VC0706_320x240);
  if (!Camera.takePicture()) {
    writeSerial(F("<STATUS>TAKE_PHOTO_FAIL</STATUS>"));
    return false;
  } else {
    byte imgSize = Camera.frameLength();
    writeSerial(F("<STATUS>TAKE_PHOTO_SUCCESS</STATUS>"));
    writeRawSerial(F("<IMAGE_SIZE>"),false);
    writeRawSerial(String(imgSize,DEC),false);
    writeSerial(F("</IMAGE_SIZE>"));
    freeHeap();//It was defined, but not key function, only for showing free heap of esp8266
    imgBuffer=Camera.readPicture(imgSize);
    freeHeap();
    Camera.resumeVideo();
    writeSerial(F("<STATUS>SAVE_PHOTO_SUCCESS</STATUS>"));
    return true;
  }
}

Thank you for reading my questions.

2
Also asked at: forum.arduino.cc/index.php?topic=535532 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.per1234

2 Answers

1
votes

So, the stack trace shown is pretty standard for any system, and it gives you pretty much everything you need to track it down - It is not assembly code, it is hexadecimal addresses of your binary.

First, you have an Exception 28 - If we look at the ESP8266 Reference, you can see 28 means you either have a bad pointer, or you're trying to access non-cached data from an interrupt/cache is turned off.

Next, you have an address, epc1. This is where the code crashes, which is a hexadecimal address to the binary you uploaded. Also, ctx: cont is helpful, as it indicates the program crashed in your code and not the system code.

You also have excvaddr, which is the addressed you tried to access, 0x10.

Given that, you almost certainly have a NULL pointer somewhere in your code that you are dereferencing. You should use the ESP Exception Decoder to determine what line has the offending crash and bad pointer usage.

In regards to using the software serial - You'd just use the pin numbers on the datasheet. GPIO 14 would be number 14 in the constructor. I found it worked, but caused very bizarre crashes in the production products I worked with after 1+ days of usage, so do not recommend it at all. We ended up using Serial1 for debug printing, and freed up Serial0 for general UART communications - Way more reliable.

2
votes

You need to add the standard Arduino functions of setup() and loop() or it won't know where to start.

If you have a look at the example sketches you should be able to get something running, and then you can start adding your takePhoto code.