diff --git a/arduino/thempScreen/thempScreen.ino b/arduino/thempScreen/thempScreen.ino new file mode 100644 index 0000000..52628e7 --- /dev/null +++ b/arduino/thempScreen/thempScreen.ino @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include "DHT.h" //For the themp and humiditi sensor + + +/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/ +#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's +//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's + +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 64 // OLED display height, in pixels +#define OLED_RESET -1 // QT-PY / XIAO +Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +//dht 11 sensor stuff +#define DHTTYPE DHT11 // DHT 11 +#define DHTPIN 42 // Digital pin connected to the DHT sensor +DHT dht(DHTPIN, DHTTYPE); + +float humiditities; +float themp; + +int debug = 0; + + +void setup() { + Serial.begin(115200); + display.begin(i2c_Address, true); // Address 0x3C default + + display.clearDisplay(); + dht.begin(); //initialising the dht11 + + display.setTextSize(2); + display.setTextColor(SH110X_WHITE); + display.setCursor(0, 0); + // display.clearDisplay(); + display.println("Welkom You life"); + display.display(); + delay(500); + display.clearDisplay(); + +} + +void loop() { + // put your main code here, to run repeatedly: + thempReading(); + + display.setCursor(0, 0); + display.println((String) "Temp: " + int(themp) + "C" + '\n' + "Humi: " + int(humiditities) + "%"); + display.display(); + +} + +void thempReading(){ + delay(1000); //Sensor can only read every 2 sec but we want it to run asinc + display.clearDisplay(); + + + humiditities = dht.readHumidity(); + // Read temperature as Celsius (the default) + themp = dht.readTemperature(); + + if (debug == 1){ + Serial.println((String)humiditities + "% " + themp + "C"); + } + +}