Skip to content

Commit 411e256

Browse files
committed
adding ltc4316 examples with the aht20
Adding Arduino and CircuitPython examples using two AHT20 sensors with one translated to 0x68 with an LTC4316
1 parent 9c6f62b commit 411e256

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: 2023 Carter Nelson for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// LTC4315 with two AHT20 sensors example
6+
// Set the LTC4315 switch A5 on and switch A4 off
7+
// The translated sensor will be on address 0x68
8+
9+
#include <Adafruit_AHTX0.h>
10+
11+
Adafruit_AHTX0 default_aht;
12+
Adafruit_AHTX0 ltc4316_aht;
13+
14+
void setup() {
15+
Serial.begin(115200);
16+
while ( !Serial ) delay(10);
17+
Serial.println("Adafruit AHT20 with LTC4316 demo!");
18+
if (! default_aht.begin(&Wire, 0, 0x38)) {
19+
Serial.println("Could not find AHT20 on 0x38? Check wiring.");
20+
while (1) delay(10);
21+
}
22+
if (! ltc4316_aht.begin(&Wire, 0, 0x68)) {
23+
Serial.println("Could not find AHT20 attached to LTC4316 on 0x68? Check wiring and switches");
24+
while (1) delay(10);
25+
}
26+
Serial.println("AHT20 sensors found on 0x38 and 0x68");
27+
}
28+
29+
void loop() {
30+
sensors_event_t humidity0, temp0;
31+
sensors_event_t humidity1, temp1;
32+
default_aht.getEvent(&humidity0, &temp0);// populate temp and humidity objects with fresh data
33+
ltc4316_aht.getEvent(&humidity1, &temp1);// populate temp and humidity objects with fresh data
34+
Serial.println("AHT20 on 0x38:");
35+
Serial.print("Temperature: "); Serial.print(temp0.temperature); Serial.println(" degrees C");
36+
Serial.print("Humidity: "); Serial.print(humidity0.relative_humidity); Serial.println("% rH");
37+
Serial.println();
38+
Serial.println("AHT20 on 0x68:");
39+
Serial.print("Temperature: "); Serial.print(temp1.temperature); Serial.println(" degrees C");
40+
Serial.print("Humidity: "); Serial.print(humidity1.relative_humidity); Serial.println("% rH");
41+
Serial.println();
42+
43+
delay(500);
44+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
LTC4315 with two AHT20 sensors example
6+
Set the LTC4315 switch A5 on and switch A4 off
7+
The translated sensor will be on address 0x68
8+
"""
9+
10+
import time
11+
import board
12+
import adafruit_ahtx0
13+
14+
# Create sensor object, communicating over the board's default I2C bus
15+
i2c = board.I2C() # uses board.SCL and board.SDA
16+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
17+
default_sensor = adafruit_ahtx0.AHTx0(i2c, 0x38)
18+
translated_sensor = adafruit_ahtx0.AHTx0(i2c, 0x68)
19+
20+
while True:
21+
print("\nAHT20 at 0x38:")
22+
print(f"Temperature: {default_sensor.temperature:0.1f} C")
23+
print(f"Humidity: {default_sensor.relative_humidity:0.1f} %")
24+
print("\nAHT20 at 0x68:")
25+
print(f"Temperature: {translated_sensor.temperature:0.1f} C")
26+
print(f"Humidity: {translated_sensor.relative_humidity:0.1f} %")
27+
time.sleep(2)

0 commit comments

Comments
 (0)