🌐
Reddit
reddit.com › r/arduino › psa: arduino with single core esp32s adds 5ms delay to loop() every 2 seconds
r/arduino on Reddit: PSA: Arduino with Single Core ESP32s adds 5ms delay to loop() every 2 Seconds
February 21, 2025 - ... I was working an a project that uses an ESP32-C6, two I2C ADS1015 ADCs and using a logic analyzer I saw a 5ms pause every 2 seconds, which was causing timing issues and corrupted data.
ESP32S2 stalling every 2 sec for 5ms Mar 28, 2024
r/esp32
2y ago
ESP 32 Interrupt handling Jul 24, 2023
r/arduino
2y ago
Making a delay_us() routine Mar 16, 2023
r/stm32
3y ago
5second interruptible timer Jul 4, 2022
r/arduino
4y ago
More results from reddit.com
🌐
RNT Lab
rntlab.com › question › esp32-replacement-for-arduino-delay
ESP32 replacement for Arduino "delay()" ??
When it get’s a request it checks what it’s for and sends the response. Most of the time it’s idling so you can do a lot. Also remember that the ESP32 has two cores so you can set one to handle HTTP requests and the other to handle everything else. ... Hi Steve, Thanks.. I am looking at NOT using regular delay()..
🌐
Mechatronics LAB
mechatronicslab.net › home › lessons › esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › delay() function for esp32 arduino programming
Delay() Function for ESP32 Arduino Programming - Mechatronics LAB
The delay() function is one of ... It? The delay() function tells your ESP32 to “wait” before running the next line of code. One millisecond equals one-thousandth of a second....
🌐
Arduino Forum
forum.arduino.cc › projects › programming
ESP32 delay required after Serial.begin - Programming - Arduino Forum
August 1, 2025 - I'm still using Arduino IDE 1.8.9 and the esp32 Boards extension (by espressif Version 3.3.0) with an ESP WROOM 32 module. A small test sketch with nothing but void setup() and some Serial output does not work, unless I add some delay between Serial.begin and the first Serial output.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
ESP32 delay() doesn't work - Programming - Arduino Forum
November 18, 2022 - Hi all, I am using ESP32 to do a project by using delay() function. It seems to me that the delay() function never works! I tried using the millis() as well and it doesn't work so well neither. unsigned long ini= 0 ; void setup() { Serial.begin(115200); delay(10); wifisecure.setInsecure(); while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network.
🌐
Reddit
reddit.com › r/arduino › sub microsecond delays on esp32
r/arduino on Reddit: Sub microsecond delays on esp32
December 18, 2021 -

Do I have to write instructions in assembly? Im using Arduino IDE and im trying to sample a signal at 44.1khz. I come from a PIC Micro background where I would just use a TMR. Whats the play here in Arduino Land?

🌐
Mechatronics LAB
mechatronicslab.net › home › lessons › protected: esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › delaymicroseconds() function for esp32 arduino programming
delayMicroseconds() Function for ESP32 Arduino Programming - Mechatronics LAB
int trigPin = 5; int echoPin = ... Serial Monitor to see distance values printed every second. What You’ll See (Output) The ESP32 will send a 10-microsecond pulse and measure how long the echo takes to return....
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino delay() function tutorial
Arduino delay() Function Tutorial
July 26, 2025 - ... The delay() function pauses ... can achieve a time delay of 1 second by passing 1000 to the delay function like this: delay(1000);...
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 1343
Timer Interrupt vs Delay · Issue #1343 · espressif/arduino-esp32
April 22, 2018 - Hello everyone, I would like to share a question with you. I currently have a metering pump that is controlled by the ESP32. To apply the correct dosage, I use a delay (ms). This is a big problem for larger dosages, it locks the system f...
Author   espressif
Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › projects › programming
ESP32-core in which file is delay() declared? - Programming - Arduino Forum
May 14, 2023 - Hi Everybody, I'm interested in the ESP32-core what are the lines of code for function delay() inside the core for ESP32 So I tried a find-text in files search in the path C:\Users\dipl-\AppData\Local\Arduino15\packages\esp32 but with no success. As the function delay() can be used in ESP32-code it must be defined / declared somewhere How would you start searching for it? extension filter *.cpp? what folder-paths? is this so special that it is just a precompiled hex-file whcih means I c...
🌐
ESP32 Forum
esp32.com › viewtopic.php
Wait microsecond - ESP32 Forum
#include "freertos/FreeRTOS.h" ... ... Sat May 04, 2019 11:09 pm The arduino-esp32 core achieves this using the following code for the delayMicroseconds() func....
🌐
ESP32 Forum
esp32.com › viewtopic.php
Nanosecond delay - ESP32 Forum
April 12, 2024 - For less time-sensitive delays I used "busy_wait_us", but the best I found for ESP is "esp_rom_delay_us" which is marked as "Internal and Unstable". Of course, if I can manage to make a delay in 10s on ns, then this won't be a problem either. For short delays, you can use esp_rom_delay_us().
🌐
Reddit
reddit.com › r/esp32 › esp32 c3: delay in execution every 2 seconds
r/esp32 on Reddit: ESP32 C3: Delay in execution every 2 seconds
September 2, 2023 -

I am controlling a stepper motor driver with my ESP32 and so I need to have my loop execution time to be low, because otherwise it can´t send enough signals a second. And generally it does that but every 2 seconds it doesn´t, even tough there is nothing changing. There is nothing more being executed by my code. Could that be caused by some feature of the ESP32 C3 and if yes how can I avoid it?

I have already turned of WIFI and Bluetooth and now Hardwareinterrupts are calles, as they only are buttons which I dont press and thus the LCD isn´t updated either.

Code:

#include <AccelStepper.h>
#include <LiquidCrystal.h>
#include <esp_wifi.h>
#include <esp_bt.h>

LiquidCrystal lcd(19, 3, 4, 5, 6, 7);

//Stepper Motor
AccelStepper stepper1(1, 1, 0); // (Type of driver: with 2 pins, STEP, DIR)
boolean plusPressed = false;
boolean minusPressed = false;
boolean switcherPressed  = false;
boolean changeStep = false;
boolean oldChangeStep = false;
int curSpeed = 0;
int oldCurSpeed = 0;
int stepSize = 100;
int oldStepSize = 100;
unsigned long lastButtonPress = millis();

void setup() 
{
  // Disable Wi-Fi
  esp_wifi_stop();

  // Disable Bluetooth
  esp_bt_controller_disable();
  esp_bt_controller_deinit();
  
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(18, INPUT);
  
  //Stepper Motor
  stepper1.setAcceleration(500);
  stepper1.moveTo(2147483647);

  // Display
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(fillupTo16("Speed: " + String(curSpeed)));
  lcd.setCursor(0, 1);
  lcd.print(fillupTo16("Step Size: " + String(stepSize)));
  if(changeStep) {
    lcd.setCursor(15, 1);
    lcd.print("X");
    lcd.setCursor(15, 0);
    lcd.print(" ");
  }
  else {
    lcd.setCursor(15, 0);
    lcd.print("X");
    lcd.setCursor(15, 1);
    lcd.print(" ");
  }

  // Hardware Interrupts
  attachInterrupt(digitalPinToInterrupt(18), increasePressed, RISING);
  attachInterrupt(digitalPinToInterrupt(10), decreasePressed, RISING);
  attachInterrupt(digitalPinToInterrupt(2), changePressed, RISING);
}

void increasePressed() {
  if(changeStep) {
    stepSize += 50;
    lcd.setCursor(0, 1);
    lcd.print(fillupTo16("Step Size: " + String(stepSize)));
  }
  else {
    curSpeed += stepSize;
    lcd.setCursor(0, 0);
    lcd.print(fillupTo16("Speed: " + String(curSpeed)));
  }
}

void decreasePressed() {
  if(changeStep) {
    stepSize -= 50;
    if(stepSize < 0) {
      stepSize = 0;
    }
    lcd.setCursor(0, 1);
    lcd.print(fillupTo16("Step Size: " + String(stepSize)));
  }
  else {
    curSpeed -= stepSize;
    if(curSpeed < 0) {
      curSpeed = 0;
    }
    lcd.setCursor(0, 0);
    lcd.print(fillupTo16("Speed: " + String(curSpeed)));
  }
}

void changePressed() {
  if(changeStep) {
    changeStep = false;
    lcd.setCursor(15, 1);
    lcd.print(" ");
    lcd.setCursor(15, 0);
    lcd.print("X");
  }
  else {
    changeStep = true;
    lcd.setCursor(15, 0);
    lcd.print(" ");
    lcd.setCursor(15, 1);
    lcd.print("X");
  }
}

String fillupTo16(String input) {
  for(int i = input.length(); i < 15; i++) {
    input += " ";
  }
  return input;
}

