ESP32+bmp280+ST7735+MCP2301 + Blynk

So, I have them both connected on the same SPI interface and if I use the example for each(with both connected at the same time) it works, but if I put the example codes both in a single program the temperature read fails. It can read if the sensor is connected or not, but it is not able to read data from it. The display works.

What is wrong? How do I deal with this? Are different devices supposed to work on the same SPI interface?

Thanks!

Failed data from sensor:
21:28:22.860 -> Temperature = -147.52 *C
21:28:22.895 -> Pressure = 127892.58 Pa
21:28:22.930 -> Approx altitude = -2008.56 m
21:28:22.964 ->

The example code for both:

/**************************************************************************
  This is a library for several Adafruit displays based on ST77* drivers.

  Works with the Adafruit 1.8" TFT Breakout w/SD card
    ----> http://www.adafruit.com/products/358
  The 1.8" TFT shield
    ----> https://www.adafruit.com/product/802
  The 1.44" TFT breakout
    ----> https://www.adafruit.com/product/2088
  as well as Adafruit raw 1.8" TFT display
    ----> http://www.adafruit.com/products/618

  Check out the links above for our tutorials and wiring diagrams.
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional).

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 **************************************************************************/

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

//#ifdef ADAFRUIT_HALLOWING
//  #define TFT_CS        39 // Hallowing display control pins: chip select
//  #define TFT_RST       37 // Display reset
//  #define TFT_DC        38 // Display data/command select
//  #define TFT_BACKLIGHT  7 // Display backlight pin

//#elif defined(ESP32)
  #define TFT_CS         2
  #define TFT_RST        22 //SCL
  #define TFT_DC         21 ///SDA

  // HARDWARE VSPI 
#define BMP_SCK  (18)  // SCL
#define BMP_MISO (19)  // SD0
#define BMP_MOSI (23)  // SDA 
#define BMP_CS   (5)  // CSB


Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);



float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  Serial.print(F("Hello! ST77xx TFT Test"));
  Serial.println(F("BMP280 test"));

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

#ifdef ADAFRUIT_HALLOWING
  // HalloWing is a special case. It uses a ST7735R display just like the
  // breakout board, but the orientation and backlight control are different.
  tft.initR(INITR_HALLOWING);        // Initialize HalloWing-oriented screen
  pinMode(TFT_BACKLIGHT, OUTPUT);
  digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
#else
  // Use this initializer if using a 1.8" TFT screen:
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
#endif



  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);



  Serial.println("done");
  delay(1000);
}

void loop() {
  readtemp();
  delay(500);
  tftPrintTest();
  delay(1000);
  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

}



void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.println(" seconds.");
  tft.print("Temperature: ");
  tft.println(bmp.readTemperature());
  
}


void readtemp() {
    //Serial.println(read8(BMP280_REGISTER_CHIPID));

    Serial.print(F("Temperature = "));
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");

    Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
    Serial.println(" m");

    Serial.println();
    delay(2000);
}

I’ve not studied your code in detail, but your cluttered void loop won’t work when you add Blynk into the equation.
Read this:

Then start restructuring and unpicking your code to get it working.

Pete.

They can… but it is not a Blynk thing at all. I recomend Googling and reading up on a few articles about SPI. For example…

https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all

I was hoping someone did something similar. I could not find any example yet.
I found here about the chip select pin for the BMP280, I updated the code with a different CS pin but no results yet.

It is not a Blynk project… yet. I need to make sure they work first.

Thanks!

There must be somthing out there… bmp280 ST7735 same SPI interface - Google Search

Seen this, but I don’t want to give up on SPI yet.

Oh… The 2nd search result shows how to combine them if setting the BMP280 to I2C… better than nothing :slight_smile:

Maybe combining them on SPI is not possible, maybe it is… but I am not going to do all the Google research myself to find more info… :wink:

1 Like

I read about that solution before posting, but I was interested in connecting all the devices using the SPI interface. I guess that’s what I am going to do.

Nobody managed to make them work together. At least from what I found till now.
As soon as I initialize the display, the temperature reading crashes. It does not matter if the display is connected or not. Tried UCGLIB too but without any success.

I guess I am going to have to use the sensors on I2C . Next thing I am trying is the MCP2317

