Skip to content

Commit 033c530

Browse files
authored
Merge pull request #2780 from caternuson/ltc4316_examples
Add LTC4316 examples
2 parents b31cb65 + ad46a98 commit 033c530

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-FileCopyrightText: 2024 Carter Nelson for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_BME280.h>
6+
7+
// For each device, create a separate instance.
8+
Adafruit_BME280 bme1; // BME280 #1 @ 0x77
9+
Adafruit_BME280 bme2; // BME280 #2 @ 0x37
10+
11+
void setup() {
12+
Serial.begin(9600);
13+
while(!Serial);
14+
Serial.println(F("Two BME280 Example"));
15+
16+
// NOTE: There's no need to manually call Wire.begin().
17+
// The BME280 library does that in its begin() method.
18+
19+
// In the call to begin, pass in the I2C address.
20+
// If left out, the default address is used.
21+
// But also OK to just be explicit and specify.
22+
bme1.begin(0x77); // address = 0x77 (default)
23+
bme2.begin(0x37); // address = 0x37 (behind LTC4316)
24+
}
25+
26+
27+
void loop() {
28+
float pressure1, pressure2;
29+
30+
// Read each device separately
31+
pressure1 = bme1.readPressure();
32+
pressure2 = bme2.readPressure();
33+
34+
Serial.println("------------------------------------");
35+
Serial.print("BME280 #1 Pressure = "); Serial.println(pressure1);
36+
Serial.print("BME280 #2 Pressure = "); Serial.println(pressure2);
37+
38+
delay(1000);
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2024 Carter Nelson for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from adafruit_bme280 import basic as adafruit_bme280
8+
9+
# Get the board's default I2C port
10+
i2c = board.I2C() # uses board.SCL and board.SDA
11+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
12+
13+
#--------------------------------------------------------------------
14+
# NOTE!!! This is the "special" part of the code
15+
#
16+
# Create each sensor instance
17+
# If left out, the default address is used.
18+
# But also OK to be explicit and specify address.
19+
bme1 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x77) # address = 0x77
20+
bme2 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x37) # address = 0x37
21+
#--------------------------------------------------------------------
22+
23+
print("Two BME280 Example")
24+
25+
while True:
26+
# Access each sensor via its instance
27+
pressure1 = bme1.pressure
28+
pressure2 = bme2.pressure
29+
30+
print("-"*20)
31+
print("BME280 #1 Pressure =", pressure1)
32+
print("BME280 #2 Pressure =", pressure2)
33+
34+
time.sleep(1)

0 commit comments

Comments
 (0)