Skip to content

reading SHT20 with Ticker (Timer) interrupt #4353

Closed
@SayidHosseini

Description

@SayidHosseini

Basic Infos

Hardware

Hardware: NodeMCU V 0.9
Core Version: 2.4.0

Description

Problem description:

I've connected SHT20 sensor to the NodeMCU V 0.9. When reading sensor data using DFRobot_SHT20 library in a loop or with a delay mechanism, it works fine. But I'm trying to get the sensor data in a Timer interrupt using the Ticker library on ESP core. it doesn't matter how long this interval is, it just doesn't work. I have also tried using SHT10 sensor with the proper library and the same happens there too. Any idea what the problem might be?

Settings in IDE

Module: NodeMCU 0.9 (ESP-12 Module)
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ?
Flash Frequency: ?
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

#include <Ticker.h>
#include <Wire.h>
#include "DFRobot_SHT20.h"

Ticker tick;
DFRobot_SHT20    sht20;

void setup()
{
  Serial.begin(115200);
  Serial.println(); 
  
  sht20.initSHT20();
  delay(100);

  int humidity = sht20.readHumidity();
  int temp = sht20.readTemperature();
  //Here, it reads fine - Also checked it with a loop and delay
  Serial.print("Temp: ");
  Serial.println(temp);
  Serial.print("Humidity: ");
  Serial.println(humidity);

  tick.attach(5, getSHTData); // it doesn't matter how long this interval is
}

void loop() 
{
}

void getSHTData()
{
  int humidity = sht20.readHumidity();
  int temp = sht20.readTemperature();

  Serial.print("Temp: ");
  Serial.println(temp); // prints 998
  Serial.print("Humidity: ");
  Serial.println(humidity); // prints 998
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions