AM2320_XINJIAN
is an Arduino library designed to interface with the AM2320 temperature and humidity sensor using the SoftwareWire
library, allowing I2C communication on custom pins.
- Read temperature and humidity data from the AM2320 sensor.
- Support for
SoftwareWire
to enable I2C communication on user-defined pins.
- Download the latest version of the
AM2320_XINJIAN
library. - Extract the downloaded archive and rename the folder to
AM2320_XINJIAN
. - Move the
AM2320_XINJIAN
folder to your Arduino libraries directory, typically located at~/Documents/Arduino/libraries/
. - In the Arduino IDE, navigate to Tools > Manage Libraries, search for and install the
SoftwareWire
library.
Here's an example of how to use the AM2320_XINJIAN
library:
#include <SoftwareWire.h>
#include <AM2320_XINJIAN.h>
// Define software I2C pins
SoftwareWire myWire(10, 11); // SDA = 10, SCL = 11
// Initialize the AM2320_XINJIAN sensor
AM2320_XINJIAN am2320;
void setup() {
Serial.begin(9600);
myWire.begin();
am2320.setWire(&myWire);
}
void loop() {
int status = am2320.update();
if (status == AM2320_XINJIAN_SUCCESS) {
Serial.print("Temperature: ");
Serial.print(am2320.temperatureC);
Serial.print(" °C, Humidity: ");
Serial.print(am2320.humidity);
Serial.println(" %");
} else {
Serial.print("Failed to read sensor data, error code: ");
Serial.println(status);
}
delay(2000); // Read every 2 seconds
}
This library is based on the AM2320_asukiaaa library by Asuki Kono, with modifications to support SoftwareWire
. A huge appreciate the original author's contributions.