Thanks!

You’ve come to the Blynk community forum to get advice on a non-Blynk issue, and don’t like the responses you’re getting. Your terse responses probably aren’t endearing too many community users to you, which may be an issue when you come back with a real Blynk related issue.

My advice would be to dial it down a bit and at least appear to be a bit more grateful for the responses you are receiving.

Pete.

Most of time I am posting something on this forum, some you guys are trying to convince me that I should have never done it, and that was a mistake. Someone is always more preoccupied on finding a reason for that rather than being helpful.

Blynk is for me, probably the most interesting thing on the internet, and this forum is the first thing that comes into my mind when I get into some iot trouble. Basically all the programming skills I gained are because of blynk.

But every time I get disappointed when I get here… Someone always have to pick on me for some reason.

you mean you feel like someone always have to pick on you for some reason?

just so you can achieve some perspective - this is a disgusting response to someone who is trying to to help you… regardless if you put a smile face after it.

2 Likes

English is not my mother’s language, so pardon me for that, probably I was tired too. None of my messages were intended to offend anyone here. I feel grateful for any help I get here, just to make that clear.

I appologize especially to Gunner if any of my messages were disrespectful in any way. All I meant to say was that I don’t expect anyone to do any research for me. I only expected some help from someone who did something similar and has already some experience to share.

I used the BMP280(later BME) sensors on I2C and it works fine. I only use an extra pin after all(comparing to SPI+ 1 aditional pin for chip select_ and hopefully, I can make the mcp23017 work correctly so I can add some buttons. As soon as everything works fine I will connect the device to Blynk.

I corrected my previous messages. Again, I am sorry about that.
At the moment, the display(the only one on spi), the bmp280 and the mcp23017 work fine all together without Blynk.

BUT, here is the Blynk part of this project. As soon as it gets connected to the Blynk server, the display gets white and it won’t display anything anymore.

What bigger(than the 0.96" ssd1306) displays have you managed to use with ESP32 and Blynk?

#define NAMEandVERSION "OfflineTask_Reconnect_V1.0"
/*
  This sketch is based on an example posted by Gunner with some modifications added in place to make it able to reconnect after Wifi or Server connection failures.
  It is able to check if it is a Wifi or a server connection issue and recover it when it is possible
  The MCU runs the task every second - It turns the builtin led on and off (allways) and post the millis/1000 to blynk server (only when a connection is available).
*/

#define BLYNK_DEBUG
#define BLYNK_TIMEOUT_MS  500  // must be BEFORE BlynkSimpleEsp8266.h doesn't work !!!
#define BLYNK_HEARTBEAT   17   // must be BEFORE BlynkSimpleEsp8266.h works OK as 17s

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_PRINT Serial    
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789



char ssid[]            = "xxxx";
char pass[]            = "xxxxx";
char auth[]            = "xxxxxxxxxx";
//char server[]          = "blynk-cloud.com";
//char server[]          = IPAddress(192,168,1,xxx);
unsigned int port      = xxxx; //use your own port of the server

bool on = 0;
bool online = 0;

bool theLEDState = 0;

 // for ESP32 I2C 22 scl - 21 sda
  #define TFT_MOSI 23  // SDA 
  #define TFT_SCLK  18  // SCL
  #define TFT_CS   15  // CS
  *#define TFT_RST  5   // reset*
  #define TFT_DC   4   // a0
  //

// If you dont want to use DHCP 
IPAddress arduino_ip ( 192,  168,   1,  xx);
IPAddress dns_ip     ( 192,  168,   1,   1);
IPAddress gateway_ip ( 192,  168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

BlynkTimer timer;
WidgetTerminal terminal(V1);
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  Serial.begin(115200);
  Serial.println();
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
  tft.setRotation(2);
  WiFi.setHostname(NAMEandVERSION);
  WiFi.mode(WIFI_STA);
  Blynk.config(auth, IPAddress(192,168,1,3), port);  // I am using the local Server

  
  CheckConnection();// It needs to run first to initiate the connection.Same function works for checking the connection!
  timer.setInterval(5000L, CheckConnection); 
  timer.setInterval(1000L, myTimerEvent); 
  timer.setInterval(10000L, tftPrintTest); 
}

void loop() {
  if(Blynk.connected()){
    Blynk.run();
  }
  timer.run();
}


void CheckConnection(){    // check every 11s if connected to Blynk server
  if(!Blynk.connected()){
    online = 0;
    yield();
    if (WiFi.status() != WL_CONNECTED)
    {
      Serial.println("Not connected to Wifi! Connect...");
      //Blynk.connectWiFi(ssid, pass); // used with Blynk.connect() in place of Blynk.begin(auth, ssid, pass, server, port);
      WiFi.config(arduino_ip, gateway_ip, subnet_mask);
      WiFi.begin(ssid, pass);
      delay(400); //give it some time to connect
      if (WiFi.status() != WL_CONNECTED)
      {
        Serial.println("Cannot connect to WIFI!");
        online = 0;
      }
      else
      {
        Serial.println("Connected to wifi!");
      }
    }
    
    if ( WiFi.status() == WL_CONNECTED && !Blynk.connected() )
    {
      Serial.println("Not connected to Blynk Server! Connecting..."); 
      Blynk.connect();  // // It has 3 attempts of the defined BLYNK_TIMEOUT_MS to connect to the server, otherwise it goes to the enxt line 
      if(!Blynk.connected()){
        Serial.println("Connection failed!"); 
        online = 0;
      }
      else
      {
        online = 1;
      }
    }
  }
  else{
    Serial.println("Connected to Blynk server!"); 
    online = 1;    
  }
}


void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  if (online == 1)
  {
    Blynk.virtualWrite(V5, millis() / 1000);    
  }
  else 
  {
    Serial.println("Working Offline!");  
  }
  
  if (on == 0)
  {
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)    
    on = 1;
  }
  else
  {
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW                  
    on = 0;
  }
  Serial.println(millis() / 1000);
}


