Post topics, source code that relate to the Arduino Platform

User avatar
By BmanDK
#80213 Hi.

I have some strange behaviour that I can't quite understand.

I'm running a Wemos D1 R2

In setup() I call my Startup_screen(); which runs fine.
But Startup_screen() runs faster/smoother when there is no code in the loop() section.

How can that be - Why is code in loop() affecting execution-speed of code in setup() ?
The execution of Sertup_screen() is about half speed or less when loop() contains code like if- of switch-statements.

/Brian

Update:
Since I posted this, I foundation a solution. Added a ESP.eraseConfig; before WiFi.forceSleepBegin(); which solved the problem.
The question now is, why?

Code: Select all
//====================================================================================
//                                  Libraries
//====================================================================================
// Call up the SPIFFS FLASH filing system this is part of the ESP Core
#define FS_NO_GLOBALS
#include <FS.h>
#include "ESP8266WiFi.h" // Bruges kun til at sætte wifi i Sleep-mode
#include "Free_Fonts.h"

#ifdef ESP32
#include "SPIFFS.h"  // For ESP32 only
#endif

// Call up the TFT library
#include <TFT_eSPI.h> // Hardware-specific library for ESP8266
#include <TFT_eFEX.h>
#include <TFTShape.h>

// Invoke TFT library
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite object: Car
TFT_eFEX  fex = TFT_eFEX(&tft);      // Create TFT_eFEX object "fex" with pointer to "tft" object

//====================================================================================
//                          Constants we need for setup
//====================================================================================
const int PWRtimeout   = 20000;  // miliSec timeout befor powering off the RasPi after last serial data has been detected
const int ABORTtimeout = 5;      // Seconds to abort an operations that are waiting for the user


//====================================================================================
//                                    Setup
//====================================================================================
void setup()
{
  WiFi.forceSleepBegin(); // Wifi goes sleepy bye bye.
  Serial.begin(115200);

  // Starting SPIFFS-filesystem
  if (!SPIFFS.begin()) {
    Serial.println("ERR DISPLAY: FS initialisation failed!");
    while (1) yield(); // Stay here twiddling thumbs waiting
  }
  Serial.println("INFO DISPLAY: FS initialised.");

  // Now initialise the TFT
  tft.begin();
  tft.setRotation(3);  // 0 & 2 Portrait. 1 & 3 landscape
  tft.fillScreen(TFT_BLACK);

  // Setup IO-pins
  // Pin that controls the power to ther RasPi. Hi = on, Low = off


  // Runs start-screen and wait for RasPI to start
  wdt_reset();
  Startup_screen();
  tft.fillScreen(TFT_BLACK);
}

//====================================================================================
//                                    Loop
//====================================================================================
void loop()
{
  yield();
  //
  long tid;
 
  if (Serial.available())
  {
    tid = millis();
    String in = GetSerial();
    if (in[0] == 'c') tft.fillScreen(TFT_BLACK);
    if (in[0] == 'h') LoadHead(in);
    if (in[0] == 't') TextWrite(in);
    if (in[0] == '!') icon(in);
  }
  if ((millis() - tid) > PWRtimeout) Shutdown();

 

}
//====================================================================================