esp8266 crashes with rst cause 4
Posted: Sun Nov 29, 2015 12:53 pm
Hello,
I want to use my esp8266-12 (with adapter board) to control lighting in my house.
I have therefore etched a PCB that includes a socket for the esp8266, a 74hc595 shift register (useful to provide 5V needed by the Relay board), an AMS1117 power supply and 2 buttons for RESET and flash programming.
On output pins of the shift register, I connect an 8-channel Relay board (including transistors, 74hc595 just provides 0/5V, relay board provides the current).
Everything works fine when I have no light attached.
But when I connect a light, it might go on once, and then the esp8266 will stop working with rst cause 4.
I have already added 1000uF to the 5V power supply, and 1uF across VCC and GND on esp8266, but I still always get that reset.
The power supply should not be the problem, it should provide more than 2A @5V.
Plese find here the schematic (not 100% accurate, I made some minor changes to errors I discovered after etching) and the source code.
Thank you for helping me find the error
I want to use my esp8266-12 (with adapter board) to control lighting in my house.
I have therefore etched a PCB that includes a socket for the esp8266, a 74hc595 shift register (useful to provide 5V needed by the Relay board), an AMS1117 power supply and 2 buttons for RESET and flash programming.
On output pins of the shift register, I connect an 8-channel Relay board (including transistors, 74hc595 just provides 0/5V, relay board provides the current).
Everything works fine when I have no light attached.
But when I connect a light, it might go on once, and then the esp8266 will stop working with rst cause 4.
I have already added 1000uF to the 5V power supply, and 1uF across VCC and GND on esp8266, but I still always get that reset.
The power supply should not be the problem, it should provide more than 2A @5V.
Plese find here the schematic (not 100% accurate, I made some minor changes to errors I discovered after etching) and the source code.
Code: Select all
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <EEPROM.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* mqtt_server = "m20.cloudmqtt.com";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
char mask = 0;
const int _SER = 5;
const int _SCL = 14;
const int _SCK = 16;
const int _RCK = 12;
const int G = 13;
void write_sr(char mask) {
int i;
digitalWrite(_RCK, 0);
digitalWrite(_SCK, 0);
for(i=0; i<8; i++) {
digitalWrite(_SER, mask & (1<<i));
digitalWrite(_SCK, 1);
digitalWrite(_SCK, 0);
}
digitalWrite(_RCK, 1);
digitalWrite(_RCK, 0);
}
void setup() {
pinMode(_SER, OUTPUT);
pinMode(_SCL, OUTPUT);
pinMode(_SCK, OUTPUT);
pinMode(_RCK, OUTPUT);
pinMode(G, OUTPUT);
digitalWrite(_SCL, 1);
digitalWrite(G, 0);
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifi;
//reset saved settings
//wifi.resetSettings();
//set custom ip for portal
//wifi.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifi.autoConnect("AutoConnectAP");
//or use this for auto generated name ESP + ChipID
//wifi.autoConnect();
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
client.setServer(mqtt_server, 13840);
client.setCallback(callback);
write_sr(0);
}
void callback(char* topic, byte* payload, unsigned int length) {
//print the received message and topic
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
String t(topic);
//Serial.print("Constructed a String object with the contents: ");
//Serial.println(t);
int pos = int(t.charAt(t.length()-1)) - '0';
int v = ((char)payload[0] == '1') ? 1 : 0;
Serial.print("Accessing port ");
Serial.print(pos);
Serial.print(" and setting to ");
Serial.println(v);
if(v==0) {
mask |= (1<<pos);
//mask = 255;
} else {
mask &= ~(1<<pos);
//mask = 0;
}
write_sr(mask);
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client", "-----------", "-----------------")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic", "hello world");
// ... and resubscribe
client.subscribe("inTopic");
client.subscribe("/node0/set/#");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
return;
/*write_sr(255);
Serial.println("ON");
delay(1000);
write_sr(0);
Serial.println("OFF");
delay(1000);*/
}
Thank you for helping me find the error