1

This is my code to build SHT10 reading. But I got an error message. It says that pin D1 is conflicting between Sensirion.cpp and arduino.h

#include <Sensirion.h>
#include <SensirionSHT.h>

SensirionSHT Sensor = SensirionSHT(4, 5);

long delayTime = 1;

void setup() {
  Serial.begin(9600);
}

void loop() {
  Sensor.tick(delayTime);
  
  Serial.println(Sensor.getTemperature());
  
  delay(delayTime * 1000);
}

And this is the error messages

C:\Users\ASUS\Documents\Arduino\libraries\Sensirion-master\Sensirion.cpp:52:15: error: conflicting declaration 'const float D1'
   const float D1  = -40.1;          // for deg C @ 5V
               ^
In file included from C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/Arduino.h:296:0,
                 from C:\Users\ASUS\Documents\Arduino\libraries\Sensirion-master\Sensirion.cpp:21:
C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\variants\nodemcu/pins_arduino.h:41:22: error: 'D1' has a previous declaration as 'const uint8_t D1'
 static const uint8_t D1   = 5;
                      ^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
user1810087
  • 5,146
  • 1
  • 41
  • 76
Vina Vinesta
  • 11
  • 1
  • 2
  • 1
    Maybe wrap the includes in different namespaces? – mediocrevegetable1 Mar 31 '21 at 08:21
  • Also, `D1` is not a great name. Name it `degrees_celcius_at_5V` or something that can be understood without finding the definition and reading the comment. – Ted Lyngmo Mar 31 '21 at 08:25
  • Well, I think I shouldn't change the Sensirion.cpp code right? [link](http://example.com) _italic_ **bold** `// Temperature & humidity equation constants const float D1 = -40.1; // for deg C @ 5V const float D2h = 0.01; // for deg C, 14-bit precision const float D2l = 0.04; // for deg C, 12-bit precision` – Vina Vinesta Mar 31 '21 at 08:35
  • 2
    @VinaVinesta I would - and I would make a pull request upsteam to fix their code. They haven't put their stuff in a namespace and also, they have global constants in their `.cpp` file that are not `static` so they cause conflicts. Not nice. It's not been updated for 7 years it seems. Perhaps there are more up-to-date libraries? – Ted Lyngmo Mar 31 '21 at 08:41
  • 1
    OK, I'll try it. Thanks – Vina Vinesta Mar 31 '21 at 10:12

0 Answers0