Skip to content

Commit

Permalink
increase resolution of measurements to 0.01
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Oct 25, 2023
1 parent 041b67f commit 2d747b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ void read_sensor_and_save() {

read_sensor(&temp,&humi);
// printf("Temp: %d.%d, humid: %d\r\n", temp/10, temp % 10, humi);
g_zcl_temperatureAttrs.measuredValue = temp * 10;
g_zcl_relHumidityAttrs.measuredValue = humi * 100;
g_zcl_temperatureAttrs.measuredValue = temp;
g_zcl_relHumidityAttrs.measuredValue = humi;

voltage = drv_get_adc_data();
converted_voltage = (u8)(voltage / 100);
Expand Down
10 changes: 5 additions & 5 deletions src/shtv3_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ u8 measure_cmd[] = {0xfd};
//Since we now got version B1.4 B1.6 and B1.9 of the Thermometer we need to detect the correct sensor it is using
// B1.4 = SHTC3 = 0 = address 0x70/0xE0
// B1.6 and B1.9 = SHV4 = 1 = address 0x44/0x88
_attribute_data_retention_ u8 sensor_version;
_attribute_data_retention_ u8 sensor_version = 2; // unknown
_attribute_data_retention_ u8 i2c_address_sensor = 0xE0;

void init_sensor(){
Expand Down Expand Up @@ -57,8 +57,8 @@ void read_sensor(s16 *temp, u16 *humi) {
reg_i2c_mode &= ~FLD_I2C_HOLD_MASTER;// Disable clock stretching for Sensor
send_i2c(i2c_address_sensor,sens_sleep, sizeof(sens_sleep));

*temp = ((1750*(read_buff[0]<<8 | read_buff[1]))>>16)-450;
*humi = (100 *(read_buff[3] << 8 | read_buff[4]))>>16;
*temp = (s16)(((17500 * ((u32)read_buff[0] << 8 | (u32)read_buff[1])) >> 16) - 4500);
*humi = (u16)(10000 * ((u32)read_buff[3] << 8 | (u32)read_buff[4])) >> 16;

}else if(sensor_version == 1){
send_i2c(i2c_address_sensor,measure_cmd, sizeof(measure_cmd));
Expand All @@ -67,8 +67,8 @@ void read_sensor(s16 *temp, u16 *humi) {
i2c_set_id(i2c_address_sensor);
i2c_read_series(0, 0, (u8*)read_buff, 5);

*temp = ((1750*(read_buff[0]<<8 | read_buff[1]))>>16)-450;
*humi = (((1250 *(read_buff[3] << 8 | read_buff[4]))>>16)-60)/10;
*temp = (s16)(((17500 * ((u32)read_buff[0] << 8 | (u32)read_buff[1])) >> 16) - 4500);
*humi = (u16)(((12500 * ((u32)read_buff[3] << 8 | (u32)read_buff[4])) >> 16) - 600);

}else if(sensor_version == 2){

Expand Down

0 comments on commit 2d747b9

Please sign in to comment.