after getting a little familiar with programming with Arduino, I'm at a point where I can't get any further. I am using an ESP32-POE-ISO. As part of the project, I want to synchronously read several sensors using the I2C protocol. Since several ESP32s are used, I need a method to synchronize them as accurately as possible. For this I use a local NTP server on a Raspberry (connected via Ethernet). Currently I get a jitter of max. +/-100 microseconds. I also tried a UDP broadcast, but the result is similar.
Do any of you have an idea for a method to improve this value (->smaller jitter)? Maybee causing an interrupt via UDP?
Thanks in advance,
Kainer
- #include <WiFi.h>
- #include <ETH.h>
- #include "time.h"
- TaskHandle_t Task1;
- time_t new_t, old_t;
- void codeForTask1(void * parameter)
- {
- const long gmtOffset_sec = 3600;
- const int daylightOffset_sec = 3600;
- // time_t new_tl, old_tl;
- for(;;){
- delay(1000);
- configTime(gmtOffset_sec, daylightOffset_sec, "192.168.1.2");
- }
- }
- void setup()
- {
- Serial.begin(115200);
- Serial.println("Start .......");
- pinMode(5, OUTPUT); // set the LED pin mode
- ETH.begin();
- ETH.config(IPAddress(192, 168, 1, 66),IPAddress(192, 168, 1, 255),IPAddress(255, 255, 255, 0));
- delay(100);
- xTaskCreatePinnedToCore(codeForTask1,"Task_1",10000,NULL,1,&Task1,0);
- old_t=0;
- }
- void loop(){
- time(&new_t);
- if(difftime(new_t,old_t)!=0)
- {
- pinMode(5, INPUT); // set the LED pin mode
- delayMicroseconds(100);
- old_t=new_t;
- }
- pinMode(5, OUTPUT);
- }