A lux sensor library
TSL2561.h@3:5b5911bfc644, 2015-08-13 (annotated)
- Committer:
- joshuasmth04
- Date:
- Thu Aug 13 15:00:29 2015 +0000
- Revision:
- 3:5b5911bfc644
- Parent:
- 2:c45d34e9c3f0
Finished and fully working, Lux values are not verified with a outside source but rather taken from the data sheet. Auto-selects between low and high gain settings. Note readings can take up to 0.65 seconds each, currently take ~0.1-0.3.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eawendtjr | 0:a3cedb66846f | 1 | // date 7/6/2015 |
eawendtjr | 0:a3cedb66846f | 2 | // author E wendt |
eawendtjr | 0:a3cedb66846f | 3 | |
eawendtjr | 0:a3cedb66846f | 4 | //TSL2561 light sensor library |
eawendtjr | 0:a3cedb66846f | 5 | |
eawendtjr | 0:a3cedb66846f | 6 | #ifndef _TSL2561_H_ |
eawendtjr | 0:a3cedb66846f | 7 | #define _TSL2561_H_ |
eawendtjr | 0:a3cedb66846f | 8 | |
eawendtjr | 0:a3cedb66846f | 9 | #include "mbed.h" |
joshuasmth04 | 2:c45d34e9c3f0 | 10 | //#define TSL2561_ADDRESS (0x72) |
eawendtjr | 0:a3cedb66846f | 11 | |
eawendtjr | 0:a3cedb66846f | 12 | #define TSL2561_VISIBLE 2 // channel 0 - channel 1 |
eawendtjr | 0:a3cedb66846f | 13 | #define TSL2561_INFRARED 1 // channel 1 |
eawendtjr | 0:a3cedb66846f | 14 | #define TSL2561_FULLSPECTRUM 0 // channel 0 |
eawendtjr | 0:a3cedb66846f | 15 | |
eawendtjr | 0:a3cedb66846f | 16 | // 3 i2c address options! |
joshuasmth04 | 2:c45d34e9c3f0 | 17 | //#define TSL2561_ADDR_LOW 0x52 |
joshuasmth04 | 2:c45d34e9c3f0 | 18 | #define TSL2561_ADDR_FLOAT (0x72) |
joshuasmth04 | 2:c45d34e9c3f0 | 19 | //#define TSL2561_ADDR_HIGH 0x92 |
eawendtjr | 0:a3cedb66846f | 20 | |
eawendtjr | 0:a3cedb66846f | 21 | // Lux calculations differ slightly for CS package |
eawendtjr | 0:a3cedb66846f | 22 | //#define TSL2561_PACKAGE_CS |
eawendtjr | 0:a3cedb66846f | 23 | #define TSL2561_PACKAGE_T_FN_CL |
eawendtjr | 0:a3cedb66846f | 24 | |
eawendtjr | 0:a3cedb66846f | 25 | #define TSL2561_READBIT (0x01) |
eawendtjr | 0:a3cedb66846f | 26 | |
eawendtjr | 0:a3cedb66846f | 27 | #define TSL2561_COMMAND_BIT (0x80) // Must be 1 |
eawendtjr | 0:a3cedb66846f | 28 | #define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear) |
eawendtjr | 0:a3cedb66846f | 29 | #define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte) |
eawendtjr | 0:a3cedb66846f | 30 | #define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write |
eawendtjr | 0:a3cedb66846f | 31 | |
eawendtjr | 0:a3cedb66846f | 32 | #define TSL2561_CONTROL_POWERON (0x03) |
eawendtjr | 0:a3cedb66846f | 33 | #define TSL2561_CONTROL_POWEROFF (0x00) |
eawendtjr | 0:a3cedb66846f | 34 | |
joshuasmth04 | 2:c45d34e9c3f0 | 35 | //ID |
eawendtjr | 1:52b855c13204 | 36 | #define I_AM_TSL2561 0x50 |
eawendtjr | 1:52b855c13204 | 37 | #define REG_NO_MASK 0x0F |
eawendtjr | 1:52b855c13204 | 38 | |
eawendtjr | 0:a3cedb66846f | 39 | //different timing and gain settings |
eawendtjr | 0:a3cedb66846f | 40 | /*#define TSL2561_INTEGRATIONTIME_13MS (0x00) // 13.7ms |
eawendtjr | 0:a3cedb66846f | 41 | #define TSL2561_INTEGRATIONTIME_101MS (0x01) // 101ms |
eawendtjr | 0:a3cedb66846f | 42 | #define TSL2561_INTEGRATIONTIME_402MS (0x02) // 402ms |
eawendtjr | 0:a3cedb66846f | 43 | |
eawendtjr | 0:a3cedb66846f | 44 | #define TSL2561_GAIN_0X (0x00) //x1 |
eawendtjr | 0:a3cedb66846f | 45 | #define TSL2561_GAIN_16X (0x10) //x16*/ |
eawendtjr | 0:a3cedb66846f | 46 | |
eawendtjr | 0:a3cedb66846f | 47 | |
eawendtjr | 0:a3cedb66846f | 48 | #define LUX_SCALE 14 // scale by 2^14 |
eawendtjr | 0:a3cedb66846f | 49 | #define RATIO_SCALE 9 // scale ratio by 2^9 |
eawendtjr | 0:a3cedb66846f | 50 | |
eawendtjr | 0:a3cedb66846f | 51 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 52 | // Integration time scaling factors |
eawendtjr | 0:a3cedb66846f | 53 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 54 | |
eawendtjr | 0:a3cedb66846f | 55 | #define CH_SCALE 10 // scale channel values by 2^10 |
eawendtjr | 0:a3cedb66846f | 56 | #define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE |
eawendtjr | 0:a3cedb66846f | 57 | #define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE |
eawendtjr | 0:a3cedb66846f | 58 | |
eawendtjr | 0:a3cedb66846f | 59 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 60 | // T, FN, and CL Package coefficients |
eawendtjr | 0:a3cedb66846f | 61 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 62 | // For Ch1/Ch0=0.00 to 0.50 |
eawendtjr | 0:a3cedb66846f | 63 | // Lux/Ch0=0.0304−0.062*((Ch1/Ch0)^1.4) |
eawendtjr | 0:a3cedb66846f | 64 | // piecewise approximation |
eawendtjr | 0:a3cedb66846f | 65 | // For Ch1/Ch0=0.00 to 0.125: |
eawendtjr | 0:a3cedb66846f | 66 | // Lux/Ch0=0.0304−0.0272*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 67 | // |
eawendtjr | 0:a3cedb66846f | 68 | // For Ch1/Ch0=0.125 to 0.250: |
eawendtjr | 0:a3cedb66846f | 69 | // Lux/Ch0=0.0325−0.0440*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 70 | // |
eawendtjr | 0:a3cedb66846f | 71 | // For Ch1/Ch0=0.250 to 0.375: |
eawendtjr | 0:a3cedb66846f | 72 | // Lux/Ch0=0.0351−0.0544*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 73 | // |
eawendtjr | 0:a3cedb66846f | 74 | // For Ch1/Ch0=0.375 to 0.50: |
eawendtjr | 0:a3cedb66846f | 75 | // Lux/Ch0=0.0381−0.0624*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 76 | // |
eawendtjr | 0:a3cedb66846f | 77 | // For Ch1/Ch0=0.50 to 0.61: |
eawendtjr | 0:a3cedb66846f | 78 | // Lux/Ch0=0.0224−0.031*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 79 | // |
eawendtjr | 0:a3cedb66846f | 80 | // For Ch1/Ch0=0.61 to 0.80: |
eawendtjr | 0:a3cedb66846f | 81 | // Lux/Ch0=0.0128−0.0153*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 82 | // |
eawendtjr | 0:a3cedb66846f | 83 | // For Ch1/Ch0=0.80 to 1.30: |
eawendtjr | 0:a3cedb66846f | 84 | // Lux/Ch0=0.00146−0.00112*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 85 | // |
eawendtjr | 0:a3cedb66846f | 86 | // For Ch1/Ch0>1.3: |
eawendtjr | 0:a3cedb66846f | 87 | // Lux/Ch0=0 |
eawendtjr | 0:a3cedb66846f | 88 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 89 | |
eawendtjr | 0:a3cedb66846f | 90 | #define K1T 0x0040 // 0.125 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 91 | #define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 92 | #define M1T 0x01be // 0.0272 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 93 | |
eawendtjr | 0:a3cedb66846f | 94 | #define K2T 0x0080 // 0.250 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 95 | #define B2T 0x0214 // 0.0325 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 96 | #define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 97 | |
eawendtjr | 0:a3cedb66846f | 98 | #define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 99 | #define B3T 0x023f // 0.0351 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 100 | #define M3T 0x037b // 0.0544 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 101 | |
eawendtjr | 0:a3cedb66846f | 102 | #define K4T 0x0100 // 0.50 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 103 | #define B4T 0x0270 // 0.0381 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 104 | #define M4T 0x03fe // 0.0624 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 105 | |
eawendtjr | 0:a3cedb66846f | 106 | #define K5T 0x0138 // 0.61 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 107 | #define B5T 0x016f // 0.0224 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 108 | #define M5T 0x01fc // 0.0310 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 109 | |
eawendtjr | 0:a3cedb66846f | 110 | #define K6T 0x019a // 0.80 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 111 | #define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 112 | #define M6T 0x00fb // 0.0153 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 113 | |
eawendtjr | 0:a3cedb66846f | 114 | #define K7T 0x029a // 1.3 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 115 | #define B7T 0x0018 // 0.00146 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 116 | #define M7T 0x0012 // 0.00112 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 117 | |
eawendtjr | 0:a3cedb66846f | 118 | #define K8T 0x029a // 1.3 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 119 | #define B8T 0x0000 // 0.000 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 120 | #define M8T 0x0000 // 0.000 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 121 | |
eawendtjr | 0:a3cedb66846f | 122 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 123 | // CS package coefficients |
eawendtjr | 0:a3cedb66846f | 124 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 125 | // For 0 <= Ch1/Ch0 <= 0.52 |
eawendtjr | 0:a3cedb66846f | 126 | // Lux/Ch0 = 0.0315−0.0593*((Ch1/Ch0)^1.4) |
eawendtjr | 0:a3cedb66846f | 127 | // piecewise approximation |
eawendtjr | 0:a3cedb66846f | 128 | // For 0 <= Ch1/Ch0 <= 0.13 |
eawendtjr | 0:a3cedb66846f | 129 | // Lux/Ch0 = 0.0315−0.0262*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 130 | // For 0.13 <= Ch1/Ch0 <= 0.26 |
eawendtjr | 0:a3cedb66846f | 131 | // Lux/Ch0 = 0.0337−0.0430*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 132 | // For 0.26 <= Ch1/Ch0 <= 0.39 |
eawendtjr | 0:a3cedb66846f | 133 | // Lux/Ch0 = 0.0363−0.0529*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 134 | // For 0.39 <= Ch1/Ch0 <= 0.52 |
eawendtjr | 0:a3cedb66846f | 135 | // Lux/Ch0 = 0.0392−0.0605*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 136 | // For 0.52 < Ch1/Ch0 <= 0.65 |
eawendtjr | 0:a3cedb66846f | 137 | // Lux/Ch0 = 0.0229−0.0291*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 138 | // For 0.65 < Ch1/Ch0 <= 0.80 |
eawendtjr | 0:a3cedb66846f | 139 | // Lux/Ch0 = 0.00157−0.00180*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 140 | // For 0.80 < Ch1/Ch0 <= 1.30 |
eawendtjr | 0:a3cedb66846f | 141 | // Lux/Ch0 = 0.00338−0.00260*(Ch1/Ch0) |
eawendtjr | 0:a3cedb66846f | 142 | // For Ch1/Ch0 > 1.30 |
eawendtjr | 0:a3cedb66846f | 143 | // Lux = 0 |
eawendtjr | 0:a3cedb66846f | 144 | //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− |
eawendtjr | 0:a3cedb66846f | 145 | |
eawendtjr | 0:a3cedb66846f | 146 | #define K1C 0x0043 // 0.130 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 147 | #define B1C 0x0204 // 0.0315 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 148 | #define M1C 0x01ad // 0.0262 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 149 | |
eawendtjr | 0:a3cedb66846f | 150 | #define K2C 0x0085 // 0.260 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 151 | #define B2C 0x0228 // 0.0337 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 152 | #define M2C 0x02c1 // 0.0430 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 153 | |
eawendtjr | 0:a3cedb66846f | 154 | #define K3C 0x00c8 // 0.390 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 155 | #define B3C 0x0253 // 0.0363 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 156 | #define M3C 0x0363 // 0.0529 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 157 | |
eawendtjr | 0:a3cedb66846f | 158 | #define K4C 0x010a // 0.520 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 159 | #define B4C 0x0282 // 0.0392 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 160 | #define M4C 0x03df // 0.0605 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 161 | |
eawendtjr | 0:a3cedb66846f | 162 | #define K5C 0x014d // 0.65 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 163 | #define B5C 0x0177 // 0.0229 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 164 | #define M5C 0x01dd // 0.0291 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 165 | |
eawendtjr | 0:a3cedb66846f | 166 | #define K6C 0x019a // 0.80 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 167 | #define B6C 0x0101 // 0.0157 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 168 | #define M6C 0x0127 // 0.0180 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 169 | |
eawendtjr | 0:a3cedb66846f | 170 | #define K7C 0x029a // 1.3 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 171 | #define B7C 0x0037 // 0.00338 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 172 | #define M7C 0x002b // 0.00260 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 173 | |
eawendtjr | 0:a3cedb66846f | 174 | #define K8C 0x029a // 1.3 * 2^RATIO_SCALE |
eawendtjr | 0:a3cedb66846f | 175 | #define B8C 0x0000 // 0.000 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 176 | #define M8C 0x0000 // 0.000 * 2^LUX_SCALE |
eawendtjr | 0:a3cedb66846f | 177 | |
eawendtjr | 0:a3cedb66846f | 178 | //Enum of all the register addresses as not to put hex numbers in .cpp |
joshuasmth04 | 2:c45d34e9c3f0 | 179 | enum { |
joshuasmth04 | 2:c45d34e9c3f0 | 180 | TSL2561_REGISTER_CONTROL = 0x00, |
joshuasmth04 | 2:c45d34e9c3f0 | 181 | TSL2561_REGISTER_TIMING = 0x01, |
joshuasmth04 | 2:c45d34e9c3f0 | 182 | TSL2561_REGISTER_THRESHHOLDL_LOW = 0x02, |
joshuasmth04 | 2:c45d34e9c3f0 | 183 | TSL2561_REGISTER_THRESHHOLDL_HIGH = 0x03, |
joshuasmth04 | 2:c45d34e9c3f0 | 184 | TSL2561_REGISTER_THRESHHOLDH_LOW = 0x04, |
joshuasmth04 | 2:c45d34e9c3f0 | 185 | TSL2561_REGISTER_THRESHHOLDH_HIGH = 0x05, |
joshuasmth04 | 2:c45d34e9c3f0 | 186 | TSL2561_REGISTER_INTERRUPT = 0x06, |
joshuasmth04 | 2:c45d34e9c3f0 | 187 | TSL2561_REGISTER_CRC = 0x08, |
joshuasmth04 | 2:c45d34e9c3f0 | 188 | TSL2561_REGISTER_ID = 0x0A, |
joshuasmth04 | 2:c45d34e9c3f0 | 189 | TSL2561_REGISTER_CHAN0_LOW = 0x0C, |
joshuasmth04 | 2:c45d34e9c3f0 | 190 | TSL2561_REGISTER_CHAN0_HIGH = 0x0D, |
joshuasmth04 | 2:c45d34e9c3f0 | 191 | TSL2561_REGISTER_CHAN1_LOW = 0x0E, |
joshuasmth04 | 2:c45d34e9c3f0 | 192 | TSL2561_REGISTER_CHAN1_HIGH = 0x0F |
eawendtjr | 0:a3cedb66846f | 193 | }; |
eawendtjr | 0:a3cedb66846f | 194 | |
joshuasmth04 | 2:c45d34e9c3f0 | 195 | typedef enum { |
joshuasmth04 | 2:c45d34e9c3f0 | 196 | TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms |
joshuasmth04 | 2:c45d34e9c3f0 | 197 | TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms |
joshuasmth04 | 2:c45d34e9c3f0 | 198 | TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms |
eawendtjr | 0:a3cedb66846f | 199 | } |
eawendtjr | 0:a3cedb66846f | 200 | tsl2561IntegrationTime_t; |
eawendtjr | 0:a3cedb66846f | 201 | |
joshuasmth04 | 2:c45d34e9c3f0 | 202 | typedef enum { |
joshuasmth04 | 2:c45d34e9c3f0 | 203 | TSL2561_GAIN_0X = 0x00, // No gain |
joshuasmth04 | 2:c45d34e9c3f0 | 204 | TSL2561_GAIN_16X = 0x10, // 16x gain |
eawendtjr | 0:a3cedb66846f | 205 | } |
eawendtjr | 0:a3cedb66846f | 206 | tsl2561Gain_t; |
eawendtjr | 0:a3cedb66846f | 207 | |
eawendtjr | 0:a3cedb66846f | 208 | extern Serial pc; |
eawendtjr | 0:a3cedb66846f | 209 | |
eawendtjr | 0:a3cedb66846f | 210 | class TSL2561 |
eawendtjr | 0:a3cedb66846f | 211 | { |
joshuasmth04 | 2:c45d34e9c3f0 | 212 | public: |
eawendtjr | 0:a3cedb66846f | 213 | //create instances |
eawendtjr | 0:a3cedb66846f | 214 | TSL2561(PinName sda, PinName scl, char slave_address = TSL2561_ADDR_FLOAT); |
eawendtjr | 0:a3cedb66846f | 215 | TSL2561(I2C &i2c_obj, char slave_adr = TSL2561_ADDR_FLOAT); |
joshuasmth04 | 2:c45d34e9c3f0 | 216 | |
eawendtjr | 0:a3cedb66846f | 217 | //destructor |
joshuasmth04 | 2:c45d34e9c3f0 | 218 | virtual ~TSL2561(); |
joshuasmth04 | 2:c45d34e9c3f0 | 219 | |
eawendtjr | 0:a3cedb66846f | 220 | /** Begin Initialization SI1145 sensor |
eawendtjr | 0:a3cedb66846f | 221 | * Configure sensor setting and read parameters for calibration |
eawendtjr | 0:a3cedb66846f | 222 | */ |
eawendtjr | 0:a3cedb66846f | 223 | //check id register before proceeding |
joshuasmth04 | 2:c45d34e9c3f0 | 224 | bool initialize(void); |
joshuasmth04 | 2:c45d34e9c3f0 | 225 | |
joshuasmth04 | 2:c45d34e9c3f0 | 226 | //Enable sensor using control register |
eawendtjr | 0:a3cedb66846f | 227 | void enable(void); |
eawendtjr | 0:a3cedb66846f | 228 | //Disable sensor using control register |
eawendtjr | 0:a3cedb66846f | 229 | void disable(void); |
joshuasmth04 | 2:c45d34e9c3f0 | 230 | |
joshuasmth04 | 2:c45d34e9c3f0 | 231 | //set the integration time and gain using command, timing, and gain registers |
joshuasmth04 | 2:c45d34e9c3f0 | 232 | void setTimingGain(tsl2561IntegrationTime_t integration, tsl2561Gain_t gain); |
eawendtjr | 0:a3cedb66846f | 233 | |
joshuasmth04 | 2:c45d34e9c3f0 | 234 | //read channal 0 and 1, adjust the gain if needed, read again(repeat), and then calculate lux. |
joshuasmth04 | 2:c45d34e9c3f0 | 235 | void read_lux(void); |
eawendtjr | 0:a3cedb66846f | 236 | |
eawendtjr | 0:a3cedb66846f | 237 | |
joshuasmth04 | 2:c45d34e9c3f0 | 238 | uint32_t lux; //Final data |
joshuasmth04 | 2:c45d34e9c3f0 | 239 | uint16_t channal0; //Raw data of vis and ir |
joshuasmth04 | 2:c45d34e9c3f0 | 240 | uint16_t channal1; //Raw data of just ir |
joshuasmth04 | 2:c45d34e9c3f0 | 241 | |
joshuasmth04 | 2:c45d34e9c3f0 | 242 | |
joshuasmth04 | 2:c45d34e9c3f0 | 243 | |
eawendtjr | 0:a3cedb66846f | 244 | //Read data registers than convert to a lux value |
eawendtjr | 0:a3cedb66846f | 245 | uint32_t calculateLux(uint16_t ch0, uint16_t ch1); |
joshuasmth04 | 2:c45d34e9c3f0 | 246 | |
eawendtjr | 0:a3cedb66846f | 247 | //get luminosity from data registers |
eawendtjr | 0:a3cedb66846f | 248 | uint32_t getFullLuminosity (void); |
eawendtjr | 0:a3cedb66846f | 249 | uint16_t getLuminosity (uint8_t channel); |
joshuasmth04 | 2:c45d34e9c3f0 | 250 | |
joshuasmth04 | 2:c45d34e9c3f0 | 251 | |
joshuasmth04 | 2:c45d34e9c3f0 | 252 | |
joshuasmth04 | 2:c45d34e9c3f0 | 253 | |
joshuasmth04 | 2:c45d34e9c3f0 | 254 | private: |
eawendtjr | 0:a3cedb66846f | 255 | I2C *i2c_p; |
eawendtjr | 0:a3cedb66846f | 256 | I2C &i2c; |
eawendtjr | 0:a3cedb66846f | 257 | char address; |
joshuasmth04 | 2:c45d34e9c3f0 | 258 | tsl2561IntegrationTime_t _integration; |
joshuasmth04 | 2:c45d34e9c3f0 | 259 | tsl2561Gain_t _gain; |
joshuasmth04 | 2:c45d34e9c3f0 | 260 | |
joshuasmth04 | 2:c45d34e9c3f0 | 261 | |
eawendtjr | 0:a3cedb66846f | 262 | }; |
joshuasmth04 | 2:c45d34e9c3f0 | 263 | #endif |