Onboard Temperature from nRF52840

xenon
boron
argon
Tags: #<Tag:0x00007fe21eb04598> #<Tag:0x00007fe21eb043e0> #<Tag:0x00007fe21eb04228>

#1

Feature request:Onboard Temperature from nRF52840

I know the nRF52840 has a really accurate onboard temperature sensor. It would be great if we could get the temperature of the MCU.
When combined with plenty of sleep cycles (keep the MCU cold) I’ve found these temperatures to be within a few degrees of atmosphere.
Here are the registry details for the MCU

I don’t really know much about the particle core but this should be an easy feature to implement.


#2

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

#3

Killer. Got it working right off the bat.
Would be great if this was a system call or advanced I/O.