There too many errors in my code i dont know where to start fixing it


#include <SPI.h>
#include <SD.h>
#include <DS3231.h>
#include <DHT.h>
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define BACKLIGHT 3
#define DHT22_PIN 4


unsigned long prevDispCycle = 0;
unsigned long currDispCycle;
const long intDispCycle = 500;
unsigned long prevReadPV = 0;
unsigned long currReadPV;
const long intReadPV = 50;
unsigned long prevDisp = 0;
unsigned long currDisp;
const long intDisp = 250;
unsigned long prevRel = 0;
unsigned long currRel;
const long intRel = 250;
unsigned long prevHold = 0;
unsigned long currHold;
const long intHold = 250;
unsigned long prevDHT = 0;
unsigned long currDHT;
const long intDHT = 2000;
unsigned long prevSave = 0;
unsigned long currSave;
long intSave = 1000;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 1000;


int display = 1;
int btnDisplay = 4;
int btnRelay = 5;
int btnHold = 9;
int relay1 = 7;
int relay2 = 8; 
int relaySelect = 0;
int logInterval = 1;
int pinInterrupt = 2;
int Count = 0;
int samples = 0;
int humidity = 0;

double reading_vol = 0;
double reading_cur = 0;
double initial_vol = 0;
double initial_cur = 0;
double voltage = 0.0;
double current = 0.0;
double power = 0;
double windSpeed = 0;
double temperature = 0;

bool hold = false;
RTC_DS3231 rtc;


LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
dht DHT;

int CS_PIN = 10;

File file;

