├── .gitattributes ├── .github └── workflows │ ├── run-ci-arduino.yml │ ├── stale.yml │ └── sync_issues.yml ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── Digital_Light_ISL29035.cpp ├── Digital_Light_ISL29035.h ├── Digital_Light_TSL2561.cpp ├── Digital_Light_TSL2561.h ├── License.txt ├── README.md ├── examples ├── Digital_Light_Sensor │ └── Digital_Light_Sensor.ino ├── Digital_Light_Sensor_IR │ └── Digital_Light_Sensor_IR.ino └── Digital_Light_Sensor_v2 │ └── Digital_Light_Sensor_v2.ino ├── keywords.txt └── library.properties /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/run-ci-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Run Ci Arduino 2 | 3 | on: 4 | push: 5 | pull_request: 6 | repository_dispatch: 7 | types: [trigger-workflow] 8 | 9 | jobs: 10 | ci-arduino: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v4 16 | 17 | - name: Checkout script repository 18 | uses: actions/checkout@v4 19 | with: 20 | repository: Seeed-Studio/ci-arduino 21 | path: ci 22 | 23 | - name: Setup arduino cli 24 | uses: arduino/setup-arduino-cli@v2.0.0 25 | 26 | - name: Create a depend.list file 27 | run: | 28 | # eg: echo "" >> depend.list 29 | 30 | - name: Create a ignore.list file 31 | run: | 32 | # eg: echo "," >> ignore.list 33 | 34 | - name: Build sketch 35 | run: ./ci/tools/compile.sh 36 | 37 | - name: Build result 38 | run: | 39 | cat build.log 40 | if [ ${{ github.event_name }} == 'pull_request' ] && [ -f compile.failed ]; then 41 | exit 1 42 | fi 43 | 44 | - name: Generate issue 45 | if: ${{ github.event_name != 'pull_request' }} 46 | run: ./ci/tools/issue.sh 47 | env: 48 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 4 * * *' 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Checkout script repository 17 | uses: actions/checkout@v4 18 | with: 19 | repository: Seeed-Studio/sync-github-all-issues 20 | path: ci 21 | 22 | - name: Run script 23 | run: ./ci/tools/stale.sh 24 | env: 25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build: 2 | tags: 3 | - nas 4 | script: 5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 6 | - chmod +x seeed-arduino-ci.sh 7 | - bash $PWD/seeed-arduino-ci.sh test 8 | 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: generic 3 | dist: bionic 4 | sudo: false 5 | cache: 6 | directories: 7 | - ~/arduino_ide 8 | - ~/.arduino15/packages/ 9 | 10 | before_install: 11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 12 | 13 | script: 14 | - chmod +x seeed-arduino-ci.sh 15 | - cat $PWD/seeed-arduino-ci.sh 16 | - bash $PWD/seeed-arduino-ci.sh test 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /Digital_Light_ISL29035.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_ISL29035.cpp 3 | A library for ISL29035 4 | 5 | Copyright (c) 2017 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : Jack 8 | Create Time: 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | #include 32 | #include 33 | 34 | DigitalLightISL29035::DigitalLightISL29035(): 35 | _full_scale_lux_range(DEFAULT_LUX_RANGE_INDEX), 36 | _integration_time(DEFAULT_INTEGRATION_TIME_INDEX) { 37 | _adc_count_max[0] = 65536; 38 | _adc_count_max[1] = 4096; 39 | _adc_count_max[2] = 256; 40 | _adc_count_max[3] = 16; 41 | 42 | _intg_time[0] = INTEGRATION_TIME0; 43 | _intg_time[1] = INTEGRATION_TIME1; 44 | _intg_time[2] = INTEGRATION_TIME2; 45 | _intg_time[3] = INTEGRATION_TIME3; 46 | 47 | _ranges[0] = FULL_SCALE_LUX_RANGE0; 48 | _ranges[1] = FULL_SCALE_LUX_RANGE1; 49 | _ranges[2] = FULL_SCALE_LUX_RANGE2; 50 | _ranges[3] = FULL_SCALE_LUX_RANGE3; 51 | } 52 | 53 | uint8_t DigitalLightISL29035::readRegister(int device_address, int reg_address) { 54 | uint8_t value; 55 | Wire.beginTransmission(device_address); 56 | Wire.write(reg_address); 57 | Wire.endTransmission(false); 58 | Wire.requestFrom(device_address, 1); 59 | //while(!Wire.available()); 60 | value = Wire.read(); 61 | return value; 62 | } 63 | 64 | void DigitalLightISL29035::writeRegister(int device_address, int reg_address, uint8_t val) { 65 | Wire.beginTransmission(device_address); 66 | Wire.write(reg_address); 67 | Wire.write(val); 68 | Wire.endTransmission(); 69 | } 70 | 71 | int DigitalLightISL29035::init() { 72 | uint8_t reg = readRegister(ISL29035_I2C_ADDRESS, CHIP_ID); 73 | //Serial.println(reg, HEX); 74 | uint8_t chip_id = (reg >> 3) & 0x7; 75 | if (chip_id != 0x5) { 76 | return -1; 77 | } 78 | 79 | //clear the BOUT bit 80 | writeRegister(ISL29035_I2C_ADDRESS, CHIP_ID, reg & 0x7f); 81 | 82 | //ensure the chip is under stop mode 83 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_I, 0); 84 | 85 | //set the default full scale lux range, and the integration time 86 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_II, _full_scale_lux_range | (_integration_time << 2)); 87 | 88 | return 0; 89 | } 90 | 91 | int DigitalLightISL29035::setFullScaleLuxRangeIndex(int range_index) { 92 | if (range_index < 0 || range_index > 3) { 93 | return -1; 94 | } 95 | _full_scale_lux_range = range_index; 96 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_II, _full_scale_lux_range | (_integration_time << 2)); 97 | 98 | return 0; 99 | } 100 | 101 | int DigitalLightISL29035::setIntegrationTimeIndex(int intg_time_index) { 102 | if (intg_time_index < 0 || intg_time_index > 3) { 103 | return -1; 104 | } 105 | _integration_time = intg_time_index; 106 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_II, _full_scale_lux_range | (_integration_time << 2)); 107 | 108 | return 0; 109 | } 110 | 111 | void DigitalLightISL29035::test() { 112 | #if 0 113 | uint8_t value; 114 | Wire.beginTransmission(ISL29035_I2C_ADDRESS); 115 | Wire.write(0); 116 | Wire.endTransmission(); 117 | Wire.requestFrom(ISL29035_I2C_ADDRESS, 8); 118 | while (!Wire.available()); 119 | for (int i = 0; i < 8; i++) { 120 | Serial.print("reg "); 121 | Serial.print(i); 122 | Serial.print(": 0x"); 123 | Serial.println(Wire.read(), HEX); 124 | } 125 | value = readRegister(ISL29035_I2C_ADDRESS, CHIP_ID); 126 | Serial.print("reg 0xf: 0x"); 127 | Serial.println(value, HEX); 128 | #endif 129 | } 130 | 131 | 132 | uint16_t DigitalLightISL29035::readData() { 133 | uint8_t l, h; 134 | Wire.beginTransmission(ISL29035_I2C_ADDRESS); 135 | Wire.write(DATA_L); 136 | Wire.endTransmission(false); 137 | Wire.requestFrom(ISL29035_I2C_ADDRESS, 2); 138 | while (Wire.available() < 2); 139 | l = Wire.read(); 140 | h = Wire.read(); 141 | 142 | return (h << 8) | l; 143 | } 144 | 145 | uint16_t DigitalLightISL29035::measure(uint8_t what) { 146 | //start 147 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_I, what); 148 | float time = _intg_time[_integration_time]; 149 | if (time < 1.0f) { 150 | delayMicroseconds((int)(time * 1000)); 151 | } else { 152 | delay((int)(time + 1.5f)); 153 | } 154 | uint16_t data = readData(); 155 | //stop 156 | writeRegister(ISL29035_I2C_ADDRESS, COMMAND_I, 0); 157 | return data; 158 | } 159 | 160 | uint32_t DigitalLightISL29035::readVisibleLux() { 161 | uint16_t data = measure(OPMODE_ALS_ONCE); 162 | return ((uint32_t)_ranges[_full_scale_lux_range]) * (uint32_t)data / _adc_count_max[_integration_time]; 163 | } 164 | 165 | uint32_t DigitalLightISL29035::readIRLux() { 166 | uint16_t data = measure(OPMODE_IR_ONCE); 167 | return ((uint32_t)_ranges[_full_scale_lux_range]) * (uint32_t)data / _adc_count_max[_integration_time]; 168 | } 169 | 170 | int32_t DigitalLightISL29035::readEV() { 171 | uint16_t data1 = measure(OPMODE_ALS_ONCE); 172 | uint16_t data2 = measure(OPMODE_IR_ONCE); 173 | 174 | float k = 0.82; 175 | float beta = -11292.86f; 176 | if (_integration_time > 1) { 177 | beta = 2137.14f; 178 | } 179 | return (int32_t)(k * data1 + data2 / beta); 180 | } 181 | 182 | 183 | DigitalLightISL29035 ISL29035; 184 | 185 | 186 | -------------------------------------------------------------------------------- /Digital_Light_ISL29035.h: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_ISL29035.h 3 | A library for ISL29035 4 | 5 | Copyright (c) 2017 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : Jack 8 | Create Time: 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | #ifndef Digital_Light_ISL29035_H 32 | #define Digital_Light_ISL29035_H 33 | 34 | #include 35 | 36 | #define ISL29035_I2C_ADDRESS 0x44 //the 7bits i2c address 37 | 38 | #define COMMAND_I 0x00 39 | #define COMMAND_II 0x01 40 | #define DATA_L 0x02 41 | #define DATA_H 0x03 42 | #define INT_LT_L 0x04 43 | #define INT_LT_H 0x05 44 | #define INT_HT_L 0x06 45 | #define INT_HT_H 0x07 46 | #define CHIP_ID 0x0f 47 | 48 | #define OPMODE_ALS_ONCE ((0x1)<<5) 49 | #define OPMODE_IR_ONCE ((0x2)<<5) 50 | #define OPMODE_ALS_CONTI ((0x5)<<5) 51 | #define OPMODE_IR_CONTI ((0x6)<<5) 52 | 53 | #define FULL_SCALE_LUX_RANGE0 1000 54 | #define FULL_SCALE_LUX_RANGE1 4000 55 | #define FULL_SCALE_LUX_RANGE2 16000 56 | #define FULL_SCALE_LUX_RANGE3 64000 57 | #define DEFAULT_LUX_RANGE_INDEX 1 //should be [0,3] 58 | 59 | #define INTEGRATION_TIME3 0.0256 //ms, this also configure the ADC to 4bits 60 | #define INTEGRATION_TIME2 0.41 //ms, this also configure the ADC to 8bits 61 | #define INTEGRATION_TIME1 6.5 //ms, this also configure the ADC to 12bits 62 | #define INTEGRATION_TIME0 105 //ms, this also configure the ADC to 16bits 63 | #define DEFAULT_INTEGRATION_TIME_INDEX 1 //should be [0,3] 64 | 65 | class DigitalLightISL29035 { 66 | public: 67 | DigitalLightISL29035(); 68 | 69 | int init(void); 70 | /** 71 | Set the full scale range for lux measurement. 72 | A lower range offers better resolution, it's suitable in a dim env, 73 | while in light env, a higher range should be selected. 74 | 0: 1000 lux, 1: 4000 lux, 2: 16000 lux, 3: 64000 lux 75 | default index is 0. 76 | */ 77 | int setFullScaleLuxRangeIndex(int range_index); 78 | 79 | /** 80 | Set the integration time. 81 | 0: 105ms, 1: 6.5ms, 2: 0.41ms, 3: 0.0256 82 | default index is 0. 83 | */ 84 | int setIntegrationTimeIndex(int intg_time_index); 85 | 86 | /** 87 | This sensor has builtin IR rejection when measuring ambient light. 88 | */ 89 | uint32_t readVisibleLux(); 90 | uint32_t readIRLux(); 91 | int32_t readEV(); 92 | 93 | void test(); 94 | 95 | private: 96 | uint8_t _full_scale_lux_range; 97 | uint8_t _integration_time; 98 | uint32_t _adc_count_max[4]; 99 | float _intg_time[4]; 100 | uint32_t _ranges[4]; 101 | 102 | uint8_t readRegister(int deviceAddress, int address); 103 | void writeRegister(int deviceAddress, int address, uint8_t val); 104 | uint16_t readData(); 105 | uint16_t measure(uint8_t what); 106 | 107 | }; 108 | extern DigitalLightISL29035 ISL29035; 109 | #endif 110 | 111 | 112 | -------------------------------------------------------------------------------- /Digital_Light_TSL2561.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_TSL2561.cpp 3 | A library for TSL2561 4 | 5 | Copyright (c) 2012 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : zhangkun 8 | Create Time: 9 | Change Log : Jack Shao, Nov 2014, bug fix and update for user experience 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | TSL2561_CalculateLux::TSL2561_CalculateLux(uint32_t read_timeout) : read_timeout(read_timeout) { 37 | } 38 | 39 | uint8_t TSL2561_CalculateLux::readRegister(int deviceAddress, int address) { 40 | 41 | uint8_t value; 42 | Wire.beginTransmission(deviceAddress); 43 | Wire.write(address); // register to read 44 | Wire.endTransmission(); 45 | Wire.requestFrom(deviceAddress, 1); // read a byte 46 | uint32_t readStart = micros(); 47 | while (!Wire.available()) { 48 | if (read_timeout != TSL2561_NO_READ_TIMEOUT && micros() - readStart >= read_timeout) { 49 | hadTimeout = true; 50 | break; 51 | } 52 | } 53 | value = Wire.read(); 54 | //delay(100); 55 | return value; 56 | } 57 | 58 | void TSL2561_CalculateLux::writeRegister(int deviceAddress, int address, uint8_t val) { 59 | Wire.beginTransmission(deviceAddress); // start transmission to device 60 | Wire.write(address); // send register address 61 | Wire.write(val); // send value to write 62 | Wire.endTransmission(); // end transmission 63 | //delay(100); 64 | } 65 | void TSL2561_CalculateLux::getLux(void) { 66 | CH0_LOW = readRegister(TSL2561_Address, TSL2561_Channal0L); 67 | CH0_HIGH = readRegister(TSL2561_Address, TSL2561_Channal0H); 68 | //read two bytes from registers 0x0E and 0x0F 69 | CH1_LOW = readRegister(TSL2561_Address, TSL2561_Channal1L); 70 | CH1_HIGH = readRegister(TSL2561_Address, TSL2561_Channal1H); 71 | 72 | ch0 = (CH0_HIGH << 8) | CH0_LOW; 73 | ch1 = (CH1_HIGH << 8) | CH1_LOW; 74 | } 75 | void TSL2561_CalculateLux::init() { 76 | writeRegister(TSL2561_Address, TSL2561_Control, 0x03); // POWER UP 77 | writeRegister(TSL2561_Address, TSL2561_Timing, 0x00); //No High Gain (1x), integration time of 13ms 78 | writeRegister(TSL2561_Address, TSL2561_Interrupt, 0x00); 79 | writeRegister(TSL2561_Address, TSL2561_Control, 0x00); // POWER Down 80 | } 81 | 82 | 83 | uint16_t TSL2561_CalculateLux::readIRLuminosity() { // read Infrared channel value only, not convert to lux. 84 | writeRegister(TSL2561_Address, TSL2561_Control, 0x03); // POWER UP 85 | delay(14); 86 | getLux(); 87 | 88 | writeRegister(TSL2561_Address, TSL2561_Control, 0x00); // POWER Down 89 | if (ch1 == 0) { 90 | return 0; 91 | } 92 | if (ch0 / ch1 < 2 && ch0 > 4900) { 93 | return -1; //ch0 out of range, but ch1 not. the lux is not valid in this situation. 94 | } 95 | return ch1; 96 | } 97 | 98 | uint16_t TSL2561_CalculateLux::readFSpecLuminosity() { //read Full Spectrum channel value only, not convert to lux. 99 | writeRegister(TSL2561_Address, TSL2561_Control, 0x03); // POWER UP 100 | delay(14); 101 | getLux(); 102 | 103 | writeRegister(TSL2561_Address, TSL2561_Control, 0x00); // POWER Down 104 | if (ch1 == 0) { 105 | return 0; 106 | } 107 | if (ch0 / ch1 < 2 && ch0 > 4900) { 108 | return -1; //ch0 out of range, but ch1 not. the lux is not valid in this situation. 109 | } 110 | return ch0; 111 | } 112 | 113 | signed long TSL2561_CalculateLux::readVisibleLux() { 114 | writeRegister(TSL2561_Address, TSL2561_Control, 0x03); // POWER UP 115 | delay(14); 116 | getLux(); 117 | 118 | writeRegister(TSL2561_Address, TSL2561_Control, 0x00); // POWER Down 119 | if (ch1 == 0) { 120 | return 0; 121 | } 122 | if (ch0 / ch1 < 2 && ch0 > 4900) { 123 | return -1; //ch0 out of range, but ch1 not. the lux is not valid in this situation. 124 | } 125 | return calculateLux(0, 0, 0); //T package, no gain, 13ms 126 | } 127 | unsigned long TSL2561_CalculateLux::calculateLux(unsigned int iGain, unsigned int tInt, int iType) { 128 | switch (tInt) { 129 | case 0: // 13.7 msec 130 | chScale = CHSCALE_TINT0; 131 | break; 132 | case 1: // 101 msec 133 | chScale = CHSCALE_TINT1; 134 | break; 135 | default: // assume no scaling 136 | chScale = (1 << CH_SCALE); 137 | break; 138 | } 139 | if (!iGain) { 140 | chScale = chScale << 4; // scale 1X to 16X 141 | } 142 | // scale the channel values 143 | channel0 = (ch0 * chScale) >> CH_SCALE; 144 | channel1 = (ch1 * chScale) >> CH_SCALE; 145 | 146 | ratio1 = 0; 147 | if (channel0 != 0) { 148 | ratio1 = (channel1 << (RATIO_SCALE + 1)) / channel0; 149 | } 150 | // round the ratio value 151 | unsigned long ratio = (ratio1 + 1) >> 1; 152 | 153 | switch (iType) { 154 | case 0: // T package 155 | if ((ratio >= 0) && (ratio <= K1T)) { 156 | b = B1T; 157 | m = M1T; 158 | } else if (ratio <= K2T) { 159 | b = B2T; 160 | m = M2T; 161 | } else if (ratio <= K3T) { 162 | b = B3T; 163 | m = M3T; 164 | } else if (ratio <= K4T) { 165 | b = B4T; 166 | m = M4T; 167 | } else if (ratio <= K5T) { 168 | b = B5T; 169 | m = M5T; 170 | } else if (ratio <= K6T) { 171 | b = B6T; 172 | m = M6T; 173 | } else if (ratio <= K7T) { 174 | b = B7T; 175 | m = M7T; 176 | } else if (ratio > K8T) { 177 | b = B8T; 178 | m = M8T; 179 | } 180 | break; 181 | case 1:// CS package 182 | if ((ratio >= 0) && (ratio <= K1C)) { 183 | b = B1C; 184 | m = M1C; 185 | } else if (ratio <= K2C) { 186 | b = B2C; 187 | m = M2C; 188 | } else if (ratio <= K3C) { 189 | b = B3C; 190 | m = M3C; 191 | } else if (ratio <= K4C) { 192 | b = B4C; 193 | m = M4C; 194 | } else if (ratio <= K5C) { 195 | b = B5C; 196 | m = M5C; 197 | } else if (ratio <= K6C) { 198 | b = B6C; 199 | m = M6C; 200 | } else if (ratio <= K7C) { 201 | b = B7C; 202 | m = M7C; 203 | } 204 | } 205 | temp = ((channel0 * b) - (channel1 * m)); 206 | if (temp < 0) { 207 | temp = 0; 208 | } 209 | temp += (1 << (LUX_SCALE - 1)); 210 | // strip off fractional portion 211 | lux = temp >> LUX_SCALE; 212 | return (lux); 213 | } 214 | 215 | bool TSL2561_CalculateLux::checkHadTimeout(){ 216 | bool timeout = hadTimeout; 217 | hadTimeout = false; 218 | return timeout; 219 | } 220 | 221 | TSL2561_CalculateLux TSL2561; 222 | 223 | 224 | -------------------------------------------------------------------------------- /Digital_Light_TSL2561.h: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_TSL2561.h 3 | A library for TSL2561 4 | 5 | Copyright (c) 2012 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : zhangkun 8 | Create Time: 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | #ifndef Digital_Light_TSL2561_H 32 | #define Digital_Light_TSL2561_H 33 | 34 | #include 35 | 36 | #define TSL2561_Control 0x80 37 | #define TSL2561_Timing 0x81 38 | #define TSL2561_Interrupt 0x86 39 | #define TSL2561_Channal0L 0x8C 40 | #define TSL2561_Channal0H 0x8D 41 | #define TSL2561_Channal1L 0x8E 42 | #define TSL2561_Channal1H 0x8F 43 | 44 | #define TSL2561_Address 0x29 //device address 45 | 46 | #define LUX_SCALE 14 // scale by 2^14 47 | #define RATIO_SCALE 9 // scale ratio by 2^9 48 | #define CH_SCALE 10 // scale channel values by 2^10 49 | #define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE 50 | #define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE 51 | 52 | #define K1T 0x0040 // 0.125 * 2^RATIO_SCALE 53 | #define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE 54 | #define M1T 0x01be // 0.0272 * 2^LUX_SCALE 55 | #define K2T 0x0080 // 0.250 * 2^RATIO_SCA 56 | #define B2T 0x0214 // 0.0325 * 2^LUX_SCALE 57 | #define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE 58 | #define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE 59 | #define B3T 0x023f // 0.0351 * 2^LUX_SCALE 60 | #define M3T 0x037b // 0.0544 * 2^LUX_SCALE 61 | #define K4T 0x0100 // 0.50 * 2^RATIO_SCALE 62 | #define B4T 0x0270 // 0.0381 * 2^LUX_SCALE 63 | #define M4T 0x03fe // 0.0624 * 2^LUX_SCALE 64 | #define K5T 0x0138 // 0.61 * 2^RATIO_SCALE 65 | #define B5T 0x016f // 0.0224 * 2^LUX_SCALE 66 | #define M5T 0x01fc // 0.0310 * 2^LUX_SCALE 67 | #define K6T 0x019a // 0.80 * 2^RATIO_SCALE 68 | #define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE 69 | #define M6T 0x00fb // 0.0153 * 2^LUX_SCALE 70 | #define K7T 0x029a // 1.3 * 2^RATIO_SCALE 71 | #define B7T 0x0018 // 0.00146 * 2^LUX_SCALE 72 | #define M7T 0x0012 // 0.00112 * 2^LUX_SCALE 73 | #define K8T 0x029a // 1.3 * 2^RATIO_SCALE 74 | #define B8T 0x0000 // 0.000 * 2^LUX_SCALE 75 | #define M8T 0x0000 // 0.000 * 2^LUX_SCALE 76 | 77 | 78 | 79 | #define K1C 0x0043 // 0.130 * 2^RATIO_SCALE 80 | #define B1C 0x0204 // 0.0315 * 2^LUX_SCALE 81 | #define M1C 0x01ad // 0.0262 * 2^LUX_SCALE 82 | #define K2C 0x0085 // 0.260 * 2^RATIO_SCALE 83 | #define B2C 0x0228 // 0.0337 * 2^LUX_SCALE 84 | #define M2C 0x02c1 // 0.0430 * 2^LUX_SCALE 85 | #define K3C 0x00c8 // 0.390 * 2^RATIO_SCALE 86 | #define B3C 0x0253 // 0.0363 * 2^LUX_SCALE 87 | #define M3C 0x0363 // 0.0529 * 2^LUX_SCALE 88 | #define K4C 0x010a // 0.520 * 2^RATIO_SCALE 89 | #define B4C 0x0282 // 0.0392 * 2^LUX_SCALE 90 | #define M4C 0x03df // 0.0605 * 2^LUX_SCALE 91 | #define K5C 0x014d // 0.65 * 2^RATIO_SCALE 92 | #define B5C 0x0177 // 0.0229 * 2^LUX_SCALE 93 | #define M5C 0x01dd // 0.0291 * 2^LUX_SCALE 94 | #define K6C 0x019a // 0.80 * 2^RATIO_SCALE 95 | #define B6C 0x0101 // 0.0157 * 2^LUX_SCALE 96 | #define M6C 0x0127 // 0.0180 * 2^LUX_SCALE 97 | #define K7C 0x029a // 1.3 * 2^RATIO_SCALE 98 | #define B7C 0x0037 // 0.00338 * 2^LUX_SCALE 99 | #define M7C 0x002b // 0.00260 * 2^LUX_SCALE 100 | #define K8C 0x029a // 1.3 * 2^RATIO_SCALE 101 | #define B8C 0x0000 // 0.000 * 2^LUX_SCALE 102 | #define M8C 0x0000 // 0.000 * 2^LUX_SCALE 103 | 104 | /** No timeout while waiting for a read response from the digital light sensor. */ 105 | #define TSL2561_NO_READ_TIMEOUT 0 106 | 107 | class TSL2561_CalculateLux { 108 | public: 109 | 110 | /** 111 | * Create a new interface to a TSL2561 light sensor. 112 | * 113 | * @param read_timeout The timeout to wait for read responses in microseconds. 114 | */ 115 | explicit TSL2561_CalculateLux(uint32_t read_timeout = TSL2561_NO_READ_TIMEOUT); 116 | 117 | signed long readVisibleLux(); 118 | uint16_t readIRLuminosity(); 119 | uint16_t readFSpecLuminosity(); 120 | unsigned long calculateLux(unsigned int iGain, unsigned int tInt, int iType); 121 | void getLux(void); 122 | void init(void); 123 | uint8_t readRegister(int deviceAddress, int address); 124 | void writeRegister(int deviceAddress, int address, uint8_t val); 125 | 126 | /** 127 | * Check whether there was a read timeout since the last call to this function 128 | * and clear the flag. 129 | * 130 | * @return whether there was a read timeout since the last check. 131 | */ 132 | bool checkHadTimeout(); 133 | private: 134 | uint8_t CH0_LOW, CH0_HIGH, CH1_LOW, CH1_HIGH; 135 | uint16_t ch0, ch1; 136 | unsigned long chScale; 137 | unsigned long channel1; 138 | unsigned long channel0; 139 | unsigned long ratio1; 140 | unsigned int b; 141 | unsigned int m; 142 | unsigned long temp; 143 | unsigned long lux; 144 | 145 | /** 146 | * The configured read timeout in microseconds. 147 | */ 148 | uint32_t read_timeout; 149 | 150 | /** 151 | * Whether a read timeout occurred since the last time checkHadTimeout was called. 152 | */ 153 | bool hadTimeout = false; 154 | }; 155 | extern TSL2561_CalculateLux TSL2561; 156 | #endif 157 | 158 | 159 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Seeed Technology Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Grove - Digital Light Sensor [![Build Status](https://travis-ci.com/Seeed-Studio/Grove_Digital_Light_Sensor.svg?branch=master)](https://travis-ci.com/Seeed-Studio/Grove_Digital_Light_Sensor) 2 | --------------------------------------------------------- 3 | 4 | Version 1 5 | 6 | 7 | 8 | This module is based on the I2C light-to-digital converter TSL2561 to transform light intensity to a digital signal. Different from traditional analog light sensor, as [Grove - Light Sensor](http://www.seeedstudio.com/depot/grove-light-sensorp-p-1253.html?cPath=144_148), this digital module features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum. 9 | 10 | You can switch between three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode. When running under the human visible mode, this sensor will give you readings just close to your eye feelings. 11 | 12 | Version 2 (Fixme when we have a bazaar image) 13 | 14 | The version 2 hasn't been on the shelf now. 15 | 16 | 17 | 18 | # Usage: 19 | 20 | This is an Arduino Library of Grove - Digital Light Sensor (two versions). 21 | 22 | ### Include the corresponding header file 23 | 24 | Version 1: 25 | 26 | #include 27 | 28 | Version 2: 29 | 30 | #include 31 | 32 | ### Initialization: 33 | 34 | //for v1 35 | TSL2561.init(); 36 | //for v2 37 | ISL29035.init(); 38 | 39 | ### Get the Lux reading of visible light 40 | 41 | unsigned long readVisibleLux(); 42 | 43 |
44 | 45 | For more information, please refer to [wiki page](http://www.seeedstudio.com/wiki/Grove_-_Digital_Light_Sensor). 46 | 47 | ---- 48 | 49 | This software is written by zhangkun for seeed studio and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
50 | 51 | Contributing to this software is warmly welcomed. You can do this basically by
52 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
53 | for operating guide). Adding change log and your contact into file header is encouraged.
54 | Thanks for your contribution. 55 | 56 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. 57 | 58 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Grove_Digital_Light_Sensor)](https://github.com/igrigorik/ga-beacon) 59 | -------------------------------------------------------------------------------- /examples/Digital_Light_Sensor/Digital_Light_Sensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_Sensor.ino 3 | A library for TSL2561 4 | 5 | Copyright (c) 2012 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : zhangkun 8 | Create Time: 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | void setup() { 35 | Wire.begin(); 36 | Serial.begin(9600); 37 | TSL2561.init(); 38 | } 39 | 40 | void loop() { 41 | Serial.print("The Light value is: "); 42 | Serial.println(TSL2561.readVisibleLux()); 43 | delay(1000); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/Digital_Light_Sensor_IR/Digital_Light_Sensor_IR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_Sensor.ino 3 | A library for TSL2561 4 | 5 | Copyright (c) 2019 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : hongtai.liu 8 | Create Time: 6/11/2019 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | void setup() { 35 | Wire.begin(); 36 | Serial.begin(9600); 37 | TSL2561.init(); 38 | } 39 | 40 | void loop() { 41 | Serial.print("The Infrared value is: "); 42 | Serial.println(TSL2561.readIRLuminosity()); //read Infrared channel value only, not convert to lux. 43 | Serial.print("The Full Spectrum value is: "); 44 | Serial.println(TSL2561.readFSpecLuminosity());///read Full Spectrum channel value only, not convert to lux. 45 | delay(1000); 46 | } 47 | -------------------------------------------------------------------------------- /examples/Digital_Light_Sensor_v2/Digital_Light_Sensor_v2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital_Light_Sensor_v2.ino 3 | A library for ISL29035 4 | 5 | Copyright (c) 2017 seeed technology inc. 6 | Website : www.seeed.cc 7 | Author : Jack 8 | Create Time: 9 | Change Log : 10 | 11 | The MIT License (MIT) 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include "Digital_Light_ISL29035.h" 34 | 35 | void setup() { 36 | Wire.begin(); 37 | Serial.begin(9600); 38 | 39 | if (ISL29035.init() < 0) { 40 | Serial.println("ISL29035 init failed!"); 41 | } 42 | 43 | /** 44 | Set the full scale range for lux measurement. 45 | A lower range offers better resolution, it's suitable in a dim env, 46 | while in light env, a higher range should be selected. 47 | 0: 1000 lux, 1: 4000 lux, 2: 16000 lux, 3: 64000 lux 48 | default index is 0. 49 | */ 50 | // ISL29035.setFullScaleLuxRangeIndex(DEFAULT_LUX_RANGE_INDEX); 51 | /** 52 | Set the integration time. 53 | 0: 105ms, 1: 6.5ms, 2: 0.41ms, 3: 0.0256 54 | default index is 0. 55 | */ 56 | // ISL29035.setIntegrationTimeIndex(DEFAULT_INTEGRATION_TIME_INDEX); 57 | 58 | /** 59 | The integration time is a trade-off between speed and accuracy. 60 | Fast integration however gains lower resolution of ADC. 61 | */ 62 | } 63 | 64 | void loop() { 65 | Serial.println("----"); 66 | Serial.print("Ambient light intensity: "); 67 | Serial.println(ISL29035.readVisibleLux()); 68 | 69 | Serial.print("IR intensity: "); 70 | Serial.println(ISL29035.readIRLux()); 71 | 72 | Serial.print("Exposure value: "); 73 | Serial.println(ISL29035.readEV()); 74 | 75 | delay(1000); 76 | } 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | 2 | ####################################### 3 | # Syntax Coloring Map For 4 | ####################################### 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | 10 | 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | readVisibleLux KEYWORD2 16 | calculateLux KEYWORD2 17 | getLux KEYWORD2 18 | init KEYWORD2 19 | readRegister KEYWORD2 20 | writeRegister KEYWORD2 21 | 22 | DigitalLightISL29035 KEYWORD2 23 | setFullScaleLuxRangeIndex KEYWORD2 24 | setIntegrationTimeIndex KEYWORD2 25 | readVisibleLux KEYWORD2 26 | readIRLuminosity KEYWORD2 27 | readFSpecLuminosity KEYWORD2 28 | readEV KEYWORD2 29 | test KEYWORD2 30 | 31 | 32 | ####################################### 33 | # Constants (LITERAL1) 34 | ####################################### -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Grove - Digital Light Sensor 2 | version=2.0.0 3 | author=Seeed Studio 4 | maintainer=Seeed Studio 5 | sentence=Arduino library to control Grove - Digital Light Sensor(TSL2561/ISL29035). 6 | paragraph=Arduino library to control Grove - Digital Light Sensor(TSL2561/ISL29035). 7 | category=Sensors 8 | url=https://github.com/Seeed-Studio/Grove_Digital_Light_Sensor 9 | architectures=* 10 | --------------------------------------------------------------------------------