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

User avatar
By Janmuel
#79506 Hey guys,

and thanks so much for all the great info in this forum, I went through a couple of threads to get me started. However, I am not getting why my ESP is running too slow or what I did wrong so far. I programmed the BlinkWithoutDelay example sketch and added some lines for Serial output:

Code: Select allint ledState = LOW;

unsigned long previousMillis = 0;
const long interval = 1000;
unsigned long steps=0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  steps++;
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
     Serial.print("Steps:");
     Serial.println(steps);
     steps=0;   
    if (ledState == LOW) {
       Serial.print("Off:");
      Serial.println(millis());
      ledState = HIGH;  // Note that this switches the LED *off*
    } else {
      ledState = LOW;  // Note that this switches the LED *on*
      Serial.print("On:");
      Serial.println(millis());
    }
    digitalWrite(LED_BUILTIN, ledState);
  }
}


What I am getting now is the following:

Steps:182039
On:576083
Steps:182144
Off:577083
Steps:181821
On:578083
Steps:181987
Off:579083

As expected the LED is toggled every second and in between there are 1000 Milliseconds. But the steps are like 182000 per second so the main loop is executed with like 182 kHz. Where is this coming from?

More info on the hardware: I bought this board (https://www.amazon.com/gp/product/B010N1SPRK/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1) and followed the steps written on that page. Also I performed step6:

6. Download and run the 32 bit flasher exe at Github(Search for nodemcu/nodemcu-flasher/tree/master/ at Github) github.com/nodemcu/nodemcu-flasher/tree/master/Win32/Release Or download and run the 64 bit flasher exe at: github.com/nodemcu/nodemcu-flasher/tree/master/Win64/Release

I first flashed the board with the default settings from the nodemcu-flasher. Are all of these settings overwritten by flashing with Arduino IDE?

Thank you so much for the help, I really appreciate that.
User avatar
By QuickFix
#79523 While there's a relation between clock speed and processing speed ("IPS"), they're not the same entities. :idea:
Apart from the IPS of a processor, one has to take into account the speed of code generated by the compiler.
If you would write code in pure assembly, you should be able to get faster "main loop" times.
Lastly the ESP has a WiFi-stack that needs time to do its thing every once in a while, which will also take time.

By default a NodeMCU (the board you're using) is flashed with LUA- or AT-firmware.
Once you flash something else, for instance BASIC or Arduino (= C++) code, the previous firmware will be overwritten.