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.
So I have a few question about this crash.
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.
I don't know what the exception info means for I can't understand assembly language.
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.