Components and supplies
SSD1306 OLED Display
BME280/BMP280
I2C Hub 1 to 6 Expansion TCA9548A Module
Arduino Nano
Tools and machines
Soldering kit
Apps and platforms
Arduino IDE
Project description
Code
arduino code
cpp
.
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.");// Print text 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");// Print text 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.");// Print text 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}
Code Large digits
cpp
.
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; 8int 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.");// Print text 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");// Print text 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.");// Print text 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(4); display.setCursor(45,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(4); display.setCursor(15,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(4); display.setCursor(45,30); 77 display.print(temp); 78 display.display(); 79 80 delay(1000); 81}
Downloadable files
Schematic
.
Schematic gray.jpg
Comments
Only logged in users can leave comments