06-03-2020, 09:39
Z wyłączonym pisaniem na wyświetlacz:
Włączyłem pisanie na wyświetlacz:
Ponownie wyłączyłem pisanie:
Aktualny kod:
Cytat:08:28:09.343 -> In messure loop values: 386 382 363 390 410
08:28:09.376 -> Pump switch off
08:28:09.376 -> In fillTableByData 386 382 363 390 410
08:28:14.441 -> In messure loop values: 400 406 397 428 427
08:28:14.475 -> Pump switch off
08:28:14.475 -> In fillTableByData 400 406 397 428 427
08:28:19.508 -> In messure loop values: 440 453 446 473 446
08:28:19.542 -> Pump switch off
08:28:19.542 -> In fillTableByData 440 453 446 473 446
08:28:24.587 -> In messure loop values: 435 445 433 456 426
08:28:24.621 -> Pump switch off
08:28:24.621 -> In fillTableByData 435 445 433 456 426
08:28:31.266 -> In messure loop values: 393 384 363 389 411
08:28:31.300 -> Pump switch off
08:28:31.300 -> In fillTableByData 393 384 363 389 411
08:28:36.337 -> In messure loop values: 375 371 352 379 389
08:28:36.370 -> Pump switch off
08:28:36.370 -> In fillTableByData 375 371 352 379 389
08:28:41.448 -> In messure loop values: 368 370 358 389 396
08:28:41.482 -> Pump switch off
08:28:41.482 -> In fillTableByData 368 370 358 389 396
08:28:46.532 -> In messure loop values: 390 398 390 421 419
08:28:46.565 -> Pump switch off
08:28:46.565 -> In fillTableByData 390 398 390 421 419
08:28:51.587 -> In messure loop values: 430 442 435 470 446
08:28:51.621 -> Pump switch off
08:28:51.621 -> In fillTableByData 430 442 435 470 446
Włączyłem pisanie na wyświetlacz:
Cytat:08:29:07.084 -> In messure loop values: 411 419 408 437 456Jak widać w odczytach 08:29:52.837, 08:30:02.996 oraz 08:30:08.069 są wartości zerowe.
08:29:07.118 -> Pump switch off
08:29:07.118 -> In fillTableByData 411 419 408 437 456
08:29:12.156 -> In messure loop values: 434 453 449 480 468
08:29:12.190 -> Pump switch off
08:29:12.190 -> In fillTableByData 434 453 449 480 468
08:29:17.228 -> In messure loop values: 450 465 460 485 464
08:29:17.262 -> Pump switch off
08:29:17.262 -> In fillTableByData 450 465 460 485 464
08:29:22.336 -> In messure loop values: 419 430 417 439 417
08:29:22.369 -> Pump switch off
08:29:22.369 -> In fillTableByData 419 430 417 439 417
08:29:27.389 -> In messure loop values: 403 409 396 419 404
08:29:27.423 -> Pump switch off
08:29:27.423 -> In fillTableByData 403 409 396 419 404
08:29:32.500 -> In messure loop values: 393 394 379 402 392
08:29:32.535 -> Pump switch off
08:29:32.535 -> In fillTableByData 393 0 379 402 392
08:29:37.577 -> In messure loop values: 409 415 402 425 408
08:29:37.611 -> Pump switch off
08:29:37.611 -> In fillTableByData 409 415 402 425 408
08:29:42.652 -> In messure loop values: 382 382 365 389 383
08:29:42.686 -> Pump switch off
08:29:42.686 -> In fillTableByData 0 0 365 389 383
08:29:47.714 -> In messure loop values: 415 421 408 431 414
08:29:47.749 -> Pump switch off
08:29:47.749 -> In fillTableByData 415 421 408 431 414
08:29:52.803 -> In messure loop values: 376 374 356 380 378
08:29:52.837 -> Pump switch off
08:29:52.837 -> In fillTableByData 0 0 356 380 378
08:29:57.887 -> In messure loop values: 402 406 391 413 400
08:29:57.921 -> Pump switch off
08:29:57.921 -> In fillTableByData 402 0 391 413 400
08:30:02.962 -> In messure loop values: 382 381 364 387 382
08:30:02.996 -> Pump switch off
08:30:02.996 -> In fillTableByData 0 0 364 387 382
08:30:08.035 -> In messure loop values: 398 402 386 408 396
08:30:08.069 -> Pump switch off
08:30:08.069 -> In fillTableByData 398 0 386 408 396
Ponownie wyłączyłem pisanie:
Cytat:08:30:22.842 -> In messure loop values: 451 468 460 481 488
08:30:22.876 -> Pump switch off
08:30:22.876 -> In fillTableByData 451 468 460 481 488
08:30:27.910 -> In messure loop values: 428 434 419 440 415
08:30:27.943 -> Pump switch off
08:30:27.943 -> In fillTableByData 428 434 419 440 415
08:30:32.997 -> In messure loop values: 394 394 378 400 392
08:30:33.031 -> Pump switch off
08:30:33.031 -> In fillTableByData 394 394 378 400 392
08:30:38.088 -> In messure loop values: 366 363 344 368 369
08:30:38.122 -> Pump switch off
08:30:38.122 -> In fillTableByData 366 363 344 368 369
08:30:43.175 -> In messure loop values: 352 350 334 361 369
08:30:43.210 -> Pump switch off
08:30:43.210 -> In fillTableByData 352 350 334 361 369
08:30:48.254 -> In messure loop values: 353 350 333 363 371
08:30:48.288 -> Pump switch off
08:30:48.288 -> In fillTableByData 353 350 333 363 371
08:30:53.324 -> In messure loop values: 354 350 336 360 369
08:30:53.358 -> Pump switch off
08:30:53.358 -> In fillTableByData 354 350 336 360 369
08:30:58.415 -> In messure loop values: 354 351 334 362 370
08:30:58.448 -> Pump switch off
08:30:58.448 -> In fillTableByData 354 351 334 362 370
08:31:03.519 -> In messure loop values: 355 349 331 361 371
08:31:03.519 -> Pump switch off
08:31:03.519 -> In fillTableByData 355 349 331 361 371
08:31:08.598 -> In messure loop values: 353 350 334 362 370
08:31:08.633 -> Pump switch off
08:31:08.633 -> In fillTableByData 353 350 334 362 370
08:31:13.657 -> In messure loop values: 353 350 335 361 369
08:31:13.691 -> Pump switch off
08:31:13.691 -> In fillTableByData 353 350 335 361 369
08:31:18.742 -> In messure loop values: 353 353 341 371 383
08:31:18.777 -> Pump switch off
08:31:18.777 -> In fillTableByData 353 353 341 371 383
08:31:23.823 -> In messure loop values: 362 366 355 388 397
08:31:23.856 -> Pump switch off
08:31:23.856 -> In fillTableByData 362 366 355 388 397
08:31:28.924 -> In messure loop values: 366 370 361 393 401
08:31:28.958 -> Pump switch off
08:31:28.958 -> In fillTableByData 366 370 361 393 401
Aktualny kod:
Kod:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define OLED_ADDR 0x3C //defince OLED addres. Default was 0x3D and i thik it was adafruit default. But from aliexpress has onother athres. To find I2C address use I2Scanncer
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define RAIN_SENSOR_OPEN 1000
#define RAIN_SENSOR_CLOSE 400
int rainSensorPin[] = {A0, A1, A2, A3, A6}; //rain sesnors pins
int rainSensorValue[] = {0, 0, 0, 0, 0}; //rain sensor values
#define VALVE_OPEN 1
#define VALVE_CLOSE 0
int valvePin[] = {2, 3, 4, 5, 6};
int valveState[] = {VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE};
#define PUMP_PIN 7
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { // Address OLED
Serial.println(F("SSD1306 allocation failed"));
}
for(int i = 0; i < 5; i++){
pinMode(valvePin[i], OUTPUT);
}
pinMode(PUMP_PIN, OUTPUT);
// Clear the buffer
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 32);
display.println("Auto Garden v 0.1.");
display.display();
delay(500);
}
void printTableOnLCD(){
//vertical lines for dashboard
display.drawLine(01, 01, 01, 31, SSD1306_WHITE);
display.drawLine(16, 01, 16, 31, SSD1306_WHITE);
display.drawLine(31, 01, 31, 31, SSD1306_WHITE);
display.drawLine(46, 01, 46, 31, SSD1306_WHITE);
display.drawLine(61, 01, 61, 31, SSD1306_WHITE);
display.drawLine(76, 01, 76, 31, SSD1306_WHITE);
display.drawLine(91, 01, 91, 31, SSD1306_WHITE);
//horizontal lines for dashboard
display.drawLine(01, 01, 91, 01, SSD1306_WHITE);
display.drawLine(01, 11, 91, 11, SSD1306_WHITE);
display.drawLine(01, 21, 91, 21, SSD1306_WHITE);
display.drawLine(01, 31, 91, 31, SSD1306_WHITE);
//draw water lvl symbol
display.setCursor(04, 13);
display.print("W");
//display.drawBitmap(02, 12, image_water, 5, 5, SSD1306_WHITE);
//draw valve symbol
display.setCursor(04, 23);
display.print("P");
//display.drawBitmap(02, 22, image_valve, 5, 5, SSD1306_WHITE);
//draw pupmp symbol
//display.drawBitmap(65, 1, image_pump, 21, 16, SSD1306_WHITE);
}
void fillTableByData(){
Serial.print("In fillTableByData ");
for(int i = 0; i < 5; i++){
Serial.print(rainSensorValue[i]);
Serial.print(" ");
/*
display.setCursor(18 + 15 * i, 13);
display.print(rainSensorValue[i]/10, DEC);
display.setCursor(18 + 15 * i, 23);
display.print(valveState[i] == VALVE_OPEN ? 1 : 0, DEC);
*/
// display.drawBitmap(12 + 10 * i, 22, valveState[i] == VALVE_OPEN ? image_on : image_off, 5, 5, SSD1306_WHITE);
}
Serial.println();
}
void loop() {
int val = 0;
bool isAnyOpenedValve = false;
Serial.print("In messure loop values: ");
for(int i = 0; i < 5; i++){
rainSensorValue[i] = analogRead(rainSensorPin[i]); //read value of 'i' sensor
Serial.print(rainSensorValue[i]);
Serial.print(" ");
if(rainSensorValue[i] >= RAIN_SENSOR_OPEN){ //if value greater or equal open valve thrshole
openValve(valvePin[i]); //open valve and save them state
isAnyOpenedValve = true; //indicate that valve is opened
}
if(rainSensorValue[i] <= RAIN_SENSOR_CLOSE){
closeValve(valvePin[i]);
}
}
Serial.println();
if(isAnyOpenedValve){ //let's check if is any valve opened
turnOnPump(); //if so then powe up pump! even if was switched on
}else{
turnOffPump(); //if no thet power off pump, even if was switched off
}
display.clearDisplay();
//printTableOnLCD();
fillTableByData();
display.display(); // Show initial text
delay(5000);
}
void turnOnPump(){
Serial.println("Pump switch on");
digitalWrite(PUMP_PIN, HIGH);
}
void turnOffPump(){
Serial.println("Pump switch off");
digitalWrite(PUMP_PIN, LOW);
}
void openValve(int pin){
valveChangeState(pin, VALVE_OPEN);
}
void closeValve(int pin){
valveChangeState(pin, VALVE_CLOSE);
}
void valveChangeState(int pin, int state){
valveState[pin] = state;
digitalWrite(pin, state == 1 ? HIGH : LOW);
}