Temperature code into Light Lightness Server code

Hi 

I am using sht85 to detect temperature/humidity in my Light lightness server code

 In the original server code, by pressing 1 or 2 you get to either decrease or increase the lightness level respectively. I modified the code so that when number 3 is pressed, both temperature and humidity will be display in the J-Link

This is the code for button number 3

 if(button_number == 3)
    {
              int32_t temperature, humidity;
               int32_t temp_read, hum_read;
                  char temp_str[5];
                  char hum_str[5];
        
           int8_t ret = sht3x_measure_blocking_read(SHT3X_I2C_ADDR_DFLT,
                                                 &temperature, &humidity);
               if (ret == STATUS_OK) {
                temp_read = temperature / 1000;
                hum_read = humidity / 1000; 
                  
                itoa(temp_read, temp_str,10);
                 itoa(hum_read, hum_str, 10);
                  
         

              }
          __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature: %d\n", temp_str);
         __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Humidity: %d\n", hum_str);
      }   

However, The display in J-Link is not what I had expected

The temperature and Humidity values are extremely high. Is there something I am doing wrong in the code? If so, please advise on what to change. Thank you!

Parents
  • Hi,

    It looks like you are printing the RAM address to where 'temp_str' and 'hum_str' are stored in RAM rather than printing the content of those arrays. Try this instead:

     if(button_number == 3)
        {
                  int32_t temperature, humidity;
                   int32_t temp_read, hum_read;
                      char temp_str[5];
                      char hum_str[5];
            
               int8_t ret = sht3x_measure_blocking_read(SHT3X_I2C_ADDR_DFLT,
                                                     &temperature, &humidity);
                   if (ret == STATUS_OK) {
                    temp_read = temperature / 1000;
                    hum_read = humidity / 1000; 
                      
                      
                    // itoa(temp_read, temp_str,10); // Reduntant. The __LOG macro will do the conversion
                    // itoa(hum_read, hum_str, 10);
                      
             
    
                  }
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature: %d\n", temperature);
             __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Humidity: %d\n", humidity);
          }   

    Best regards,

    Vidar

Reply
  • Hi,

    It looks like you are printing the RAM address to where 'temp_str' and 'hum_str' are stored in RAM rather than printing the content of those arrays. Try this instead:

     if(button_number == 3)
        {
                  int32_t temperature, humidity;
                   int32_t temp_read, hum_read;
                      char temp_str[5];
                      char hum_str[5];
            
               int8_t ret = sht3x_measure_blocking_read(SHT3X_I2C_ADDR_DFLT,
                                                     &temperature, &humidity);
                   if (ret == STATUS_OK) {
                    temp_read = temperature / 1000;
                    hum_read = humidity / 1000; 
                      
                      
                    // itoa(temp_read, temp_str,10); // Reduntant. The __LOG macro will do the conversion
                    // itoa(hum_read, hum_str, 10);
                      
             
    
                  }
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature: %d\n", temperature);
             __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Humidity: %d\n", humidity);
          }   

    Best regards,

    Vidar

Children
No Data
Related