├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md └── workflows │ ├── run-ci-arduino.yml │ ├── stale.yml │ └── sync_issues.yml ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── examples └── BasicRead │ └── BasicRead.ino ├── library.json ├── library.properties └── src ├── AHT20.h └── ATH20.cpp /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.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 | .vscode/ -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at zuobaozhu@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing guidelines 2 | 3 | All guidelines for contributing to the Seeed_Arduino_AHT20 repository can be found at [`How to contribute guideline`](https://github.com/Seeed-Studio/Seeed_Arduino_AHT20/wiki/How_to_contribute). 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Seeed Studio 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Seeed_Arduino_AHT20 [![Build Status](https://travis-ci.com/Seeed-Studio/Seeed_Arduino_ATH20.svg?branch=master)](https://travis-ci.com/Seeed-Studio/Seeed_Arduino_ATH20) 2 | 3 | ## Introduction 4 | 5 | AHT20 is a new generation of temperature and humidity sensor embedded with a dual-row flat and no-lead SMD package, suitable for the reflow soldering. AHT20 is equipped with a newly designed ASIC chip: an improved MEMS semiconductor capacitive humidity sensor, and a standard on-chip temperature sensor. 6 | 7 | ## Usage 8 | 9 | ```c++ 10 | // ARDUINO DEMO FOR GROVE-AHT20 11 | // 12 | #include 13 | #include "AHT20.h" 14 | 15 | AHT20 AHT; 16 | 17 | void setup() 18 | { 19 | Serial.begin(115200); 20 | Serial.println("AHT20 DEMO"); 21 | AHT.begin(); 22 | } 23 | 24 | void loop() 25 | { 26 | float humi, temp; 27 | 28 | int ret = AHT.getSensor(&humi, &temp); 29 | 30 | if(ret) // GET DATA OK 31 | { 32 | Serial.print("humidity: "); 33 | Serial.print(humi*100); 34 | Serial.print("%\t temerature: "); 35 | Serial.println(temp); 36 | } 37 | else // GET DATA FAIL 38 | { 39 | Serial.println("GET DATA FROM AHT20 FAIL"); 40 | } 41 | 42 | delay(100); 43 | } 44 | 45 | // END FILE 46 | ``` 47 | 48 | ## API 49 | 50 | ### void begin() 51 | 52 | Initializing the AHT20 53 | 54 | ```c++ 55 | AHT.begin(); 56 | ``` 57 | 58 | ### bool getSensor(float *h, float *t) 59 | 60 | get all data of sensor 61 | 62 | 63 | ```c++ 64 | int ret = AHT.getSensor(&humi, &temp); 65 | ``` 66 | 67 | ### bool getTemperature(float *t) 68 | 69 | get Temperature of sensor 70 | 71 | 72 | ```c++ 73 | int ret = AHT.getTemperature(&temp); 74 | ``` 75 | 76 | ### bool getHumidity(float *h) 77 | 78 | get Humidity of sensor 79 | 80 | ```c++ 81 | int ret = AHT.getHumidity(&humi); 82 | ``` -------------------------------------------------------------------------------- /examples/BasicRead/BasicRead.ino: -------------------------------------------------------------------------------- 1 | // ARDUINO DEMO FOR GROVE-AHT20 2 | // 3 | #include 4 | #include "AHT20.h" 5 | 6 | AHT20 AHT; 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | Serial.println("AHT20 DEMO"); 12 | AHT.begin(); 13 | } 14 | 15 | void loop() 16 | { 17 | float humi, temp; 18 | 19 | int ret = AHT.getSensor(&humi, &temp); 20 | 21 | if(ret) // GET DATA OK 22 | { 23 | Serial.print("humidity: "); 24 | Serial.print(humi*100); 25 | Serial.print("%\t temerature: "); 26 | Serial.println(temp); 27 | } 28 | else // GET DATA FAIL 29 | { 30 | Serial.println("GET DATA FROM AHT20 FAIL"); 31 | } 32 | 33 | delay(100); 34 | } 35 | 36 | // END FILE -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Seeed_Arduino_AHT20", 3 | "version": "1.0.1", 4 | "keywords": "AHT20,temp,humi", 5 | "description": "A arduino library for AHT20 sensor", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/Seeed-Studio/Seeed_Arduino_AHT20" 10 | }, 11 | "authors": 12 | [ 13 | { 14 | "name": "Junjie Chen", 15 | "email": "59535940@qq.com", 16 | "maintainer": true 17 | } 18 | ], 19 | "frameworks": "arduino", 20 | "platforms": "*2" 21 | } 22 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Seeed_Arduino_AHT20 2 | version=1.0.1 3 | author=Baozhu Zuo 4 | maintainer=baozhu.zuo@gmail.com 5 | sentence=A AHT20 library for Arduino. 6 | paragraph=A AHT20 library for Arduino. 7 | category=Sensors 8 | url=https://github.com/Seeed-Studio/Seeed_Arduino_AHT20 9 | architectures=* 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/AHT20.h: -------------------------------------------------------------------------------- 1 | #ifndef __AHT20_H__ 2 | #define __AHT20_H__ 3 | 4 | #include 5 | #include 6 | 7 | class AHT20{ 8 | 9 | private: 10 | 11 | bool startSensor(); 12 | public: 13 | 14 | void begin(); 15 | bool getSensor(float *h, float *t); 16 | bool getTemperature(float *t); 17 | bool getHumidity(float *h); 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /src/ATH20.cpp: -------------------------------------------------------------------------------- 1 | // AHT20 ARDUINO LIBRARY 2 | #include "AHT20.h" 3 | 4 | void AHT20::begin() 5 | { 6 | Wire.begin(); 7 | 8 | Wire.beginTransmission(0x38); // transmit to device #8 9 | Wire.write(0xBE); 10 | Wire.endTransmission(); // stop transmitting 11 | } 12 | 13 | bool AHT20::startSensor() 14 | { 15 | Wire.beginTransmission(0x38); // transmit to device #8 16 | Wire.write(0xac); 17 | Wire.write(0x33); 18 | Wire.write(0x00); 19 | Wire.endTransmission(); // stop transmitting 20 | 21 | unsigned long timer_s = millis(); 22 | while(1) 23 | { 24 | if(millis()-timer_s > 200) return 0; // time out 25 | Wire.requestFrom(0x38, 1); 26 | 27 | while(Wire.available()) 28 | { 29 | unsigned char c = Wire.read(); 30 | if(c&0x80 != 0)return 1; // busy 31 | 32 | } 33 | 34 | delay(20); 35 | } 36 | } 37 | 38 | bool AHT20::getSensor(float *h, float *t) 39 | { 40 | startSensor(); 41 | Wire.requestFrom(0x38, 6); 42 | 43 | 44 | unsigned char str[6] ={0,}; 45 | int index = 0; 46 | while (Wire.available()) 47 | { 48 | str[index++] = Wire.read(); // receive a byte as character 49 | } 50 | if(index == 0 )return 0; 51 | if(str[0] & 0x80)return 0; 52 | 53 | unsigned long __humi = 0; 54 | unsigned long __temp = 0; 55 | 56 | __humi = str[1]; 57 | __humi <<= 8; 58 | __humi += str[2]; 59 | __humi <<= 4; 60 | __humi += str[3] >> 4; 61 | 62 | *h = (float)__humi/1048576.0; 63 | 64 | __temp = str[3]&0x0f; 65 | __temp <<=8; 66 | __temp += str[4]; 67 | __temp <<=8; 68 | __temp += str[5]; 69 | 70 | *t = (float)__temp/1048576.0*200.0-50.0; 71 | 72 | return 1; 73 | 74 | } 75 | 76 | bool AHT20::getTemperature(float *t) 77 | { 78 | float __t, __h; 79 | 80 | int ret = getSensor(&__h, &__t); 81 | if(0 == ret)return 0; 82 | 83 | *t = __t; 84 | return 1; 85 | } 86 | 87 | bool AHT20::getHumidity(float *h) 88 | { 89 | float __t, __h; 90 | 91 | int ret = getSensor(&__h, &__t); 92 | if(0 == ret)return 0; 93 | 94 | *h = __h; 95 | return 1; 96 | } 97 | --------------------------------------------------------------------------------