Skip to content

InternetOfPins/OneSensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

OneSensor

HAPI Compatibility: Works with new Check/Apply/ApplyPack API (2026-Q2)

HAPI sensor driver components — parameterized on bus and chip at compile time. Zero dynamic allocation, pure-static dispatch.

Part of the InternetOfPins project family.

Overview

Each sensor is a HAPI component. The bus (I2C, 1-Wire) is injected as a template parameter, so the same driver works across AVR, ESP32, and any other target that provides a compatible bus implementation.

Drivers in this library depend on OneBus for bus types. For drivers that live directly in a project without the OneBus dependency, see the standalone versions in OneIO (oneIO/sensor/).

Drivers

DS18B20 — 1-Wire temperature sensor

#include <oneSensor/temperature/ds18b20.h>
#include <oneBus/oneWire.h>

// OneWire bus: Arduino pin 4 (any target)
using Bus  = oneBus::OneWire<4>;
using Temp = oneSensor::DS18B20<Bus>;
using Api  = Temp::Api;  // hapi::APIOf<SensorDef, DS18B20<Bus>>

Api::begin();

// Non-blocking: trigger, wait 750 ms, read
Api::trigger();
// ... do other work for 750 ms ...
auto r = Api::read();
if (r.ok) printf("%.2f °C\n", r.tempC());

// Blocking: trigger + wait + read in one call
auto r2 = Api::sample();

For AVR with cycle-accurate timing:

#include <oneBus/oneWire.h>
#include <chips/avr/avrPort.h>

using Bus = oneBus::AvrOneWire<hw::avr::chip::PortC, 4>;  // PC4 = A4
using Api = oneSensor::DS18B20<Bus>::Api;

MPU6050 — I2C 6-axis IMU

#include <oneSensor/imu/mpu6050.h>

// TwiMaster: any compatible I2C master (AvrTwiMaster, ArduinoWire, ...)
using Imu = oneSensor::MPU6050<TwiMaster>;
using Api = Imu::Api;

Api::begin();          // wakes device, sets default gyro/accel ranges
auto r = Api::read();  // burst-read 14 bytes, returns Reading

printf("ax=%d ay=%d az=%d\n", r.ax, r.ay, r.az);
printf("gx=%d gy=%d gz=%d\n", r.gx, r.gy, r.gz);
printf("temp=%.2f °C\n", r.tempC());

// Optional: change full-scale range before begin()
Api::setGyroRange(oneInput::MPU6050<TwiMaster>::GyroRange::Deg500);
Api::setAccelRange(oneInput::MPU6050<TwiMaster>::AccelRange::G8);

Default I2C address is 0x68 (AD0 low). Use MPU6050<TwiMaster, 0x69> when AD0 is pulled high.

Usage summary

#include <oneSensor/oneSensor.h>  // includes all sensor headers

Sensors expose Api as a pre-assembled hapi::APIOf<> type. Call static methods directly on Api — no object needed. Multiple sensors on the same bus coexist because each driver controls its own CS / ROM ID; they share the bus type without interference.

Dependencies

  • HAPI
  • OneBus — bus types (OneWire, AvrTwiMaster, ...)
  • OneChip — for AVR port types used by AvrOneWire

License

MIT — see LICENSE.

Author: Rui Azevedo (neu-rah) · Azores, Portugal

About

HAPI sensor driver components — parameterized on bus and chip

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors