/* Description: **** Weather Station YO6PIR - 2020 **** ARDUINO UNO alimentat la 3V din baterii Afisaj LCD Nokia 5110 cuplat direct Senzor BP-180: Presiune, Altitude & Temperatura Senzor DHT11: Humidity, Dew-Point Battery Voltage Supervizor Hardware SPI LCD Nokia5510: ------------------------ pin 13 - SCK is LCD serial clock (SCLK) pin 11 - MOSI is LCD DIN pin 5 - Data/Command select (D/C) pin 4 - LCD chip select (CS) pin 3 - LCD reset (RST) BP-180 pins: ---------------------- 3V - Vin GND - GND pin A5 - SCL pin A4 - SDA DHT11 pins: --------------------- 3V - Vin GND - GND NC - pin 2 - Data References: - https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup- - https://github.com/adafruit/Adafruit-GFX-Library - https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library */ #include #include #include #include #include #include Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3); int idDHT11pin = 2; //Digital pin for comunications int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) //int val = 0; //Initialize the Batt input value //declaration void dht11_wrapper(); // must be declared before the lib initialization // Lib initiate idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); // This wrapper is in charge of calling // mus be defined like this for the lib work void dht11_wrapper() { DHT11.isrCallback(); } SFE_BMP180 bmp180; void setup() { // pinMode(analogInput, INPUT); //assigning the input port Serial.begin(9600); //BaudRate // initialize display display.begin(); // set contrast display.setContrast(50); // initialize BMP180 bool success = bmp180.begin(); } // main loop void loop() { // clear display display.clearDisplay(); //display.display(); // take measurement double T, P, A, H, D, Dew; bool success = measureBMP180(T, P, A); // don't update for unsuccessful measurement if (!success) return; // Masurare DHT11 Humidity, Temperature DHT11.acquire(); while (DHT11.acquiring()); int result = DHT11.getStatus(); // display display.setTextSize(1); display.setTextColor(BLACK); display.setCursor(0,0); String strMsg; // Temperature char strT[16]; dtostrf(T, 3, 1, strT); strMsg += "Temp.| "; strMsg += strT; strMsg += " C\n"; // Humidity H = DHT11.getHumidity(), 2; char strH[16]; dtostrf(H, 2, 0, strH); strMsg +="Humid| "; strMsg +=strH; strMsg +=" %\n"; // Dew Point D = DHT11.getDewPoint(), 2; Dew = D + H; char strDew[16]; dtostrf(Dew, 2, 0, strDew); char strD[16]; dtostrf(D, 2, 0, strD); strMsg +="Dew-p|"; strMsg +=strD; strMsg +="C("; strMsg += strDew; strMsg +=")\n"; // Altitude char strA[16]; dtostrf(A, 4, 0, strA); strMsg += "Alt. |"; strMsg += strA; strMsg += " m\n"; // Pressure char strP[16]; dtostrf(P, 4, 0, strP); strMsg += "Press|"; strMsg += strP; strMsg += " hPA"; // Battery Tension double Vbat = 0.00; //Battery Voltage Vbat= readVcc(); //read real internal reference Vcc Vbat = Vbat / 1000; //Convert in Volts char strBat[16]; dtostrf(Vbat, 1, 2, strBat); // Format string Vbat strMsg += "Batt.| "; strMsg += strBat; strMsg += " V\n"; display.println(strMsg); // show on display display.display(); // wait delay(5000); } // Read internal reference Avcc long readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both float result = (high<<8) | low; result = (1125300L / result); // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in milivolts } // get T, P, A readings from BMP180 bool measureBMP180(double& temp, double& pr, double& al) { char status; double T,P,p0,a; bool success = false; // Start a temperature measurement: // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = bmp180.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed temperature measurement: // Note that the measurement is stored in the variable T. // Function returns 1 if successful, 0 if failure. status = bmp180.getTemperature(T); if (status != 0) { // save temp temp = T; // Start a pressure measurement: // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = bmp180.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed pressure measurement: // Note that the measurement is stored in the variable P. // Note also that the function requires the previous temperature measurement (T). // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) // Function returns 1 if successful, 0 if failure. status = bmp180.getPressure(P,T); if (status != 0) { // save pressure pr = P; // calculate altitude using pressure at sea level al = bmp180.altitude(P, 1013.25); // set flag success = true; } } } } return success; }