Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative temperature values when temperature must be positive #7

Open
T365 opened this issue Aug 14, 2024 · 3 comments
Open

Negative temperature values when temperature must be positive #7

T365 opened this issue Aug 14, 2024 · 3 comments
Assignees

Comments

@T365
Copy link

T365 commented Aug 14, 2024

Temperature readings are ok, but sometimes it suddenly gets negative values between others,
last readings in summer where 26° , 24° , 22° , 26°, 28° then -26° -22° then 29° , 26° ...
very strange, when I use sht4x.measureHighPrecision(temperature, humidity);
maybe I have to wait for a while (seconds) to get the right value before I send it with LORA ?

@sdmueller
Copy link

Hi @T365

According to the datasheet, the maximum time a high precision measurement takes is 8.3ms (see Chapter 3.1 Timings).

Are these the readings directly from the SHT4x (i.e. before sending them further)?
And does it happen with low or medium precision as well?

@sdmueller sdmueller self-assigned this Aug 16, 2024
@T365
Copy link
Author

T365 commented Aug 16, 2024

Thank you for your answer,
Yes, first I read the value and put it in a variable, then handle other things,
before I send it.
There are 15 devices that are active outside as demo , and 3 of them sometimes give those strange values.
The others perform well, all the devices have the same hardware, and software.
Other sensors and data have no problems.

  • data temperature +30 for no negative numbers
  • multiply by 1000 for comma shift.
  • measures done on different times a day.

,
My Arduino code (not complete):

struct Measure {
	float temperature;
	float humidity;
	uint8_t temperature_lowbits;
	uint8_t temperature_highbits;
	uint8_t humidity_lowbits;
	uint8_t humidity_highbits;
};

RTC_DATA_ATTR Measure measure_cold = { 0, 0, 0, 0, 0, 0 };
RTC_DATA_ATTR Measure measure_hot = { 0, 0, 0, 0, 0, 0 };
}


SensirionI2cSht4x sht4x;

float roundToTwoDecimals(float number) {
    return round(number * 100) / 100.0;
}

void GetTemperatures(float* mytemperature, float* myhumidity) {

    float temperature = 0;
    float humidity = 0;

    uint16_t error;
    char errorMessage[256];

    sht4x.begin(Wire, 0x44);
    error = sht4x.measureHighPrecision(temperature, humidity);

    if (error != 0) {
        if (DEBUG) {
            debugln("Error trying to execute measureMediumPrecision(): ");
            errorToString(error, errorMessage, 256);
            debugln(errorMessage);
        }
        temperature = 0;
        humidity = 0;
    }

    // adjust temperature value by adding 30 frost compensation
    *mytemperature = roundToTwoDecimals(temperature); 
    *myhumidity = roundToTwoDecimals(humidity);
}

float temperature = 0;
float humidity = 0;

uint16_t error;
char errorMessage[256];

sht4x.begin(Wire, 0x44);
error = sht4x.measureHighPrecision(temperature, humidity);

if (error != 0) {
    if (DEBUG) {
        debugln("Error trying to execute measureMediumPrecision(): ");
        errorToString(error, errorMessage, 256);
        debugln(errorMessage);
    }
    temperature = 0;
    humidity = 0;
}

// adjust temperature value by adding 30 frost compensation
*mytemperature = roundToTwoDecimals(temperature); 
*myhumidity = roundToTwoDecimals(humidity);
}
LORA:

	uint8_t* pointers[] = {
		&mydata[0],  // DeviceNr_HIGH
		&mydata[1],  // DeviceNr_LOW
		&mydata[2],  // PIR_Count_HIGH
		&mydata[3],  // PIR_Count_LOW
		&mydata[4],  // Voltage_HIGH
		&mydata[5],  // Voltage_LOW
		&mydata[6],  // Distance_HIGH
		&mydata[7],  // Distance_LOW
		&mydata[8],  // Sensor_Temperature_HIGH
		&mydata[9],  // Sensor_Temperature_LOW

more....
};

Measure measure = measureprobes();

// Assign values through pointers
*(uint8_t*)(pointers[0]) = DeviceNr_HIGH;
*(uint8_t*)(pointers[1]) = DeviceNr_LOW;
*(uint8_t*)(pointers[2]) = PIR_Count_HIGH;
*(uint8_t*)(pointers[3]) = PIR_Count_LOW;
*(uint8_t*)(pointers[4]) = ADC_HIGH;
*(uint8_t*)(pointers[5]) = ADC_LOW;
*(uint8_t*)(pointers[6]) = Distance_HIGH;
*(uint8_t*)(pointers[7]) = Distance_LOW;
*(uint8_t*)(pointers[8]) = measure_hot.temperature_highbits;
*(uint8_t*)(pointers[9]) = measure_hot.temperature_lowbits;
*(uint8_t*)(pointers[10]) = measure_cold.temperature_highbits;
*(uint8_t*)(pointers[11]) = measure_cold.temperature_lowbits;
*(uint8_t*)(pointers[12]) = measure_hot.humidity_highbits;
*(uint8_t*)(pointers[13]) = measure_hot.humidity_lowbits;
more.....
```

@LeonieFierz
Copy link
Member

Hi @T365
is the temperature already negative in the temperature and humidity variables after the call to sht4x.measureHighPrecision(...)? How do you convert from float values to pointer measure_hot.temperature_highbits / pointer measure_hot.temperature_lowbits?
Best, Léonie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants