Sensors

Related to: [HW] Sensors Module

This library contains functions to use different sensors in the HomeLab kit.

Data Types

  • ir_distance_sensor

Infrared distance sensor distance calculation parameters structure. Formula for distance calculation is a / (ADC + b) - k. Structure members:

  • a - Dividend.
  • b - Non-linear constant.
  • k - Linearizing constant.

Constants

  • ir_distance_sensor GP2Y0A21YK

Sharp GP2Y0A21YK distance calculation formula parameters.

Functions

  • signed short thermistor_calculate_celsius(unsigned short adc_value)

Calculates thermistor temperature in Celsius degrees from ADC conversion result. Functions use pre-calculated conversion table. Parameters:

  • adc_value - ADC conversion result (10-bit with +5 V reference voltage)..
  • Returns temperature in Celsius degrees in the -20 to 100 degrees limit.
  • signed short ir_distance_calculate_cm(ir_distance_sensor sensor, unsigned short adc_value)

Calculates distance from ADC result received from IR distance sensor voltage. Parameters:

  • sensor - Distance sensor calculation parameters.
  • adc_value - ADC conversion result (10-bit with +5 V reference voltage).
  • Returns distance in centimeters or -1 if it cannot be calculated.
  • unsigned short ultrasonic_measure_srf04(pin trigger, pin echo)

Measures distance with ultrasonic distance sensor SRF04. Function generates a trigger pulse on one pin and measures the time of echo pulse on another pin. Distance is calculated from the time. Function expects a 14.7456 MHz clock frequency. Measuring may take up to 36 ms. Parameters:

  • trigger - Trigger pin variable.
  • echo - Echo pin variable.
  • Returns distance in centimeters or 0 when measuring failed.
  • unsigned short ultrasonic_measure_srf05(pin trigger_echo)

Measures distance with ultrasonic distance sensor SRF05 in one wire regime. Function generates a trigger pulse on the pin and measures the time of echo pulse on the same pin. Distance is calculated from the time. Function expects a 14.7456 MHz clock frequency. Measuring may take up to 36 ms. Parameters:

  • trigger_echo - Trigger/Echo combined pin variable.
  • Returns distance in centimeters or 0 when measuring failed.

Example

The following program demonstrates usage of IR and ultrasonic distance sensor SRF05.

#include <homelab/module/sensors.h>
 
// Ultrasonic distance sensor control pins.
pin pin_triggerecho    = PIN(G, 0);
 
int main(void)
{
	unsigned short adc_value = 400; // random ADC result.
	signed short distance;
 
	// Distance calculation from IR distance sensor ADC result.
	distance = ir_distance_calculate_cm(GP2Y0A21YK, adc_value);
 
	// Measuring with ultrasonic distance sensor.
	distance = ultrasonic_measure_srf05(pin_triggerecho);
}
en/software/homelab/library/module/sensor.txt · Last modified: 2020/07/20 09:00 by 127.0.0.1
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0