void setup() {

  Serial.begin(9600);

  rtc.begin();
  lcd.begin (20,4);
  lcd.setBacklightPin (BACKLIGHT, POSITIVE);
  lcd.setBacklight (HIGH);
  pinMode(pinInterrupt, INPUT_PULLUP);
  pinMode (btnDisplay, INPUT_PULLUP);
  pinMode (btnRelay, INPUT_PULLUP);
  pinMode (btnHold, INPUT_PULLUP);
  pinMode (relay1, OUTPUT);
  pinMode (relay2, OUTPUT);
  pinMode (CS_PIN, OUTPUT);
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, HIGH);

  attachInterrupt(digitalPinToInterrupt (pinInterrupt), onChange, FALLING);

  updateDHT();

  displayIntro(); 
  //Introduction.
  delay(10000);
  displayInit();
  //Initializing...

  delay(800);
  // Serial.println("Sd start");
  // SD.begin(CS_PIN);
  if (!SD.begin()) {
  
    Serial.println("initialization failed!");

  }

  file = SD.open("PVlogs.txt", FILE_WRITE);
  
  if (file) {

    Serial.println("Device Started..."); 
    //Every start ng Device
    file.println("Device Started...");
  }

  file.close();
  // Serial.println("Sd end");
}
  void onChange (){
    if (digitalRead(pinInterrupt) == LOW) 
    
    Count++;
  }

  void dataLog(){
      
  //saving at SD Card

    currSave = millis();

    if (currSave - prevSave >= intSave) {
      prevSave = currSave;
   Serial.println("SAVE!");
    file = SD.open("PVlogs.txt", FILE_WRITE);
    if (file) {
      Serial.println("Writing");
      file.print("|");
      file.print(rtc.getDateStr());
      file.print("|");
      file.print(rtc.getTimeStr());
      file.print("|");
      file.print(windSpeed);
      file.print("|");
      file.print(temperature);
      file.print("|");
      file.print(humidity);
      file.print("|");
      if (relaySelect == 0){

        file.print("PV Open CKT");

      }

      if (relaySelect == 1){

        file.print("PV Short CKT");
      }

      if (relaySelect == 2){
        
        file.print("15 Ohm Load");

      }
      
      file.print("|");
      file.print(voltage);
      file.print("|");
      file.print(current);
      file.print("|");
      file.print(power);
      file.println("|");
      file.close();
      // Serial.println("Writing Done!");
    }
    }
  }

  void updateDHT () {
      //DHT22 Humidity &Temp Sensor. 
      currDHT = millis();

      if (currDHT - prevDHT >= intDHT){
        prevDHT = currDHT;
        DHT.read22(DHT22_PIN);
        temperature = DHT.temperature;
        humidity = DHT.humidity;
        Serial.println(temperature);
        Serial.println(humidity);
      }
  }
  void readAnemometer(){
         //Wind Speed
        if ((millis() - lastDebounceTime) > debounceDelay){
        
          lastDebounceTime = millis();
          windSpeed = (Count * 8.75)/100;
        
        // Serial.println(windSpeed);
          Count = 0;
        }
  }

  void readPV() {

        currReadPV= millis();

        if (currReadPV - prevReadPV = intReadPV) {

          prevReadPV = currReadPV;

          reading_vol = ((analogRead(A0)/1023.0)*23.92);
          // Voltage Reading. 1023 arduino max 12 102423-321.52 rom calibration with tester.

          int adc = analogRead(A1):

          float volt = (adc * 5.0)/1023.0; 
          //adc 5/1023

          reading_cur = (volt-2.5)/0.66; 
          //from anemometer spreadsheet

          initial_vol += reading_vol; 
          initial_cur += reading_cur;
          samples++;

          if (samples >-20) {

             voltage = (initial_vol/20);
             //20 samples/20 = Average Voltage & Current

            if ((initial_cur/20) < 0) {
              
              current = 0;

            }
            if ((initial_cur/20) >= 0){
              
              current = (initial_cur/20);

            }
            power = voltage * current;
            samples = 0;
            initial_vol = 0;
            initial_cur = 0;
          }
        }
  }

  void relayControl() { 
        //3Relay switches

            if (relaySelect == 0) {
              digitalWrite(relay1, LOW); //off
              digitalWrite(relay2, HIGH); //off
            }

            if (relaySelect == 1){
              digitalWrite(relay1, HIGH); //on
              digitalWrite(relay2 , HIGH); //off
            }
            if (relaySelect == 2){
              digitalWrite(relay1, LOW); //off
              digitalWrite(relay2, LOW); //on
            }
  }
    
  void btnDisp() {

          currDisp = millis();

            if (digitalRead(btnDisplay) == LOW) {

              if (currDisp - prevDisp >= intDisp) {
                prevDisp = currDisp;
                display++;
              if (display > 2){
                display = 1;
              }
              }
            }
  }

  void btnRel() {
          currRel = millis();
            if (digitalRead(btnRelay) == LOW) {
            if (currRel - prevRel >= intRel) {
              prevRel = currRel;
              if (display == 1){
                relaySelect;
                 if (relaySelect > 2){
                   relaySelect = 0;
                 }
              }
              
              if (display == 2) {

               if (logInterval <= 995) logInterval = logInterval - 5;
               if (logInterval == 999) logInterval = logInterval - 4;
               if (logInterval <= 0) {
                  logInterval = 1;
               }
                  intSave = logInterval * 1000;
              }
            }
            }
  }
  void btnHld() {
          currHold = millis();
            if (digitalRead(btnHold) == LOW) {
              if (currHold - prevHold >= intHold) { 
                prevHold = currHold;
                if (display == 1) {
                  hold =! hold;
                }
                if (display == 2){
                  if (logInterval >= 5) logInterval = logInterval + 5;
                  if (logInterval == 1) logInterval = loginterval + 4;
                  if (logInterval > 999) {
                  logInterval = 999;
                  }             
                  intSave = logInterval * 1000;
                }
              }
            }
  }
  void displayIntro () {
    //Intro Display
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("PV DATA LOGGER");
    lcd.setCursor(9,1);
    lcd.print("by");
    lcd.setCursor(0,2);
    lcd.print("JA BLANCAFLOR, RJ CUNANAN "):
    lcd.setCursor (5,3);
    lcd.print("J MALAYANG JR.");
  }

  void displayInit(){
    lcd.clear();
    lcd.setCursor(2, 2);
    lcd.print("Initializing");
    delay (800);
    lcd.setCursor(2,2);
    lcd.print("Initializing.");
    delay (800);
    lcd.setCursor(2,2);
    lcd.print("Initializing..");
    delay (800);
    lcd.setCursor(2,2);
    lcd.print("Initializing...");
    delay (800);
    lcd.clear();
    lcd.setCursor(4,2);
    lcd.print("LINK START!!");
    delay (2000);
  }

  void displayCycle() {
  //DISPLAYS; POSITIONING SA SCREEN
          currDispCycle = millis();
            if (currDispCycle - prevDispCycle >= intDispCycle) {
              prevDispCycle = currDispCycle;
              if (display == 1) {
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.print(rtc.getTimeStr());
                lcd.setCursor(11,0);
                lcd.print (windSpeed);
                lcd.setCursor(16,0);
                lcd.print("m/s");
                lcd.setCursor(0,1);
                lcd.print("RELAY:");
                if (relaySelect == 0) {
                  lcd.setCursor(6,1);
                  lcd.print("PV Open CKT");
                }
                if (relaySelect == 1){
                  lcd.setCursor(6,1);
                  lcd.print("PV Short CKT");
                }
                if (relaySelect == 2) {
                  lcd.setCursor(6,1);
                  lcd.print("15 Ohm Load");
                }
                lcd.setCursor(0,2);
                lcd.print(temperature);
                lcd.setCursor(5,2);
                lcd.print("C");
                lcd.setCursor(7,2);
                lcd.print(humidity);
                lcd.setCursor(10,2);
                lcd.print("%");
                lcd.setCursor(12,2);
                lcd.print("P:");
                lcd.setCursor (14,2);
                lcd.print (power);
                lcd.setCursor(19,2);
                lcd.print("W");
                lcd.setCursor(0,3);
                lcd.print("VOLT:");
                lcd.setCursor (5,3);
                lcd.print (voltage);
                lcd.setCursor (11,3);
                lcd.print("AMP:");
                lcd.setCursor(15,3);
                lcd.print(current);
              }
                if (display == 2) {
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.print("DATE: ");
                lcd.setCursor(6,0);
                lcd.print(rtc.getDateStr());
                lcd.setCursor (1,2);
                lcd.print("DATA LOG INTERVAL");
                lcd.setCursor(4,3);
                lcd.print(logInterval);
                lcd.setCursor(7,3);
                lcd.print("second(s)");
                }
            }
  }

  void loop() {
              if (!hold) {
                readPV();
                readAnemometer();
                updateDHT();
              }
                dataLog();
                displayCycle();
                relayControl();
                btnDisp();
                btnRel();
                btnHld();
  }


            In file included from C:\Users\user\Documents\THESIS\THESIS.ino:6:0:
c:\Users\user\Documents\Arduino\libraries\RTClib\src/RTClib.h:143:7: error: redefinition of 'class DateTime'
 class DateTime {
       ^~~~~~~~
In file included from C:\Users\user\Documents\THESIS\THESIS.ino:3:0:
c:\Users\user\Documents\Arduino\libraries\DS3231/DS3231.h:33:7: note: previous definition of 'class DateTime'
 class DateTime {
       ^~~~~~~~
C:\Users\user\Documents\THESIS\THESIS.ino:70:87: error: no matching function for call to 'LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)'
 LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
                                                                                       ^
In file included from C:\Users\user\Documents\THESIS\THESIS.ino:7:0:
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:57:3: note: candidate: LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, uint8_t)
   LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
   ^~~~~~~~~~~~~~~~~
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:57:3: note:   candidate expects 3 arguments, 8 provided
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(const LiquidCrystal_I2C&)
 class LiquidCrystal_I2C : public Print {
       ^~~~~~~~~~~~~~~~~
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note:   candidate expects 1 argument, 8 provided
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(LiquidCrystal_I2C&&)
c:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note:   candidate expects 1 argument, 8 provided
C:\Users\user\Documents\THESIS\THESIS.ino:71:1: error: 'dht' does not name a type
 dht DHT;
 ^~~
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void setup()':
C:\Users\user\Documents\THESIS\THESIS.ino:83:7: error: 'class LiquidCrystal_I2C' has no member named 'setBacklightPin'; did you mean 'setBacklight'?
   lcd.setBacklightPin (BACKLIGHT, POSITIVE);
       ^~~~~~~~~~~~~~~
       setBacklight
C:\Users\user\Documents\THESIS\THESIS.ino:83:35: error: 'POSITIVE' was not declared in this scope
   lcd.setBacklightPin (BACKLIGHT, POSITIVE);
                                   ^~~~~~~~
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void dataLog()':
C:\Users\user\Documents\THESIS\THESIS.ino:145:22: error: 'class RTC_DS3231' has no member named 'getDateStr'
       file.print(rtc.getDateStr());
                      ^~~~~~~~~~
C:\Users\user\Documents\THESIS\THESIS.ino:147:22: error: 'class RTC_DS3231' has no member named 'getTimeStr'; did you mean 'getTemperature'?
       file.print(rtc.getTimeStr());
                      ^~~~~~~~~~
                      getTemperature
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void updateDHT()':
C:\Users\user\Documents\THESIS\THESIS.ino:191:12: error: expected unqualified-id before '.' token
         DHT.read22(DHT22_PIN);
            ^
C:\Users\user\Documents\THESIS\THESIS.ino:192:26: error: expected primary-expression before '.' token
         temperature = DHT.temperature;
                          ^
C:\Users\user\Documents\THESIS\THESIS.ino:193:23: error: expected primary-expression before '.' token
         humidity = DHT.humidity;
                       ^
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void readPV()':
C:\Users\user\Documents\THESIS\THESIS.ino:213:39: error: lvalue required as left operand of assignment
         if (currReadPV - prevReadPV = intReadPV) {
                                       ^~~~~~~~~
C:\Users\user\Documents\THESIS\THESIS.ino:220:35: error: expected ',' or ';' before ':' token
           int adc = analogRead(A1):
                                   ^
C:\Users\user\Documents\THESIS\THESIS.ino:225:26: error: 'volt' was not declared in this scope
           reading_cur = (volt-2.5)/0.66;
                          ^~~~
C:\Users\user\Documents\THESIS\THESIS.ino:225:26: note: suggested alternative: 'hold'
           reading_cur = (volt-2.5)/0.66;
                          ^~~~
                          hold
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void btnHld()':
C:\Users\user\Documents\THESIS\THESIS.ino:323:55: error: 'loginterval' was not declared in this scope
                   if (logInterval == 1) logInterval = loginterval + 4;
                                                       ^~~~~~~~~~~
C:\Users\user\Documents\THESIS\THESIS.ino:323:55: note: suggested alternative: 'logInterval'
                   if (logInterval == 1) logInterval = loginterval + 4;
                                                       ^~~~~~~~~~~
                                                       logInterval
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void displayIntro()':
C:\Users\user\Documents\THESIS\THESIS.ino:340:44: error: expected ';' before ':' token
     lcd.print("JA BLANCAFLOR, RJ CUNANAN "):
                                            ^
C:\Users\user\Documents\THESIS\THESIS.ino: In function 'void displayCycle()':
C:\Users\user\Documents\THESIS\THESIS.ino:373:31: error: 'class RTC_DS3231' has no member named 'getTimeStr'; did you mean 'getTemperature'?
                 lcd.print(rtc.getTimeStr());
                               ^~~~~~~~~~
                               getTemperature
C:\Users\user\Documents\THESIS\THESIS.ino:420:31: error: 'class RTC_DS3231' has no member named 'getDateStr'
                 lcd.print(rtc.getDateStr());
                               ^~~~~~~~~~
Multiple libraries were found for "Wire.h"
  Used: C:\Users\user\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire
  Not used: C:\Users\user\Documents\Arduino\libraries\Wire-master
Multiple libraries were found for "LiquidCrystal_I2C.h"
  Used: C:\Users\user\Documents\Arduino\libraries\LiquidCrystal_I2C-1.1.2
  Not used: C:\Users\user\Documents\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master
exit status 1

Compilation error: no matching function for call to 'LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)'

Start by removing either the include of DS3231 or the include of RTClib. Next look at the examples that came with the library that you have included to work around new errors that may occur.

Look at the examples that come with the LiquidCrystal_I2C library that you use. You're passing 8 arguments but the constructor in the library only expects 3 arguments; this is a clear indication that you're using the wrong library for the code or the wrong code for the library.

Again, look at the examples that come with the DHT library that you use.

= for assignment, == for compare.

Statements and with a semicolon.

That's it for now; there might be more. You should never have gotten that many errors if you would have created your sketch in steps. E.g. get experience with the LiquidCrystal_I2C library that you use and understand it; same for thre other libraries. Next start combining.

So I seriously suggest that you start with that step-by-step approach.

2 Likes

Did chatGPT generate this code?

It seems you have I2C library for your LCD mixed up with a call to a constructor for a parallel controlled LCD (that uses many more pins).

1 Like

When will this be false?
Do you mean >= ?

1 Like

@build_1971, I'm reasonably sure that there is one LiquidCrystal_I2C library that uses the constructor implied in the code.

that ones a typo

okayy will do thanks for the help

Often errors further down in the code are a consequence of initial errors so you can take an iterative approach when you have lots of error , you deal with the first one and then compile again and deal again with the first one etc…

But here it seems your mistake is more than syntax and grammar. It seems you’ve thrown all the codes you found on the internet together and hoped it would work… well hope is usually not a winning strategy in anything…

Spend some time with the basics of programming, then you can build on solid knowledge.

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.