I have seen that the nRF52840 has a build-in temperature sensor. Is there an Arduino library to access it, or somebody has developed some function that I could reuse ?
I see also that there is a complex linearity function mechanisms, Is it mandatory to calibrate it ? and in this case what should be the calibration algorithm ?
So I used it in m|y sensor node code demo’s
it’s available without any schinanigans..
You can access the nRF52840’s internal die temperature sensor quite easily in Arduino without needing a heavy external library. The Nordic core exposes the hardware registers directly, or you can use the built-in temperature_sensing functions if you are using the Adafruit nRF52 BSP.
Here is a short, clean example showing both the direct register method (which works universally on nRF52) and the standard API method.
#include <Arduino.h>
// If using the Adafruit nRF52 core, this built-in function is often available:
// extern "C" int32_t read_temperature(void);
void setup() {
Serial.begin(115200);
while (!Serial) delay(10); // Wait for Serial Monitor
Serial.println("nRF52840 Internal Temperature Sensor Test");
// Initialize the internal TEMP peripheral registers directly
NRF_TEMP->TASKS_START = 1;
}
void loop() {
// Trigger a new temperature measurement
NRF_TEMP->TASKS_START = 1;
// Wait for the measurement to complete (DATARDY event)
while (NRF_TEMP->EVENTS_DATARDY == 0) {
// Busy wait or yield
}
NRF_TEMP->EVENTS_DATARDY = 0; // Clear the event flag
// Read the raw value (0.25°C steps)
int32_t raw_temp = NRF_TEMP->TEMP;
// Convert to actual Celsius (divide by 4.0 or multiply by 0.25)
float celsius = raw_temp * 0.25;
Serial.print("Internal Die Temp: ");
Serial.print(celsius);
Serial.println(" °C");
delay(2000); // Read every 2 seconds
}
As far as the factory ca, short answer is NO.
" Do you need to implement a complex calibration algorithm?
No, it is not mandatory for standard applications. The “complex linearity function” you read about in the Nordic datasheets is actually already handled in the hardware factory calibration. "
Worked the first time before I posted it. and It works now.
so I would summarize the problem exists between the Keyboard and the floor. This is the area of concern. (but only slightly)
compiler output;
FQBN: Seeeduino:mbed:xiaonRF52840
Using board 'xiaonRF52840' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.3
Using core 'arduino' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.3
"" EDIT for brevity ""
Zip created at C:\Users\Dude\AppData\Local\arduino\sketches\81B678104D35C6047702629EAAB5AB42/sketch_may26a.ino.zip
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-size" -A "C:\\Users\\Dude\\AppData\\Local\\arduino\\sketches\\81B678104D35C6047702629EAAB5AB42/sketch_may26a.ino.elf"
Sketch uses 84712 bytes (10%) of program storage space. Maximum is 811008 bytes.
Global variables use 43944 bytes (18%) of dynamic memory, leaving 193624 bytes for local variables. Maximum is 237568 bytes.
Performing 1200-bps touch reset on serial port COM9
Waiting for upload port...
Upload port found on COM11
---
Opened serial port COM11
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 84720
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
########################################
########################################
######
Activating new firmware
DFU upgrade took 5.745628118515015s
Device programmed.
followed by the serial output of the TEMP
nRF52840 Internal Temperature Sensor Test
Internal Die Temp: 30.50 °C
Internal Die Temp: 30.50 °C
Internal Die Temp: 30.50 °C
Internal Die Temp: 30.50 °C
Internal Die Temp: 30.50 °C
Internal Die Temp: 30.50 °C