pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
    • Playground
  • Development
    • The pbl CLI
    • Build system
    • Samples
      • Threads
      • Mutexes
      • Semaphores
      • Message queues
      • Poll groups
      • Timers
      • Work queues
      • Delayed work
      • Heaps
      • Time
      • Dining philosophers
      • Bounded buffer
      • Readers and writers
      • Sleeping barber
      • Priority inversion
      • Barrier
      • Input events
      • Accelerometer
      • Ambient light
      • Backlight
      • Battery
      • Display
      • Flash
      • Magnetometer
      • Microphone
      • External RAM
      • Random numbers
      • Real-time clock
      • Speaker
      • Die temperature
      • Touchscreen
      • Vibration
      • Kernel benchmark
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
    • Subsystems
    • Drivers
    • Services
    • Libraries
    • Third-party
    • Application SDK
  • Hardware
    • Boards
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

Die temperature

This sample reads the temperature of the chip five times, a second apart, through DIE_TEMP: the board’s die temperature sensor, whatever drives it. pbl_temp_read() gives millidegrees Celsius.

On a watch the reading follows the chip, a few degrees above the room and rising under load. The emulator’s simulated sensor reads a fixed 25 C.

Run:

pbl samples samples/drivers/temp

Boards:

every board

Sources

src/main.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <pbl/drivers/temp.h>
#include <pbl/kernel/delay.h>

#define READS 5

int main(void) {
  for (int i = 0; i < READS; i++) {
    int32_t millicelsius;
    int ret;

    /* DIE_TEMP is the board's die temperature sensor, whatever drives it. */
    ret = pbl_temp_read(DIE_TEMP, &millicelsius);
    if (ret != 0) {
      fprintf(stderr, "temp: read failed (%d)\n", ret);
      return ret;
    }

    printf("temp: %s%d.%d C\n", millicelsius < 0 ? "-" : "", (int)(abs(millicelsius) / 1000),
           (int)(abs(millicelsius) % 1000 / 100));

    pbl_sleep_ms(1000);
  }

  printf("Sample done\n");

  return 0;
}

Output

temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
Sample done

Generated from PebbleOS 9e782207f. This page is maintained in the pebbleos repository: docs/samples/drivers/temp.md.

Overview

  • Sources
  • Output