{"id":13893757,"url":"https://github.com/RobTillaart/AM232X","last_synced_at":"2025-07-17T08:30:43.987Z","repository":{"id":37043411,"uuid":"250009589","full_name":"RobTillaart/AM232X","owner":"RobTillaart","description":"Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor","archived":false,"fork":false,"pushed_at":"2024-04-13T08:50:31.000Z","size":62,"stargazers_count":13,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T22:04:52.016Z","etag":null,"topics":["arduino","humidity","i2c","sensor","temperature"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-03-25T15:00:58.000Z","updated_at":"2024-05-11T14:36:10.000Z","dependencies_parsed_at":"2024-11-19T06:41:44.970Z","dependency_job_id":null,"html_url":"https://github.com/RobTillaart/AM232X","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/RobTillaart/AM232X","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FAM232X","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FAM232X/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FAM232X/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FAM232X/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/AM232X/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FAM232X/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265585272,"owners_count":23792712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","humidity","i2c","sensor","temperature"],"created_at":"2024-08-06T18:01:16.436Z","updated_at":"2025-07-17T08:30:43.706Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":["C++"],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/AM232X/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/AM232X/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AM232X/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/AM232X/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AM232X/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AM232X.svg)](https://github.com/RobTillaart/AM232X/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AM232X/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/AM232X.svg?maxAge=3600)](https://github.com/RobTillaart/AM232X/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AM232X.svg)](https://registry.platformio.org/libraries/robtillaart/AM232X)\n\n\n# AM232X\n\nArduino library for AM2320 AM2321 and AM2322 I2C temperature and humidity sensor.\n\n\n## Description\n\nAM232X is a sensor similar to the DHT12 with an I2C interface. \nAlthough in theory this could enable multiple sensors on one bus\nthe AM232X has a fixed address **0x5C** so one need to implement a \nmultiplexing strategy to have multiple sensors in practice. \nSee multiplexing below.\n\nThis library works also for the **AM2315** which has a library of its own - https://github.com/RobTillaart/AM2315\n\n\n#### Typical parameters\n\n|             |  range     | accuracy | repeatability |\n|:------------|:----------:|:--------:|:-------------:|\n| Temperature | -40 - 80   | 0.5°C    |  ±0.1         |\n| Humidity    | 0.0 - 99.9 | ±3%      |  ±0.1         |\n| Sample time | 2 seconds  |          |               |\n\n\n#### Hardware connection\n\n```\n//  AM232X PIN layout             AM2315 COLOR\n//  ============================================\n//   bottom view  DESCRIPTION     COLOR\n//       +---+\n//       |o  |       VDD          RED\n//       |o  |       SDA          YELLOW\n//       |o  |       GND          BLACK\n//       |o  |       SCL          GREY\n//       +---+\n//\n// do not forget pull up resistors between SDA, SCL and VDD.\n```\n\n\n#### I2C clock speed\n\nThe datasheet states the AM2320 should be used on 100 KHz I2C only.\n\nTODO measure and verify (see AM2315)\n\n\n## One Wire Protocol\n\nThe AM2320, AM2321 and AM2322 can also be read by using a \"OneWire\" protocol.\nThis protocol is identical to the DHT22 and will only provide temperature,\nhumidity and a CRC. See issue #26.\n\nIf one wants to use this protocol, one can use https://github.com/RobTillaart/DHTNew\nand optionally force the type to 22.\n\nIf problems arise with the \"OneWire\" protocol, please let me know and \nfile the issues under DHTNew.\n\n\n## Interface\n\n```cpp\n#include \"AM232X.h\"\n```\n\nSince 0.4.2 the library provides specific classes for the AM2320, AM2321 and AM2322 which have the same interface.\n\n\n#### Constructor\n\n- **AM232X(TwoWire \\*wire = \u0026Wire)** constructor, default using Wire (I2C bus), \noptionally set to Wire0 .. WireN.\n- **bool begin()** initializer for class.\nReturns true if fixed device address 0x5C is connected.\n- **bool isConnected(uint16_t timeout = 3000)** returns true if the fixed device address 0x5C is found on I2C bus.\nAs the device can be in sleep modus it will retry for the defined timeout (in micros) with a minimum of 1 try. \nminimum = 800 us and maximum = 3000 us according to datasheet.\n\n\n#### Core\n\n- **int read()** read the sensor and store the values internally.\nReturns the status of the read which should be **AM232X_OK** == 0.\n- **float getHumidity()** returns the last read humidity + optional offset, \nor **AM232X_INVALID_VALUE** == -999 in case of error. \nThis error can be suppressed, see below.\n- **float getTemperature()** returns the last read temperature + optional offset,\nor **AM232X_INVALID_VALUE** == -999 in case of error. \nThis error can be suppressed, see below.\n- **uint32_t lastRead()** returns the timestamp in milliseconds since startup of the last successful read.\n\n\n#### Offset\n\n- **void setHumOffset(float offset = 0)** set an offset for humidity to calibrate (1st order) the sensor.\nDefault offset = 0, so no parameter will reset the offset to 0.\n- **float getHumOffset()** return the current humidity offset, default 0.\n- **void setTempOffset(float offset = 0)** set an offset for temperature to calibrate (1st order) the sensor.\nDefault offset = 0, so no parameter will reset the offset to 0.\n- **float getTempOffset()** return the current temperature offset, default 0.\n\n\n#### Control\n\nFunctions to adjust the communication with the sensor.\n\n- **void setReadDelay(uint16_t readDelay = 0)** Tunes the time it waits before actual read can be done.\nSet readDelay to 0 will reset it to 2000 ms effective the next **read()**.\n- **uint16_t getReadDelay()** returns the current readDelay in milliseconds. \nNote that a value of zero (reset) will return 0 before the call and 2000 after the call to **read()**.\n- **bool wakeUp()** function that will try for 3 milliseconds to wake up the sensor.\nThis can be done before an actual read to minimize the **read()** call.\n- **void setSuppressError(bool b)** suppress error values of **AM232X_INVALID_VALUE** == -999.\n=\u003e you need to check the return value of read() instead.  \nThis can be used to keep spikes out of your graphs / logs. \n- **bool getSuppressError()**  returns the current suppression setting.\n\n\n#### Metadata\n\nCheck datasheet for details.\n\n- **int getModel()** idem\n- **int getVersion()** idem\n- **uint32_t getDeviceID()** idem\n- **int setStatus(uint8_t value)**\n- **int getStatus()**\n\n\n#### User registers\n\nCheck datasheet for details.\n\n- **int setUserRegisterA(int value)**\n- **int setUserRegisterB(int value)**\n- **int getUserRegisterA()**\n- **int getUserRegisterB()**\n\n\n#### Error codes\n\n| name                              | value | notes       |\n|:----------------------------------|------:|:------------|\n| AM232X_OK                         |  0    |\n| AM232X_ERROR_UNKNOWN              |  -10  |\n| AM232X_ERROR_CONNECT              |  -11  |\n| AM232X_ERROR_FUNCTION             |  -12  |\n| AM232X_ERROR_ADDRESS              |  -13  |\n| AM232X_ERROR_REGISTER             |  -14  |\n| AM232X_ERROR_CRC_1                |  -15  |\n| AM232X_ERROR_CRC_2                |  -16  |\n| AM232X_ERROR_WRITE_DISABLED       |  -17  |\n| AM232X_ERROR_WRITE_COUNT          |  -18  |\n| AM232X_MISSING_BYTES              |  -19  |\n| AM232X_READ_TOO_FAST              |  -20  |\n| AM232X_HUMIDITY_OUT_OF_RANGE      |  -100 | not used by default.\n| AM232X_TEMPERATURE_OUT_OF_RANGE   |  -101 | not used by default.\n| AM232X_INVALID_VALUE              |  -999 | can be suppressed. \n\n\n## Operation\n\nSee examples\n\nIn **setup()** you have to call the **begin()** to initialize \nthe Wire library and do an initial **read()** to fill the variables temperature and humidity. \nTo access these values one must use **getTemperature()** and **getHumidity()**. \nMultiple calls will give the same values until **read()** is called again.\n\nNote that the sensor can go into sleep mode after 3 seconds after last read, \nso one might need to call **wakeUp()** before the **read()**.\n\n\n## Multiplexing \n\nMultiplexing the **AM232X** can be done in several ways.\nThis is not a complete list or tutorial but should get you started.\n\n1. Control the power line by means of an extra pin (+ transistor). \nOnly switch on the sensor you want to use. Drawback might be time \nthe sensor takes to boot and to be ready for the first measurement.\n2. Use an AND gate between the I2C SCL (clock) line and the I2C SCL \npin of the sensors. This way one can enable / disable communication \nper sensor. This will still need an IO pin per sensor but does not \nhave the \"boot time\" constraint mentioned above.\nyou may use a **PCF8574** to control the AND gates.\nhttps://github.com/RobTillaart/PCF8574\n3. Use a **TCA9548A** I2C Multiplexer, or similar. https://github.com/RobTillaart/TCA9548\n\nWhich method fit your application depends on your requirements and constraints.\n\n\n## Future\n\n#### Must\n\n- update documentation\n- test more (other platforms)\n\n#### Should\n\n- keep in sync with AM2315 class\n  - merge in a far future.\n- update unit test\n- add examples\n\n#### Could\n\n- I2C performance measurements\n  - clock speed \u003e 170 - see AM2315\n\n\n#### Wont\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FAM232X","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobTillaart%2FAM232X","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FAM232X/lists"}