This shows you the differences between two versions of the page.
uphp:functions:adc_read [2017/03/28 19:59] jeff |
uphp:functions:adc_read [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======adc_read====== | ||
- | < | ||
- | |||
- | Read an onboard <tooltip title=" | ||
- | |||
- | ====Description==== | ||
- | <well size=" | ||
- | <span style=" | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | Return the raw <tooltip title=" | ||
- | |||
- | ====Parameter==== | ||
- | < | ||
- | |||
- | Channel 0 is attached to pin <tooltip title=" | ||
- | |||
- | Channel 1 is connected to pin A2 which can handle up to 330V DC. | ||
- | |||
- | Channel 2 is connected to pin A3, which reads 0-5V DC. | ||
- | |||
- | ====Return Value==== | ||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Examples==== | ||
- | **Example #1** - Read Channel 0 and use the constants v_adc_offset and v_adc_mul to obtain a calibrated voltage((**Example #1** demonstrates a legacy method to obtain a calibrated voltage, which was the primary method in early Wattmon releases, and has not yet been removed from the OS. The calibration constants are loaded automatically into [[uphp: | ||
- | |||
- | <code php> | ||
- | < | ||
- | $adc=adc_read(0); | ||
- | $volts=floatval($_GLOBALS[' | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | ?></ | ||
- | </ | ||
- | |||
- | Typical output for the above example (results vary depending on actual voltage and calibration constants): | ||
- | < | ||
- | adc=192 | ||
- | v_adc_offset=24.811435 | ||
- | v_adc_mul=0.065411 | ||
- | volts=14.181854 | ||
- | </ | ||
- | |||
- | ====Additional Information==== | ||
- | The raw ADC values can be accessed using [[adc_read()]], | ||
- | |||
- | **Example #2** - Use [[mb_get_dev_by_id()]] to obtain calibrated values for A1, A2 and A3: | ||
- | |||
- | <code php> | ||
- | < | ||
- | $dev=mb_get_dev_by_id(0); | ||
- | $a1=$dev[' | ||
- | $a2=$dev[' | ||
- | $a3=$dev[' | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | ?></ | ||
- | </ | ||
- | |||
- | Typical output for the above example (results vary depending on actual voltage and calibration constants): | ||
- | < | ||
- | A1=13.600001 V | ||
- | A2=2.100000 V | ||
- | A3=4.980000 V | ||
- | </ | ||
- | |||
- | ====See Also==== | ||
- | [[uphp: | ||
- | |||
- | [[floatval()]] - Return the floating point value of a number or string | ||