writing sensor lib - shunyaos/shunyainterfaces GitHub Wiki
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.
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.
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.
Click me to reveal the details.
-
Setup/Init/Begin
Makes the sensor Ready for sensing-
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. -
Calibration
Sensors do not give accurate measurement, we need to adjust the sensor to get accurate measurement, The adjustment process is called calibration.
-
-
Reading sensor data
-
Reading raw Data/ Getting raw data
Access the Sensor Register(Memory) and read raw data from it. -
Calculating Values/ Compensate Values
Convert raw data to Human readable data.
-
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
- Configuration
- Calibration
- Reading Data from the Sensor
- 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