void tftPrintTest() {
  Serial.println("TestDisplay");
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  delay(2000);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
  Serial.println("Display END");
  delay(2000);
}

LE: replaced gpio2 with gpio5 for the display reset. GPIO2 was used by the builtin led. the display is fully working now with blynk. proceeding

1 Like

fully working example for anyone who’s interested:

#define NAMEandVERSION "ESP32_BMP280_ST7735_MCP2301"
/*
 Basic example of esp32 + bmp280 + ST7735 + MCP2301
*/

//#define BLYNK_DEBUG
#define BLYNK_TIMEOUT_MS  500  // must be BEFORE BlynkSimpleEsp8266.h doesn't work !!!
#define BLYNK_HEARTBEAT   17   // must be BEFORE BlynkSimpleEsp8266.h works OK as 17s
#define BLYNK_PRINT Serial    

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include "Adafruit_MCP23017.h"
#include <Wire.h>

#define SDA 21
#define SCL 22           /// I2C pins
Adafruit_MCP23017 mcp;
Adafruit_BMP280 bmp;

  // for ESP32 I2C 22 scl - 21 sda
  #define TFT_MOSI 23  // SDA 
  #define TFT_SCLK  18  // SCL
  #define TFT_CS   15  // CS
  #define TFT_RST  5   // reset
  #define TFT_DC   4   // a0

//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
float p = 3.1415926;

char ssid[]            = "ssid";
char pass[]            = "pass";
char auth[]            = "auth";
//char server[]          = "blynk-cloud.com";
//char server[]          = IPAddress(192,168,1,x);
unsigned int port      = xxxx; //use your own port of the server

bool on = 0;
bool online = 0;

bool theLEDState = 0;

#define LEDpin 0


// If you dont want to use DHCP 
IPAddress arduino_ip ( 192,  168,   1,  xxx);
IPAddress dns_ip     ( 192,  168,   1,   1);
IPAddress gateway_ip ( 192,  168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

BlynkTimer timer;
WidgetTerminal terminal(V1);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  Serial.begin(115200);
  Serial.println();
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
  tft.setRotation(2);
  WiFi.setHostname(NAMEandVERSION);
  WiFi.mode(WIFI_STA);
  WiFi.config(arduino_ip, gateway_ip, subnet_mask);
  Blynk.config(auth, IPAddress(192,168,1,xxx), port);  // I am using the local Server

  Wire.begin(SDA,SCL);
  mcp.begin();      // use default address 0
  //mcp.begin(0x20);      // use custom address
  mcp.pinMode(0, OUTPUT);
  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
                  
  Serial.println(F("BMP280 test"));
  if (!bmp.begin(0x76)) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    //while (1);
  }
  
  CheckConnection();// It needs to run first to initiate the connection.Same function works for checking the connection!
  timer.setInterval(5000L, CheckConnection); 
  timer.setInterval(1000L, myTimerEvent);    
  timer.setInterval(10000L, readtemp);
  timer.setInterval(5000L, BlinkTheLed);  
  timer.setInterval(5000L, tftPrintTest);      
}

