LowPowerLab Forum

Hardware support => Moteino => Topic started by: Neko on July 24, 2017, 09:44:41 PM

Title: radio.readTemperature problem
Post by: Neko on July 24, 2017, 09:44:41 PM
In the example sketch, Gateway, there is a command to read the LFM69 temperature:

byte Temperature = radio.readTemperature(-1);

I am getting a fixed reading of 164C on a variety of Moteino's, which means that REG_TEMP2 is coming back as 255 each time (after adding back COURSE_TEMP_COEF (-90) and calFactor (-1). Is there something I need to do to get a proper reading?
Title: Re: radio.readTemperature problem
Post by: ChemE on July 24, 2017, 10:09:21 PM
Try this code and see if you are able to get reliable results:


// Return the temperature x 10 in C. Leaves the radio in sleep mode once done to save power
static inline int16_t RadioGetTemp(void) {
  uint16_t total;
  writeReg( REG_OPMODE, SYNTHESIZER_MODE );         // Radio must be in standby or synthesizer to measure               
  for( uint8_t cnt=40; cnt; cnt-- ) {
    writeReg( REG_TEMP1, RF_TEMP1_MEAS_START );     // Initiate a temperature conversion
    while ( readReg( REG_TEMP1 ));                  // Wait for the result to be ready
    total += (uint8_t) ~readReg( REG_TEMP2 ) - 91;  // Add the current result to the running total
  }                                                 // Take 40 such temperature readings
  writeReg( REG_OPMODE, SLEEP_MODE );               // Place radio in sleep mode to save power
  return( (total+2)>>2 );                           // Return temp x 10 in C and account for rounding error
}
Title: Re: radio.readTemperature problem
Post by: Neko on July 24, 2017, 10:46:40 PM
Yup. Working now.

Thanks.
Title: Re: radio.readTemperature problem
Post by: ChemE on July 24, 2017, 11:30:13 PM
My pleasure!
Title: Re: radio.readTemperature problem
Post by: joelucid on July 25, 2017, 03:23:48 PM
Just an FYI: the temp sensor on the sx1231h measures incorrect temperatures in some circumstances. Typically this problem shows when the radio was just about to rx a packet before you measure. In that case you'll measure a pretty random sequence of numbers instead of the correct temp. I've found it necessary to wait until I get 20 measurements within a range of +-1 before I conclude I actually have a valid temperature.

Joe