0

I'm trying to use SHT40 this one with arduino opla kit, but I keep getting this error when compiling.

In file included from /home/krystofprasil/Arduino/libraries/Arduino_MCHPTouch/src/Arduino_MCHPTouch.h:13:0,
                 from /home/krystofprasil/Arduino/libraries/Arduino_MKRIoTCarrier/src/Arduino_MKRIoTCarrier_Qtouch.h:25,
                 from /home/krystofprasil/Arduino/libraries/Arduino_MKRIoTCarrier/src/Arduino_MKRIoTCarrier.h:37,
                 from /tmp/.arduinoIDE-unsaved202225-83850-1h13urr.1oioh/SHT4test/SHT4test.ino:13:
/home/krystofprasil/Arduino/libraries/Arduino_MCHPTouch/src/touch_api_SAMD.h:709:1: error: conflicting declaration 'typedef struct tag_sensor_t sensor_t'
 sensor_t;
 ^~~~~~~~
In file included from /home/krystofprasil/Arduino/libraries/Adafruit_SHT4x_Library/Adafruit_SHT4x.h:25:0,
                 from /tmp/.arduinoIDE-unsaved202225-83850-1h13urr.1oioh/SHT4test/SHT4test.ino:11:
/home/krystofprasil/Arduino/libraries/Adafruit_Unified_Sensor/Adafruit_Sensor.h:155:3: note: previous declaration as 'typedef struct sensor_t sensor_t'
 } sensor_t;
   ^~~~~~~~
Compilation error: exit status 1}

I already tried to rename every sensor_t to sensor_tmp in the SHT4 library

Code:

/*************************************************** 
  This is an example for the SHT4x Humidity & Temp Sensor

  Designed specifically to work with the SHT4x sensor from Adafruit
  ----> https://www.adafruit.com/products/4885

  These sensors use I2C to communicate, 2 pins are required to  
  interface
 ****************************************************/

#include "Adafruit_SHT4x.h"

#include "Arduino_MKRIoTCarrier.h"
MKRIoTCarrier carrier;
Adafruit_SHT4x sht4 = Adafruit_SHT4x();

void setup() {
  Serial.begin(115200);

  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit SHT4x test");
  if (! sht4.begin()) {
    Serial.println("Couldn't find SHT4x");
    while (1) delay(1);
  }
  Serial.println("Found SHT4x sensor");
  Serial.print("Serial number 0x");
  Serial.println(sht4.readSerial(), HEX);

  // You can have 3 different precisions, higher precision takes longer
  sht4.setPrecision(SHT4X_HIGH_PRECISION);
  switch (sht4.getPrecision()) {
     case SHT4X_HIGH_PRECISION: 
       Serial.println("High precision");
       break;
     case SHT4X_MED_PRECISION: 
       Serial.println("Med precision");
       break;
     case SHT4X_LOW_PRECISION: 
       Serial.println("Low precision");
       break;
  }

  // You can have 6 different heater settings
  // higher heat and longer times uses more power
  // and reads will take longer too!
  sht4.setHeater(SHT4X_NO_HEATER);
  switch (sht4.getHeater()) {
     case SHT4X_NO_HEATER: 
       Serial.println("No heater");
       break;
     case SHT4X_HIGH_HEATER_1S: 
       Serial.println("High heat for 1 second");
       break;
     case SHT4X_HIGH_HEATER_100MS: 
       Serial.println("High heat for 0.1 second");
       break;
     case SHT4X_MED_HEATER_1S: 
       Serial.println("Medium heat for 1 second");
       break;
     case SHT4X_MED_HEATER_100MS: 
       Serial.println("Medium heat for 0.1 second");
       break;
     case SHT4X_LOW_HEATER_1S: 
       Serial.println("Low heat for 1 second");
       break;
     case SHT4X_LOW_HEATER_100MS: 
       Serial.println("Low heat for 0.1 second");
       break;
  }
  
}


void loop() {
  sensors_event_t humidity, temp;
  
  uint32_t timestamp = millis();
  sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  timestamp = millis() - timestamp;

  Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");

  Serial.print("Read duration (ms): ");
  Serial.println(timestamp);

  delay(1000);
}

Thank you for any tips and help! :]

krystof18
  • 315
  • 4
  • 10

0 Answers0