void loop() {
  if(Blynk.connected()){
    Blynk.run();
  }
  timer.run();
}


void CheckConnection(){    // check every 11s if connected to Blynk server
  if(!Blynk.connected()){
    online = 0;
    yield();
    if (WiFi.status() != WL_CONNECTED)
    {
      Serial.println("Not connected to Wifi! Connect...");
      //Blynk.connectWiFi(ssid, pass); // used with Blynk.connect() in place of Blynk.begin(auth, ssid, pass, server, port);
      WiFi.config(arduino_ip, gateway_ip, subnet_mask);
      WiFi.begin(ssid, pass);
      delay(400); //give it some time to connect
      if (WiFi.status() != WL_CONNECTED)
      {
        Serial.println("Cannot connect to WIFI!");
        online = 0;
      }
      else
      {
        Serial.println("Connected to wifi!");
      }
    }
    
    if ( WiFi.status() == WL_CONNECTED && !Blynk.connected() )
    {
      Serial.println("Not connected to Blynk Server! Connecting..."); 
      Blynk.connect();  // // It has 3 attempts of the defined BLYNK_TIMEOUT_MS to connect to the server, otherwise it goes to the enxt line 
      if(!Blynk.connected()){
        Serial.println("Connection failed!"); 
        online = 0;
      }
      else
      {
        online = 1;
      }
    }
  }
  else{
    Serial.println("Connected to Blynk server!"); 
    online = 1;    
  }
}


void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  if (online == 1)
  {
    Blynk.virtualWrite(V5, millis() / 1000);    
  }
  else 
  {
    Serial.println("Working Offline!");  
  }
  
  if (on == 0)
  {
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)    
    on = 1;
  }
  else
  {
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW                  
    on = 0;
  }
  Serial.println(millis() / 1000);
}


void readtemp() {
    Serial.print(F("Temperature = "));
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");

    Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
    Serial.println(" m");
    Serial.println();  
}

void BlinkTheLed()
{
  Serial.println("The LED");
  if (theLEDState == 1) {
    // btnState is used to avoid sequential toggles
      mcp.digitalWrite(LEDpin, HIGH);
      theLEDState = 0;
    }
  else {
    mcp.digitalWrite(LEDpin, LOW);
    theLEDState = 1;
  }
}

void tftPrintTest() {
  Serial.println("The display!");

  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.println(" seconds.");
  tft.print("Temperature: ");
  tft.println(bmp.readTemperature());
  tft.print("Pressure: ");
  tft.println(bmp.readPressure());
}

I’d recommend anyone thinking of using this code to stagger these timers, as every 10 seconds they will be five events all trying to execute at EXACTLY the same time, which will probably lead to issues with missed readings or possibly random disconnections in future.

Pete.

1 Like

five events all trying to execute at EXACTLY the same time

To clarify, with a single processor, only one thing can be executed at one time. The callbacks will be called in some order - in order by their assigned timer number which is out of the user’s control (other than if no other timers had been assigned yet, these 5 would be assigned in the order they were started).

If the timers expire “simultaneously” (i.e. during the same millis() tick), the callbacks will be called one immediately after another during the next call to timer.run(). In particular, they can not interrupt one another or interleave in any way. Each one will run to completion before the next can be called.

Calling 5 callbacks in one timer.run() call will stretch the duration of that call, but the callbacks can’t compete or interfere with one-another (at least, not due to any kind of simultaneity).

1 Like

I don’t dispute what you’re saying, it’s just simpler to explain it the way I did - especially for people who don’t have English as their first language.

Pete.

2 Likes