This should work on all Gen 3 devices (Argon, Boron, Xenon, B Series SoM):
#include "Particle.h"
// Optional:
// SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler;
void setup() {
}
void loop() {
// Get die temperature in 0.25 degrees Celsius. Takes 50 us to complete.
int32_t temp;
uint32_t res = sd_temp_get(&temp);
if (res == NRF_SUCCESS) {
float tempC = (float)temp / 4;
float tempF = tempC * 9 / 5 + 32;
Log.info("tempC=%.1f tempF=%.1f", tempC, tempF);
}
else {
Log.error("failed to get temperature");
}
delay(2000);
}
Output:
0000011269 [app] INFO: tempC=29.8 tempF=85.6
0000013271 [app] INFO: tempC=29.8 tempF=85.6