writing sensor lib - shunyaos/shunyainterfaces GitHub Wiki

Introduction

This guide will help you

  • Understand Sensors
  • Write sensor libraries for shunya-interfaces

Note: This guide is designed for audience which may not know the basics. So feel free to skip stuff.

What is a sensor ?

Click me to reveal the details.

Sensor is a device which senses parameters available in nature.
Parameters can be air temperature, air pressure, light intensity, etc.

Sensor-Internals

All these parameters found in nature are in analog form i.e (a range of values)

For example:
Temperature range = 15 to 50 degC
Pressure range = 0 to 20 Pa

But all our devices which process them are in digital form, so Sensors contain internal ADC's (Analog to Digital Converters) to convert analog value to digital.

Advanced Sensors also contain memory to store these digital values. This memory is called registers.

Advanced Sensors use these registers to store data as well as configuration.

Logical flow of Reading data from sensor

Click me to reveal the details.

Sensor_flow-Page-2

  1. Setup/Init/Begin
    Makes the sensor Ready for sensing

    1. Configuration
      Advanced sensors may have different option that need to be set before we start reading data from it. Simple sensors may not require Configuration.

    2. Calibration
      Sensors do not give accurate measurement, we need to adjust the sensor to get accurate measurement, The adjustment process is called calibration.

  2. Reading sensor data

    1. Reading raw Data/ Getting raw data
      Access the Sensor Register(Memory) and read raw data from it.

    2. Calculating Values/ Compensate Values
      Convert raw data to Human readable data.

How to write a Sensor library for shunya-interfaces ?

Step 1: Search for Arduino code or library

Step 2: Understand the flow

Step 3: Divide all the given C/C++ functions into 4 blocks

  1. Configuration
  2. Calibration
  3. Reading Data from the Sensor
  4. Converting raw data

Step 4: Cleanup unnecessary function and variables and convert code to C from C++

Step 5: Put all these functions into sensor-name.c file

Step 6: List the function names into sensor-name.h file

Step 7: Write an example code to test all these functions called

Examples :

  1. INA19
  2. BH1750 (Comming Soon)
⚠️ **GitHub.com Fallback** ⚠️