1#include <Wire.h>
2#include <Adafruit_Sensor.h>
3#include <Adafruit_BME280.h>
4#include <Adafruit_SSD1306.h>
5
6Adafruit_SSD1306 display(128, 64, &Wire, 4);
7Adafruit_BME280 bme;
8float temp, hum, pressure;
9
10void TCA9548A(uint8_t bus)
11{
12 Wire.beginTransmission(0x70);
13 Wire.write(1 << bus);
14 Wire.endTransmission();
15}
16
17void setup()
18{
19 TCA9548A(1);
20 bme.begin(0x76, &Wire);
21
22 TCA9548A(2);
23 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
24 display.clearDisplay();
25 display.setTextSize(4);
26 display.setTextColor(WHITE);
27 display.setCursor(18,20);
28 display.println("HUM.");
29 display.display();
30
31 TCA9548A(3);
32 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
33 display.clearDisplay();
34 display.setTextSize(4);
35 display.setTextColor(WHITE);
36 display.setCursor(10,20);
37 display.println("PRES");
38 display.display();
39
40 TCA9548A(4);
41 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
42 display.clearDisplay();
43 display.setTextSize(4);
44 display.setTextColor(WHITE);
45 display.setCursor(10,20);
46 display.println("TEMP.");
47 display.display();
48 delay(5000);
49
50}
51
52void loop()
53{
54 TCA9548A(1);
55 temp = bme.readTemperature();
56 hum = bme.readHumidity();
57 pressure = bme.seaLevelForAltitude(700.0, bme.readPressure())/100.0;
58
59 TCA9548A(2);
60 display.setTextColor(WHITE); display.clearDisplay();
61 display.setTextSize(2); display.setCursor(0,0); display.print("Humidity %");
62 display.setTextSize(3); display.setCursor(20,30);
63 display.print(hum);
64 display.display();
65
66 TCA9548A(3);
67 display.setTextColor(WHITE); display.clearDisplay();
68 display.setTextSize(2); display.setCursor(5,0); display.print("Press. hPa");
69 display.setTextSize(3); display.setCursor(0,30);
70 display.print(pressure);
71 display.display();
72
73 TCA9548A(4);
74 display.setTextColor(WHITE); display.clearDisplay();
75 display.setTextSize(2); display.setCursor(30,0); display.print("Temp C");
76 display.setTextSize(3); display.setCursor(20,30);
77 display.print(temp);
78 display.display();
79
80 delay(1000);
81}
pat34
2 months ago
nice little project, i made one but it doesn't work, don't know why. the only difference i made in it, is to begin in address 0 of the I2C bus. I put the bme280 in sda0and the sreens in 1, 2, and 3. Mod in the code is just call TCA9548A(0) for the bme, and 1 to 3 for the screen. As it wasn't working, i add some pull up resistors on the sda and sck ligns but it produce the same result. could someone help me?