To give some immediate context on what I'm doing, see this circuit diagram below, I'm using the right side.
The whole point is to preserve power. I realize the ESP side could just use a super-cap or a small LDO/not use a giant step down regulator when it will be constantly on.
Anyway the Seeeduino is turned on/off by the ESP by a digital high output which enables the ground to flow on the parent MOSFET. This generally works but I'm having problems syncing the two devices, so the Seeeduino will get into this "brown out" state I call it. Where it's not powered up correctly, the green/amber lights are both on together(should just be green).
I have tried a few ways to sync them, the seemingly more reliable way is to communicate between the two (Seeeduino says "I'm booted" to ESP)... but the data between the two is not reliable... I'll send for example "sb" and I'll get back "sbx" or "sby" on the ESP side.
I've attached two images of my code that I tried(some methods omitted but not needed). The 9999 to string I know is dumb but it was out of desperation, originally I was sending something like "seeeduino booted" but seemed to be too many characters to reliably transmit/receive in one piece/correctly so I went with just "sb" and then tried a "number".
Anyway thanks for any thoughts, this project did become overblown it was not my intent to do this originally but it's good practice for trying to make something that lasts at least a month/use all the pins on the board imo. It generally works but the serial com is what is messing it up, possibly the on/off/on/off booting of the Seeeduino.
No communication attempt just wait for serial data to be available
ESP-code
void loop()
{
digitalWrite(LED, HIGH); // turn Seeeduino on
if (Serial.available() > 0)
{
String serialMsg = Serial.readString();
if (serialMsg.length() > 0)
{
digitalWrite(LED, LOW); // turn Seeeduino off have data
delay(5000); // wait for Seeeduino to completely power off
txStrByWiFi(serialMsg); // this works fine
clearSerialBuffer();
sleepDelay = 30000; // long sleep
}
}
delay(sleepDelay); // this is initially 1000
}
Seeeduino code
void setup()
{
Serial1.begin(115200);
analogReadResolution(10);
pinMode(0, OUTPUT);
}
void loop()
{
delay(5000); // wait for ESP to be ready (first turned on, both will share same power switch)
digitalWrite(0, HIGH); // turns shared parallel analog sensor power on
delay(5000); // wait for power to build up, this is excessive
int aVal = analogRead(A1);
digitalWrite(0, LOW); // sensors off
Serial1.write(aVal); // data to ESP
delay(10000); // long delay to wait till it dies/not loop again
}
Communication attempt
ESP-code
void loop()
{
digitalWrite(LED, HIGH); // turn Seeeduino circuit on
if (Serial.available() > 0)
{
String serialMsg = Serial.readString();
if (serialMsg.length() > 0)
{
// https://forum.arduino.cc//index.php?topic=543780.0
if (serialMsg.equals("9999")) // not a possible value
{
txStrByWiFi("match");
seeeduinoBooted = true;
clearSerialBuffer();
} else {
digitalWrite(LED, LOW);
delay(2000); // wait to completely die
seeeduinoBooted = false;
txStrByWiFi(serialMsg);
clearSerialBuffer();
sleepDelay = 10000; // long sleep
}
}
}
delay(sleepDelay);
// ESP.deepSleep(sleepDelay);
}
Seeeduino-code
void setup() {
// Serial.begin(115200); // to monitor // also sends
Serial1.begin(115200); // to ESP // also works
analogReadResolution(10);
pinMode(0, OUTPUT);
}
void loop() {
Serial1.write(9999); // seeeduino booted avoiding long strings
delay(2000); // still using unguaranteed delays
digitalWrite(0, HIGH);
delay(5000);
int aVal = analogRead(A1);
digitalWrite(0, LOW);
// Serial.println("done measuring"); // comment out if monitor not connected
Serial1.write(aVal);
delay(10000); // this shouldn't turn on again for a while
}
Edit: can right-click open new tab to see the image in full size






