Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:846e2321c637 1 #include "mbed.h"
Rhyme 0:846e2321c637 2 #include "PSE530.h"
Rhyme 0:846e2321c637 3
Rhyme 0:846e2321c637 4 /**
Rhyme 0:846e2321c637 5 * SMC PSE530 pressure sensor
Rhyme 0:846e2321c637 6 * analog output 1.0V - 5.0V
Rhyme 0:846e2321c637 7 * 1.0V : 0
Rhyme 0:846e2321c637 8 * 5.0V : 1MPa
Rhyme 0:846e2321c637 9 * (at 0.6V : -0.1MPa)
Rhyme 0:846e2321c637 10 * Our sensor I/F converts 0-5V to 0-3V
Rhyme 0:846e2321c637 11 * So we suppose V = Analog Float Value : Pressure
Rhyme 0:846e2321c637 12 * 0.6V = 0.2 : 0
Rhyme 0:846e2321c637 13 * 3.0V = 1.0 : 1MPa
Rhyme 0:846e2321c637 14 */
Rhyme 0:846e2321c637 15
Rhyme 0:846e2321c637 16 /**
Rhyme 0:846e2321c637 17 * conversion from Pa to kgf/cm2
Rhyme 0:846e2321c637 18 * 98,066.5 Pa = 1 kgf/cm2
Rhyme 0:846e2321c637 19 * 1 Pa = 1 / 98066.6 kgf/cm2
Rhyme 0:846e2321c637 20 */
Rhyme 0:846e2321c637 21
Rhyme 0:846e2321c637 22 PSE530::PSE530(AnalogIn *ain)
Rhyme 0:846e2321c637 23 {
Rhyme 0:846e2321c637 24 _ain = ain ;
Rhyme 0:846e2321c637 25 }
Rhyme 0:846e2321c637 26
Rhyme 0:846e2321c637 27 PSE530::~PSE530(void)
Rhyme 0:846e2321c637 28 {
Rhyme 0:846e2321c637 29 if (_ain) {
Rhyme 0:846e2321c637 30 delete _ain ;
Rhyme 0:846e2321c637 31 }
Rhyme 0:846e2321c637 32 }
Rhyme 0:846e2321c637 33
Rhyme 0:846e2321c637 34 /**
Rhyme 0:846e2321c637 35 * On FRDM-KL25Z ADC's AREF is about 3.28V
Rhyme 0:846e2321c637 36 * Where the converted pressure output is 0 to 3.21V
Rhyme 0:846e2321c637 37 * So we must map ADC output 0 to 3.21/3.28 as full scale
Rhyme 0:846e2321c637 38 *
Rhyme 0:846e2321c637 39 * Then according to the datasheet of PSE530
Rhyme 0:846e2321c637 40 * when full range is 0V to 5V
Rhyme 0:846e2321c637 41 * 1V is 0 and 5V is 1MPa which is converted to
Rhyme 0:846e2321c637 42 * 0.642/3.28 to 3.21/3.28 ~ 0.195731 to 0.9786585.
Rhyme 0:846e2321c637 43 * The linear equation of
Rhyme 0:846e2321c637 44 * y = a x + b
Rhyme 0:846e2321c637 45 * 0 = a * 0.195731 + b
Rhyme 0:846e2321c637 46 * 1 = a * 0.978658 + b
Rhyme 0:846e2321c637 47 * results a = 1.277, b = -0.250
Rhyme 0:846e2321c637 48 */
Rhyme 0:846e2321c637 49 float PSE530::getPressure(void)
Rhyme 0:846e2321c637 50 {
Rhyme 0:846e2321c637 51 float coef_A = 1.277 ;
Rhyme 0:846e2321c637 52 float coef_B = -0.250 ;
Rhyme 0:846e2321c637 53 float av = 0.0 ;
Rhyme 0:846e2321c637 54 float value = 0.0 ;
Rhyme 0:846e2321c637 55 av = coef_A * _ain->read() + coef_B ;
Rhyme 0:846e2321c637 56 // printf("Pressure ADC = %.4f\n", av) ;
Rhyme 0:846e2321c637 57 value = 1000000 * av ; /* 1MPa at 1.0 */
Rhyme 0:846e2321c637 58 value = value / 98066.5 ; /* Pa -> kgf/cm2 */
Rhyme 0:846e2321c637 59 return( value ) ;
Rhyme 0:846e2321c637 60 }