Mit dem Sensor BME280, einem Arduino Mega und einem 320 x 480 Pixel Display kann eine Wetterstation gebastelt werden. Angezeigt werden die Verläufe von Luftdruck, Luftfeuchtigkeit und Temperatur der letzten 36 Stunden. Dadurch erkennt man beim Blick auf das Display nicht nur die momentanen Werte, sondern kann auch abschätzen, wie sich das Wetter in den nächsten Stunden entwickeln wird.
Arduino-Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
/* Hardware connections: BME280 -> Arduino GND -> GND Vin -> 5V SDA -> pin 20 SCL -> pin 21 */ #include <UTFT.h> // Declare which fonts we will be using extern uint8_t SmallFont[]; UTFT myGLCD(CTE32HR,38,39,40,41); int xPos, yPos; // Abtastposition int value; // Grauwert int i, j; // Zählvariable float pressure[350]; // Luftdruck float temperature[350]; // Temperatur float humidity[350]; // Luftfeuchtigkeit unsigned long time_alt, time_neu, time_next; // Integer zwischen 0 und 4.294.967.295 #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; // I2C // ==================================== // === === // === SETUP === // === === // ==================================== void setup() { Serial.begin(9600); while(!Serial); // time to get serial running Serial.println(F("BME280 test")); unsigned status; // default settings // (you can also pass in a Wire library object like &Wire2) status = bme.begin(); 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); } time_alt = millis(); time_next = time_alt + 360000; //Serial.println(time_next); delay(10); // Setup the LCD myGLCD.InitLCD(); myGLCD.setFont(SmallFont); myGLCD.clrScr(); for (i = 0; i <= 349; i++) { humidity[i] = -66; pressure[i] = -66; temperature[i] = -66; } myGLCD.clrScr(); myGLCD.setColor(255, 255, 255); myGLCD.print("Wetterstation - stoppi", 150, 1); myGLCD.setColor(255, 255, 255); myGLCD.drawLine(50,290,430,290); myGLCD.drawLine(50,20,50,290); myGLCD.drawLine(430,20,430,290); myGLCD.setColor(255, 0, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.drawCircle(20,2,2); myGLCD.print("C", 26, 1); myGLCD.setColor(0, 255, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.print("%rh", 65, 1); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.print("mbar", 430, 1); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.print("h", 440, 300); myGLCD.setColor(255, 255, 255); myGLCD.drawLine(45,290,55,290); myGLCD.drawLine(45,245,55,245); myGLCD.drawLine(45,200,55,200); myGLCD.drawLine(45,155,55,155); myGLCD.drawLine(45,110,55,110); myGLCD.drawLine(45,65,55,65); myGLCD.drawLine(45,20,55,20); myGLCD.drawLine(430,290,435,290); myGLCD.drawLine(430,245,435,245); myGLCD.drawLine(430,200,435,200); myGLCD.drawLine(430,155,435,155); myGLCD.drawLine(430,110,435,110); myGLCD.drawLine(430,65,435,65); myGLCD.drawLine(430,20,435,20); myGLCD.drawLine(430,290,430,295); myGLCD.drawLine(390,290,390,295); myGLCD.drawLine(350,290,350,295); myGLCD.drawLine(310,290,310,295); myGLCD.drawLine(270,290,270,295); myGLCD.drawLine(230,290,230,295); myGLCD.drawLine(190,290,190,295); myGLCD.drawLine(150,290,150,295); myGLCD.drawLine(110,290,110,295); myGLCD.setColor(255, 0, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(-20,20,285); myGLCD.printNumI(-10,20,240); myGLCD.printNumI(0,35,195); myGLCD.printNumI(10,25,150); myGLCD.printNumI(20,25,105); myGLCD.printNumI(30,25,60); myGLCD.printNumI(40,25,15); myGLCD.setColor(0, 255, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(20,60,285); myGLCD.printNumI(30,60,240); myGLCD.printNumI(40,60,195); myGLCD.printNumI(50,60,150); myGLCD.printNumI(60,60,105); myGLCD.printNumI(70,60,60); myGLCD.printNumI(80,60,15); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(955,440,285); myGLCD.printNumI(960,440,240); myGLCD.printNumI(965,440,195); myGLCD.printNumI(970,440,150); myGLCD.printNumI(975,440,105); myGLCD.printNumI(980,440,60); myGLCD.printNumI(985,440,15); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(0,428,300); myGLCD.printNumI(-4,385,300); myGLCD.printNumI(-8,345,300); myGLCD.printNumI(-12,300,300); myGLCD.printNumI(-16,260,300); myGLCD.printNumI(-20,220,300); myGLCD.printNumI(-24,180,300); myGLCD.printNumI(-28,140,300); myGLCD.printNumI(-32,100,300); /* for (i = 0; i <= 349; i++) { myGLCD.setColor(255,0,0); myGLCD.drawPixel(81 + i, 300 - humidity[i]); } */ j = 0; } // ==================================== // === === // === HAUPTSCHLEIFE === // === === // ==================================== void loop() { time_neu = millis(); if(time_neu < time_alt) // millis-Überlauf { //time_alt = 0; time_next = 0 + 360000; } if(time_neu > time_next && time_next >= 360000) // neue Messung nach 6 Minuten { myGLCD.clrScr(); myGLCD.setColor(255, 255, 255); myGLCD.print("Wetterstation - stoppi", 150, 1); myGLCD.setColor(255, 255, 255); myGLCD.drawLine(50,290,430,290); myGLCD.drawLine(50,20,50,290); myGLCD.drawLine(430,20,430,290); myGLCD.setColor(255, 0, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.drawCircle(20,2,2); myGLCD.print("C", 26, 1); myGLCD.setColor(0, 255, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.print("%rh", 65, 1); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.print("mbar", 430, 1); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.print("h", 440, 300); myGLCD.setColor(255, 255, 255); myGLCD.drawLine(45,290,55,290); myGLCD.drawLine(45,245,55,245); myGLCD.drawLine(45,200,55,200); myGLCD.drawLine(45,155,55,155); myGLCD.drawLine(45,110,55,110); myGLCD.drawLine(45,65,55,65); myGLCD.drawLine(45,20,55,20); myGLCD.drawLine(430,290,435,290); myGLCD.drawLine(430,245,435,245); myGLCD.drawLine(430,200,435,200); myGLCD.drawLine(430,155,435,155); myGLCD.drawLine(430,110,435,110); myGLCD.drawLine(430,65,435,65); myGLCD.drawLine(430,20,435,20); myGLCD.drawLine(430,290,430,295); myGLCD.drawLine(390,290,390,295); myGLCD.drawLine(350,290,350,295); myGLCD.drawLine(310,290,310,295); myGLCD.drawLine(270,290,270,295); myGLCD.drawLine(230,290,230,295); myGLCD.drawLine(190,290,190,295); myGLCD.drawLine(150,290,150,295); myGLCD.drawLine(110,290,110,295); myGLCD.setColor(255, 0, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(-20,20,285); myGLCD.printNumI(-10,20,240); myGLCD.printNumI(0,35,195); myGLCD.printNumI(10,25,150); myGLCD.printNumI(20,25,105); myGLCD.printNumI(30,25,60); myGLCD.printNumI(40,25,15); myGLCD.setColor(0, 255, 0); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(20,60,285); myGLCD.printNumI(30,60,240); myGLCD.printNumI(40,60,195); myGLCD.printNumI(50,60,150); myGLCD.printNumI(60,60,105); myGLCD.printNumI(70,60,60); myGLCD.printNumI(80,60,15); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(955,440,285); myGLCD.printNumI(960,440,240); myGLCD.printNumI(965,440,195); myGLCD.printNumI(970,440,150); myGLCD.printNumI(975,440,105); myGLCD.printNumI(980,440,60); myGLCD.printNumI(985,440,15); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.printNumI(0,428,300); myGLCD.printNumI(-4,385,300); myGLCD.printNumI(-8,345,300); myGLCD.printNumI(-12,300,300); myGLCD.printNumI(-16,260,300); myGLCD.printNumI(-20,220,300); myGLCD.printNumI(-24,180,300); myGLCD.printNumI(-28,140,300); myGLCD.printNumI(-32,100,300); for (i = 0; i <= 348; i++) { humidity[i] = humidity[i+1]; pressure[i] = pressure[i+1]; temperature[i] = temperature[i+1]; } humidity[349] = bme.readHumidity(); Serial.print("Humidity: "); Serial.print(humidity[349], 0); pressure[349] = bme.readPressure() / 100.0; Serial.print(" Pressure: "); Serial.print(pressure[349], 0); Serial.print(" Alt: "); Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA), 1); temperature[349] = bme.readTemperature(); Serial.print(" Temp: "); Serial.print(temperature[349], 1); Serial.println(); //humidity[349] = random(100); /* temperature[349] = -5 + 10 * sin(2 * 3.1415926535 * j / 40); humidity[349] = 70 + 10 * sin(2 * 3.1415926535 * j / 60); pressure[349] = 950 + 10 * sin(2 * 3.1415926535 * j / 80); j = j + 1; */ for (i = 0; i <= 348; i++) { if (humidity[i] != -66) { myGLCD.setColor(255,0,0); //myGLCD.drawPixel(81 + i, -4.5 * temperature[i] + 200); myGLCD.drawLine(81+i,-4.5 * temperature[i] + 200,81+i+1,-4.5 * temperature[i+1] + 200); myGLCD.setColor(0,255,0); //myGLCD.drawPixel(81 + i, -4.5 * humidity[i] + 380); myGLCD.drawLine(81+i,-4.5 * humidity[i] + 380,81+i+1,-4.5 * humidity[i+1] + 380); myGLCD.setColor(0,0,255); //myGLCD.drawPixel(81 + i, -4.5 * pressure[i] + 4430); myGLCD.drawLine(81+i,-9.0 * pressure[i] + 8885,81+i+1,-9.0 * pressure[i+1] + 8885); } } Serial.print("6 Minuten abgelaufen "); Serial.println(time_next); time_next = time_next + 360000; } time_alt = time_neu; delay(10); } |