1+ #include < Arduino.h>
2+ #include " t1000e_sensors.h"
3+
4+ #define HEATER_NTC_BX 4250 // thermistor coefficient B
5+ #define HEATER_NTC_RP 8250 // ohm, series resistance to thermistor
6+ #define HEATER_NTC_KA 273.15 // 25 Celsius at Kelvin
7+ #define NTC_REF_VCC 3000 // mV, output voltage of LDO
8+ #define LIGHT_REF_VCC 2400 //
9+
10+ static unsigned int ntc_res2[136 ]={
11+ 113347 ,107565 ,102116 ,96978 ,92132 ,87559 ,83242 ,79166 ,75316 ,71677 ,
12+ 68237 ,64991 ,61919 ,59011 ,56258 ,53650 ,51178 ,48835 ,46613 ,44506 ,
13+ 42506 ,40600 ,38791 ,37073 ,35442 ,33892 ,32420 ,31020 ,29689 ,28423 ,
14+ 27219 ,26076 ,24988 ,23951 ,22963 ,22021 ,21123 ,20267 ,19450 ,18670 ,
15+ 17926 ,17214 ,16534 ,15886 ,15266 ,14674 ,14108 ,13566 ,13049 ,12554 ,
16+ 12081 ,11628 ,11195 ,10780 ,10382 ,10000 ,9634 ,9284 ,8947 ,8624 ,
17+ 8315 ,8018 ,7734 ,7461 ,7199 ,6948 ,6707 ,6475 ,6253 ,6039 ,
18+ 5834 ,5636 ,5445 ,5262 ,5086 ,4917 ,4754 ,4597 ,4446 ,4301 ,
19+ 4161 ,4026 ,3896 ,3771 ,3651 ,3535 ,3423 ,3315 ,3211 ,3111 ,
20+ 3014 ,2922 ,2834 ,2748 ,2666 ,2586 ,2509 ,2435 ,2364 ,2294 ,
21+ 2228 ,2163 ,2100 ,2040 ,1981 ,1925 ,1870 ,1817 ,1766 ,1716 ,
22+ 1669 ,1622 ,1578 ,1535 ,1493 ,1452 ,1413 ,1375 ,1338 ,1303 ,
23+ 1268 ,1234 ,1202 ,1170 ,1139 ,1110 ,1081 ,1053 ,1026 ,999 ,
24+ 974 ,949 ,925 ,902 ,880 ,858 ,
25+ };
26+
27+ static char ntc_temp2[136 ]=
28+ {
29+ -30 ,-29 ,-28 ,-27 ,-26 ,-25 ,-24 ,-23 ,-22 ,-21 ,
30+ -20 ,-19 ,-18 ,-17 ,-16 ,-15 ,-14 ,-13 ,-12 ,-11 ,
31+ -10 ,-9 ,-8 ,-7 ,-6 ,-5 ,-4 ,-3 ,-2 ,-1 ,
32+ 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,
33+ 10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,
34+ 20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,
35+ 30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,
36+ 40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,
37+ 50 ,51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,
38+ 60 ,61 ,62 ,63 ,64 ,65 ,66 ,67 ,68 ,69 ,
39+ 70 ,71 ,72 ,73 ,74 ,75 ,76 ,77 ,78 ,79 ,
40+ 80 ,81 ,82 ,83 ,84 ,85 ,86 ,87 ,88 ,89 ,
41+ 90 ,91 ,92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,
42+ 100 ,101 ,102 ,103 ,104 ,105 ,
43+ };
44+
45+ static float get_heater_temperature ( unsigned int vcc_volt, unsigned int ntc_volt )
46+ {
47+ int i = 0 ;
48+ float Vout = 0 , Rt = 0 , temp = 0 ;
49+ Vout = ntc_volt;
50+
51+ Rt = ( HEATER_NTC_RP * vcc_volt ) / Vout - HEATER_NTC_RP;
52+
53+ for ( i = 0 ; i < 136 ; i++ )
54+ {
55+ if ( Rt >= ntc_res2[i] )
56+ {
57+ break ;
58+ }
59+ }
60+
61+ temp = ntc_temp2[i - 1 ] + 1 * ( ntc_res2[i - 1 ] - Rt ) / ( float )( ntc_res2[i - 1 ] - ntc_res2[i] );
62+
63+ temp = ( temp * 100 + 5 ) / 100 ;
64+ return temp;
65+ }
66+
67+ static int get_light_lv ( unsigned int light_volt )
68+ {
69+ float Vout = 0 , Vin = 0 , Rt = 0 , temp = 0 ;
70+ unsigned int light_level = 0 ;
71+
72+ if ( light_volt <= 80 )
73+ {
74+ light_level = 0 ;
75+ return light_level;
76+ }
77+ else if ( light_volt >= 2480 )
78+ {
79+ light_level = 100 ;
80+ return light_level;
81+ }
82+ Vout = light_volt;
83+ light_level = 100 * ( Vout - 80 ) / LIGHT_REF_VCC;
84+
85+ return light_level;
86+ }
87+
88+ float t1000e_get_temperature ( void )
89+ {
90+ unsigned int ntc_v, vcc_v;
91+
92+ digitalWrite (PIN_3V3_EN, HIGH);
93+ digitalWrite (SENSOR_EN, HIGH);
94+ analogReference (AR_INTERNAL_3_0);
95+ analogReadResolution (12 );
96+ delay (10 );
97+ vcc_v = (1000.0 *(analogRead (BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE)) / 4096 ;
98+ ntc_v = (1000.0 * AREF_VOLTAGE * analogRead (TEMP_SENSOR)) / 4096 ;
99+ digitalWrite (PIN_3V3_EN, LOW);
100+ digitalWrite (SENSOR_EN, LOW);
101+
102+ return get_heater_temperature (vcc_v, ntc_v);
103+ }
104+
105+ uint32_t t1000e_get_light ( void )
106+ {
107+ int lux = 0 ;
108+ unsigned int lux_v = 0 ;
109+
110+ digitalWrite (SENSOR_EN, HIGH);
111+ analogReference (AR_INTERNAL_3_0);
112+ analogReadResolution (12 );
113+ delay (10 );
114+ lux_v = 1000 * analogRead (LUX_SENSOR) * AREF_VOLTAGE / 4096 ;
115+ lux = get_light_lv ( lux_v );
116+ digitalWrite (SENSOR_EN, LOW);
117+
118+ return lux;
119+ }
0 commit comments