Created
March 8, 2019 22:28
-
-
Save wdog/7fbf8dd19825d1651d09e1a7213188d7 to your computer and use it in GitHub Desktop.
LCD 1602 w/ BMP280 + MQ7 + RTC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include "RTClib.h" | |
RTC_DS1307 RTC; | |
#include <LiquidCrystal_I2C.h> | |
#include <SPI.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BMP280.h> | |
/**********************************************************/ | |
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
/*********************************************************/ | |
Adafruit_BMP280 bme; // I2C | |
/*********************************************************/ | |
#include "MQ7.h" | |
MQ7 mq7(0, 5.0);// param[1] : Analog pin number, param[2] : Sensor Vcc value | |
// Declare lcd as a LiquidCrystal Object | |
int pi = 0; | |
int j = 0; | |
int k = 0; | |
int delayTime2 = 150; // Delay between shifts | |
char buffer1[20]; | |
char buffer2[20]; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Starting test ..."); | |
// BMP280 | |
Wire.begin(); | |
Wire.beginTransmission(0x27); | |
if (!bme.begin()) { | |
Serial.println("Could not find a valid BMP280 sensor, check wiring!"); | |
while (1); | |
} | |
// RTC | |
RTC.begin(); | |
while (! RTC.isrunning()) { | |
Serial.println("RTC is NOT running!"); | |
// This will reflect the time that your sketch was compiled | |
RTC.adjust(DateTime(__DATE__, __TIME__)); | |
} | |
lcd.init(); | |
lcd.backlight(); | |
lcd.home(); | |
lcd.clear(); | |
} | |
void loop() { | |
Serial.println(mq7.getPPM()); | |
scrollInFromRight(0, ( "CO: " + String(mq7.getPPM()) + " PPM" ).c_str() , 0 ); | |
delay(2000); | |
lcd.clear(); | |
//// | |
scrollInFromRight(0, ("Tmp: " + String(bme.readTemperature()) + " C" ).c_str() , 0 ); | |
scrollInFromRight(1, ("Psr: " + String(bme.readPressure() / 100) + " hPa").c_str() , 0 ); | |
delay(2000); | |
lcd.clear(); | |
////// | |
DateTime now = RTC.now(); | |
sprintf(buffer1, "%02d:%02d:%02d", now.hour(), now.minute(), now.second()); | |
sprintf(buffer2, "%02d/%02d/%d", now.day(), now.month(), now.year()); | |
scrollInFromRight(0, buffer1 , 0 ); | |
scrollInFromRight(1, buffer2 , 0 ); | |
delay(2000); | |
lcd.clear(); | |
/******************/ | |
} | |
void scrollInFromRight (int line, char str1[], int mustRun) { | |
if ( mustRun == 1 ) { | |
// Written by R. Jordan Kreindler June 2016 | |
pi = strlen(str1); | |
for (j = 16; j >= 0; j--) { | |
lcd.setCursor(0, line); | |
for (k = 0; k <= 15; k++) { | |
lcd.print(" "); // Clear line | |
} | |
lcd.setCursor(j, line); | |
lcd.print(str1); | |
delay(delayTime2); | |
} | |
} else { | |
lcd.setCursor(0,line); | |
lcd.print(str1); | |
} | |
} | |
void scrollInFromLeft (int line, char str1[]) { | |
// Written by R. Jordan Kreindler June 2016 | |
pi = 40 - strlen(str1); | |
line = line - 1; | |
for (j = pi; j <= pi + 16; j++) { | |
for (k = 0; k <= 15; k++) { | |
lcd.print(" "); // Clear line | |
} | |
lcd.setCursor(j, line); | |
lcd.print(str1); | |
delay(delayTime2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment