So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By surfman1975
#90688 Hello there, noob to the forums and fairly so with the ESP8266. I have a project that uses I2c for the OLED display and talks to another device via serial (pins 3-RX, 1-TX). I had it all working, or so I thought, and found that on "power up" everything ran great. Then the ESP goes to DeepSleep and when it wakes up it just "might" send commands out the Serial but it also may not.

So then I started from the beginning and skinnied the code down to reduce variables at potential play in the matter. When I did the following it works 100% of the time. (working = Serial.print("I'm awake"), turn LED on, sleeps for 5 seconds, goes to deep sleep, wakes up with the click of a button which sends a low to RST and repeats as expected). Here is the quite simple code, that again seems to work 100% of the time.

Code: Select all#define LED 2   //Define connection of LED

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);
  while(!Serial){}
  Serial.println("I'm awake now!);

  pinMode(LED, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  digitalWrite(LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
  delay(5000);

  ESP.deepSleep(0);
}

void loop() {
 
}



BUT when I add in the display code for the OLED the following happens...
1 - it always works on power up (boot)
2 - first or second wake might also work
3 - never works again but the code never errors, it simply acts like it transmitted and moved to next line in code. for instance, the display will load all of the heading images and then the "Hello World" for 5 seconds and then back to deep sleep. But nothing is sent to the Serial Monitor in the code below. (or the device in my project code which is simply sending a "Serial.print('O');"

As I just mentioned, I validated this with the Serial Terminal and was shocked (not sure why) I saw this exact same behavior there too. Here is the code for what does not work as desired.

Code: Select all#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define LED 2   //Define connection of LED

// OLED Display
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define CHARGE_AREA_START_X     20
#define CHARGE_AREA_START_Y     18
#define CHARGE_AREA_WIDTH       83
#define CHARGE_AREA_HEIGHT      28

// 'FullBat', 25x8px
const unsigned char fullBat [] PROGMEM = {
  0x1f, 0xff, 0xff, 0x80, 0x18, 0x00, 0x01, 0x80, 0xfb, 0xff, 0xfd, 0x80, 0xfb, 0xff, 0xfd, 0x80,
  0xfb, 0xff, 0xfd, 0x80, 0xfb, 0xff, 0xfd, 0x80, 0x18, 0x00, 0x01, 0x80, 0x1f, 0xff, 0xff, 0x80
};

// 'wifi', 15x10px
const unsigned char wifi [] PROGMEM = {
  0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc, 0x70, 0x1c, 0x07, 0xe0, 0x1f, 0xf0, 0x0c, 0x60, 0x01, 0x00,
  0x03, 0x80, 0x01, 0x00
};

void setup() {
  // Serial Setup
  Serial.begin(115200);
  Serial.setTimeout(2000);
  while(!Serial) { }
  Serial.println("I'm awake now");
 
  // OLED Setup
  display.setRotation(2); // Set rotation
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    for(;;); // Don't proceed, loop forever
  }
  DrawScreen();
 
  // Turn the LED on
  pinMode(LED, OUTPUT);   
  digitalWrite(LED, LOW);   
  delay(5000);

  // Going to Deep Sleep
  Serial.println("I'm shutting down now");
  display.clearDisplay();
  display.display();
  ESP.deepSleep(0);
}

void loop() {
}

void DrawScreen(void) {
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.drawBitmap(0,0,wifi,15,10,1); // Wifi (18,12)
  display.drawBitmap(87,0,fullBat,25,8,1); // Battery
  display.setCursor(0, 16);
  display.setTextSize(.5);
  display.print("Hello World");
  display.display();
}


Have any of you ever seen this before? I have also tried using SoftwareSerial in case it was an error in the standard serial library but no dice, same result. Please do let me know your thoughts. thanks,
User avatar
By surfman1975
#90782 UPDATE: I put a delay(1000); after the Serial.Begin(115200) and now, it does seem to wake up and transmit more (not 100%) but definitely more than before. Maybe 80% of the time AND I have a better result if I wait a little bit longer (more than 30 seconds) in between wake ups. I really want it to be 100% and I shoulld be able to push the wake up button as soon as it goes to sleep (maybe 5 seconds delay at most) Thoughts?