This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:software:homelab:library:module:sensor [2010/02/08 12:53] – mikk.leini | en:software:homelab:library:module:sensor [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Sensors ====== | ====== Sensors ====== | ||
- | //Seotud mooduliga: [HW] [[en: | + | //Related to: [HW] [[en: |
- | See teegi osa sisaldab kodulabori andurite kasutamise funktsioone. | + | This library contains functions to use different sensors in the HomeLab kit. |
- | ===== Andmetüübid | + | ===== Data Types ===== |
- | * **// | + | * **// |
- | * //a// - jagatav. | + | Infrared distance sensor distance calculation parameters structure. Formula for distance calculation is //a / (ADC + b) - k//. Structure members: |
- | * //b// - vabaliige. | + | * //a// - Dividend. |
- | * //k// - korrigeerimiskonstant. | + | * //b// - Non-linear constant. |
+ | * //k// - Linearizing constant. | ||
- | ===== Konstandid | + | ===== Constants |
- | * **// | + | * **// |
+ | | ||
- | ===== Funktsioonid | + | ===== Functions |
* **//signed short thermistor_calculate_celsius(unsigned short adc_value)// | * **//signed short thermistor_calculate_celsius(unsigned short adc_value)// | ||
- | | + | |
- | * // | + | * // |
- | * Tagastab temperatuuri Celsiuse kraadides | + | * 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)// | * **//signed short ir_distance_calculate_cm(ir_distance_sensor sensor, unsigned short adc_value)// | ||
- | | + | |
- | * //sensor// - Kaugusanduri parameetrite struktuuri objekt. | + | * //sensor// - Distance sensor calculation parameters. |
- | * // | + | * // |
- | * Tagastab kauguse sentimeetrites või -1, kui seda ei saanud arvutada. | + | * Returns distance in centimeters or -1 if it cannot be calculated. |
- | * **// | + | * **// |
- | | + | |
- | * //trigger// - päästiku viigu muutuja. | + | * //trigger// - Trigger pin variable. |
- | * //echo// - kaja viigu muutuja. | + | * //echo// - Echo pin variable. |
- | * Tagastab kauguse sentimeetrites või 0, kui mõõtmine ebaõnnestus. | + | * Returns distance in centimeters or 0 when measuring failed. |
+ | * **// | ||
+ | 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: | ||
+ | * // | ||
+ | * Returns distance in centimeters or 0 when measuring failed. | ||
- | ===== Näide | + | ===== Example |
+ | |||
+ | The following program demonstrates usage of IR and ultrasonic distance sensor SRF05. | ||
<code c> | <code c> | ||
#include < | #include < | ||
- | // Ultraheli kaugusmõõdiku juhtviigud | + | // Ultrasonic distance sensor control pins. |
- | pin pin_trigger = PIN(G, 1); | + | pin pin_triggerecho |
- | pin pin_echo | + | |
int main(void) | int main(void) | ||
{ | { | ||
- | unsigned short adc_value = 400; // näidisväärtus | + | unsigned short adc_value = 400; // random ADC result. |
signed short distance; | signed short distance; | ||
- | // IR kaugusanduri | + | // Distance calculation from IR distance sensor |
distance = ir_distance_calculate_cm(GP2Y0A21YK, | distance = ir_distance_calculate_cm(GP2Y0A21YK, | ||
- | // Ultraheli-kaugusanduriga mõõtmine | + | // Measuring with ultrasonic distance sensor. |
- | distance = ultrasonic_measure(pin_trigger, | + | distance = ultrasonic_measure_srf05(pin_triggerecho); |
} | } | ||
</ | </ | ||
- |