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
      • Kernel
      • Subsystems
      • Drivers
      • Third-party
      • Rust
      • Benchmarks
    • 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

Pressure: Air pressure readings

This sample reads the air pressure five times, a second apart, through PRESSURE: the board’s pressure sensor, whatever drives it. pbl_pressure_read() gives pascals; the sample prints hectopascals.

The reading is the pressure where the watch is, not corrected to sea level, so it is lower than a weather report’s by about 1.2 hPa for every 10 m of altitude. Only boards with a pressure sensor run it; the emulator has none.

Run:

pbl samples samples/drivers/pressure

Boards:

every board

Sources

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

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

#define READS 5

int main(void) {
  for (int i = 0; i < READS; i++) {
    uint32_t pa;
    int ret;

    /* Each read runs one conversion; the sensor sleeps in between. */
    ret = pbl_pressure_read(PRESSURE, &pa);
    if (ret != 0) {
      fprintf(stderr, "pressure: read failed (%d)\n", ret);
      return ret;
    }

    printf("pressure: %d.%02d hPa\n", (int)(pa / 100U), (int)(pa % 100U));

    pbl_sleep_ms(1000);
  }

  printf("Sample done\n");

  return 0;
}

Output

pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
Sample done

Generated from PebbleOS 4bbc630fa. This page is maintained in the pebbleos repository: docs/samples/drivers/pressure.md.

Overview

  • Sources
  • Output