void loop() 
{ 
  // Stepper Motor Control
  stepper1.setMaxSpeed(curSpeed); 
  stepper1.run();
}
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 2211
Delay(x) delays 3 times more than expected while running esp32 at 80MHz clock speed · Issue #2211 · espressif/arduino-esp32
December 18, 2018 - Hardware: Board: ESP-WROOM-32 with a break out board. Core Installation date: 04/09/2018 IDE name: Arduino IDE Flash Frequency: 80Mhz PSRAM enabled: no Upload Speed: 921600 Computer OS: Windows 10 ### Description: the delay function dela...
Author   espressif
🌐
ESP32 Forum
esp32.com › board index › english forum › discussion forum › esp32 arduino
vTaskDelay() vS. Delay() - ESP32 Forum
portTICK_PERIOD_MS = 10; vTaskDelay(1000 / portTICK_PERIOD_MS); // 1000/10 = 100 Ticks instead of Delay(1000)?
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › arduino › theory and blog › why you shouldn’t always use the arduino delay function
Why You Shouldn’t Always Use the Arduino Delay Function | Random Nerd Tutorials
April 2, 2019 - Using the millis() functions takes ... to using delay(). But your programs can’t do multitasking on the Arduino without it. Share this post with a friend that also likes electronics! You can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page. ... Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, ...
🌐
Reddit
reddit.com › r/esp32 › need to have sub microsecond delay precision
r/esp32 on Reddit: Need to have sub microsecond delay precision
July 29, 2020 -

Hi guys,

I'm trying to implement something that will generate two triggers at regular intervals where the two triggers are separated by a configurable delay. The delay has to be configurable to sub microsecond resolution. Ideally, 500ns or less.

I chose the ESP32 because of its 240MHz clock, but it still seems to be having trouble.

I'm messing around with the following code:

#define cyclespermicro 240
#define microcycles(n) (n*cyclespermicro)

uint32_t startCounter, counter, cpu_cycles;
int cyclediff, totalcycles, corrected;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  startCounter = ESP.getCycleCount();
  totalcycles = startCounter + microcycles(2);
  //delayMicroseconds(1);

 while (ESP.getCycleCount() < totalcycles) {
        __asm__ __volatile__ ("nop");
 }
  
  counter = ESP.getCycleCount();
  cpu_cycles = counter - startCounter;
  corrected = cpu_cycles - 262;
  Serial.print("StartCounter: ");
  Serial.print(startCounter);
  Serial.print(" counter: ");
  Serial.print(counter);
  Serial.print(" cpu_cycles: ");
  Serial.print(cpu_cycles);
  Serial.print(" corrected: ");
  Serial.println(corrected);
}

void loop() {

}

The problem is that I get the same number of clock cycles for 1 us as I do for 2 us. I'm guessing this is because the while loop overhead is overwhelming the 1 us delay.

The problem is I need to have the amount of delay configurable and I don't know the best way to do this. Anyone have any ideas how to efficiently create configurable sub-microsecond delays?

EDIT: I am also noticing, when I get rid of the while loop entirely, and just straight up copy in NOP lines, it works as expected for like 3 NOPs, but once I hit 5 NOPS, the overhead jumps to like 500 cycles. What is going on here?

🌐
Arduino Forum
forum.arduino.cc › other hardware › 3rd party boards
Time delay computation ESP32 - 3rd Party Boards - Arduino Forum
December 9, 2024 - Good afternoon to everybody! I'm very sorry if I bother you with this question but I'm struggling on it since so long! I have an ESP32 and I'm using FreeRTOS to acquire 6 signals. I use Core0 to acquire the data and Co…
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 2981
delay() function doesn't work for less than 10ms · Issue #2981 · espressif/arduino-esp32
July 11, 2019 - Current code is: void delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } // My suggestion is: void delay(uint32_t ms) { uint32_t delay_end = millis() + ms; vTaskDelay(ms / portTICK_PERIOD_MS); while (delay_end > millis()) { NOP(); } }
Author   espressif
🌐
Xplore-DNA
xplore-dna.net › mod › page › view.php
Coding ESP32: delay() | DNA
February 18, 2021 - #define LED 13 //LED an digital pin 13 void setup() { pinMode(LED, OUTPUT); //Pin 13 als Ausgang konfigurieren } void loop() { digitalWrite(LED, HIGH); //Schaltet pin 13 auf HIGH //(LED wird angeschaltet) delay(1000); //Das Programm wird fuer 1000 ms angehalten digitalWrite(LED, LOW); //Die LED wird ausgeschaltet(auf LOW gestellt) }