Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #include "RTClib.h"
- // bme/p 280 stuff
- #define BUFF_SIZE 100
- #define SEALEVELPRESSURE_HPA (1013.25)
- char buff[BUFF_SIZE];
- unsigned long delayTime;
- Adafruit_BME280 bme; // I2C
- RTC_DS3231 rtc;
- char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
- void setup() {
- Serial.begin(9600);
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- //while (1);
- }
- rtc.adjust(DateTime(__DATE__, __TIME__));
- unsigned status;
- // default settings
- status = bme.begin(0x76);
- // You can also pass in a Wire library object like &Wire2
- // status = bme.begin(0x76, &Wire2)
- if (!status) {
- Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
- Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(), 16);
- Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
- Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
- Serial.print(" ID of 0x60 represents a BME 280.\n");
- Serial.print(" ID of 0x61 represents a BME 680.\n");
- while (1) delay(10);
- }
- Serial.println("-- Default Test --");
- Serial.print("SensorID is: 0x"); Serial.println(bme.sensorID(), 16);
- delayTime = 1000;
- Serial.println();
- }
- void loop()
- {
- printBME();
- printRTC();
- delay(3000);
- }
- void printBME() {
- for (int i = 0; i < BUFF_SIZE; i++) {
- snprintf(buff, sizeof(buff), "T:%.2f, H:%.2f, P:%.2f, A:%.2f\n",
- bme.readTemperature(), bme.readHumidity(), (bme.readPressure() / 100.0F),
- bme.readAltitude(SEALEVELPRESSURE_HPA));
- }
- Serial.print(buff);
- }
- void printRTC(void) {
- DateTime now = rtc.now();
- Serial.print("Current Time: ");
- Serial.print(now.hour(), DEC);
- Serial.print(":");
- Serial.println(now.minute(), DEC);
- Serial.print("Todays Date: ");
- Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
- Serial.print(" ");
- Serial.print(now.day(), DEC);
- Serial.print("/");
- Serial.print(now.month(), DEC);
- Serial.print("/");
- Serial.println(now.year(), DEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement