Go Down

Topic: error no matching function to call for lcd (Read 173 times) previous topic - next topic

Aug 11, 2017, 05:39 pm Last Edit: Aug 17, 2017, 04:29 pm by Fares1992 Reason: code tag
this is the code?
can anyone try to fix the code?!
Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SOL_ADC A0    
#define BAT_ADC A1    
#define CURRENT_ADC A2
#define TEMP_ADC A3  
#define AVG_NUM 10    
#define BAT_MIN 10.5
#define BAT_MAX 15.0
#define BULK_CH_SP 14.4
#define FLOAT_CH_SP 13.6  
#define LVD 11.5        
#define PWM_PIN 3      
#define LOAD_PIN 2      
#define BAT_RED_LED 5
#define BAT_GREEN_LED 6
#define BAT_BLUE_LED 7
#define LOAD_RED_LED 8
#define LOAD_GREEN_LED 9


byte solar[8] = {
0b11111,0b10101,0b11111,0b10101,0b11111,0b10101,0b11111,0b00000
};
byte battery[8] =
{
0b01110,0b11011,0b10001,0b10001,0b10001,0b10001,0b10001,0b11111
};

byte energy[8] =  
{
0b00010,0b00100,0b01000,0b11111,0b00010,0b00100,0b01000,0b00000
};
/*byte alarm[8] =  // icon for alarm
{
0b00000,0b00100,0b01110,0b01110,0b01110,0b11111,0b00000,0b00100
};*/
byte temp[8] =
{
0b00100,0b01010,0b01010,0b01110,0b01110,0b11111,0b11111,0b01110
};

byte charge[8] =
{
0b01010,0b11111,0b10001,0b10001,0b10001,0b01110,0b00100,0b00100,
};
byte not_charge[8]=
{
0b00000,0b10001,0b01010,0b00100,0b01010,0b10001,0b00000,0b00000,
};



float solar_volt=0;
float bat_volt=0;
float load_current=0;
int temperature=0;
int temp_change=0;
float system_volt=0;
float bulk_charge_sp=0;
float float_charge_sp=0;
float charge_status=0;
float load_status=0;
float error=0;
float Ep=0;
int duty =0;
float lvd;
float msec=0;
float last_msec=0;
float elasped_msec=0;
float elasped_time=0;
float ampSecs = 0;
float ampHours=0;
float watts=0;
float wattSecs = 0;
float wattHours=0;


LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3);

void setup()
{

Serial.begin(9600);
pinMode(BAT_RED_LED,OUTPUT);
pinMode(BAT_GREEN_LED,OUTPUT);
pinMode(BAT_BLUE_LED,OUTPUT);
pinMode(LOAD_RED_LED ,OUTPUT);
pinMode(LOAD_GREEN_LED,OUTPUT);
pinMode(PWM_PIN,OUTPUT);
pinMode(LOAD_PIN,OUTPUT);
digitalWrite(PWM_PIN,LOW);
digitalWrite(LOAD_PIN,LOW);  
lcd.begin(20,4);  
lcd.backlight();  
lcd.createChar(1,solar);
lcd.createChar(2, battery);
lcd.createChar(3, energy);
//lcd.createChar(4,alarm);
lcd.createChar(5,temp);
lcd.createChar(6,charge);
lcd.createChar(7,not_charge);
lcd.clear();
}

void loop()
{
read_data();            
system_voltage();        
setpoint();    
charge_cycle();      
power();              
load_control();        
led_indication();      
print_data();          
lcd_display();      
}



int read_adc(int adc_parameter)
{

int sum = 0;
int sample ;
for (int i=0; i<AVG_NUM; i++)
{                                        
  sample = analogRead(adc_parameter);      
  sum += sample;                        
  delayMicroseconds(50);              
}
return(sum / AVG_NUM);              
}

void read_data(void)
{
  //5V = ADC value 1024 => 1 ADC value = (5/1024)Volt= 0.0048828Volt
  // Vout=Vin*R2/(R1+R2) => Vin = Vout*(R1+R2)/R2   R1=100 and R2=20
   solar_volt = read_adc(SOL_ADC)*0.00488*(120/20);
   bat_volt   = read_adc(BAT_ADC)*0.00488*(120/20);      
   load_current = (read_adc(CURRENT_ADC)*.0488 -25);
   temperature = read_adc(TEMP_ADC)*0.00488*100;
   
}

void power(void)

{
msec = millis();
elasped_msec = msec - last_msec;
elasped_time = elasped_msec / 1000.0;
watts = load_current * bat_volt;
ampSecs = (load_current*elasped_time);
wattSecs = ampSecs * bat_volt;
ampHours = ampHours + ampSecs/3600;
wattHours = wattHours + wattSecs/3600;
last_msec = msec;
}

void print_data(void)
{
  delay(100);
  Serial.print("Solar Panel Voltage: ");
  Serial.print(solar_volt);
  Serial.println("V");
  Serial.print("Battery Voltage: ");
  Serial.print(bat_volt);
  Serial.println("V");
  Serial.print("Syestem Voltage: ");
  Serial.print(system_volt);
  Serial.println("V");
  Serial.print("Charge Set Point:");
  Serial.println(bulk_charge_sp);
  Serial.print("Temperature:");
  Serial.print(temperature);
  Serial.println("C");
  Serial.print("Load Current: ");
  Serial.print(load_current);
  Serial.println("A");
  Serial.print("Power: ");
  Serial.print(watts);
  Serial.println("W");
  Serial.print("Energy: ");
  Serial.print(wattHours);
  Serial.println("WH");
  Serial.print("Duty Cycle :");
  if (charge_status==1)
  {
  Serial.println("99%");
  Serial.println("BULK CHARGING");
  }
  else if (charge_status==2)
  {
  Serial.print(Ep);
  Serial.println("%");
  Serial.println("FLOAT CHARGING");
  }
  else
  {
  Serial.println("0%");
  Serial.println("NOT CHARGING");
  }
  if(load_status==1)
  {
   Serial.println("LOAD IS CONNECTED");
  }
  else
  {
   Serial.println("LOAD IS DISCONNECTED");  
  }
 
  Serial.println("***************************");
}

void system_voltage(void)
{
if ((bat_volt >BAT_MIN) && (bat_volt < BAT_MAX))
{
   system_volt = 12;
}
/*
else if  ((bat_volt > BAT_MIN*2 ) && (bat_volt < BAT_MAX*2))
{
  system_volt=24;
}*/
else if ((bat_volt > BAT_MIN/2 ) && (bat_volt < BAT_MAX/2))
{
  system_volt=6;
}

}


void setpoint(void)
{
temp_change =temperature-25.0;
if(system_volt ==12)
{
   bulk_charge_sp = BULK_CH_SP-(0.030*temp_change) ;
   float_charge_sp=FLOAT_CH_SP-(0.030*temp_change) ;
   lvd =LVD;
}

else if(system_volt ==6)
{
   bulk_charge_sp = (BULK_CH_SP/2)-(0.015*temp_change) ;
   float_charge_sp= (FLOAT_CH_SP/2)-(0.015*temp_change) ;
   lvd=LVD/2;
}


}

void charge_cycle(void)
{
if (solar_volt > bat_volt && bat_volt <= bulk_charge_sp)
{

 
 if (bat_volt <= float_charge_sp)
{  
   charge_status = 1;
   duty= 252.45;
   analogWrite(PWM_PIN,duty);
   
 
}
else if (bat_volt >float_charge_sp && bat_volt <= bulk_charge_sp)
{  
    charge_status = 2;
    error  = (bulk_charge_sp - bat_volt);  
    Ep= error *100 ;
   
    if(Ep < 0)
     {
      Ep=0;
      }
    else if(Ep>100)
      {
       Ep=100;
      }
    else if(Ep>0 && Ep <=100)
     {
       duty = (Ep*255)/100;
     }
     analogWrite(PWM_PIN,duty);
 }
}
 else
 {
 charge_status=0;
 duty=0;
 analogWrite(PWM_PIN,duty);
 }
}


void load_control()
{
if (solar_volt < 5  )
{
if(bat_volt >lvd)  
{
load_status=1;
digitalWrite(LOAD_PIN, HIGH);
}
else if(bat_volt < lvd)
{
  load_status=0;
 digitalWrite(LOAD_PIN, LOW);
}
}
else
{
 load_status=0;
 digitalWrite(LOAD_PIN, LOW);
}
}


void led_indication(void)
{
battery_led();        
load_led();  
}


void battery_led(void)
{

 if( (bat_volt > system_volt) && ( bat_volt <bulk_charge_sp))
{  
    leds_off_all();
    digitalWrite(BAT_GREEN_LED,LOW);
}
else if(bat_volt >= bulk_charge_sp)
{
    leds_off_all();
    digitalWrite(BAT_BLUE_LED,LOW);
}
 else if(bat_volt < system_volt)
{
    leds_off_all();
    digitalWrite(BAT_RED_LED,LOW);  // battery voltage low
}
}


void load_led()
{
  if(load_status==1)
  {
    digitalWrite(LOAD_GREEN_LED,HIGH);
  }
  else if(load_status==0)
  {
    digitalWrite(LOAD_RED_LED,HIGH);
  }
 }

void leds_off_all(void)
{

digitalWrite(BAT_RED_LED,HIGH);
digitalWrite(BAT_GREEN_LED,HIGH);
digitalWrite(BAT_BLUE_LED,HIGH);
digitalWrite(LOAD_RED_LED, LOW);
digitalWrite(LOAD_GREEN_LED, LOW);
}
void lcd_display()
{
lcd.setCursor(0, 0);
lcd.write(1);
lcd.setCursor(2, 0);
lcd.print(solar_volt);
lcd.print("V");
lcd.setCursor(14, 0);
lcd.write(5);
lcd.setCursor(16, 0);
lcd.print(temperature);
lcd.write(0b11011111);
lcd.print("C");
lcd.setCursor(0,1);
lcd.write(2);
lcd.setCursor(2, 1);
lcd.print(bat_volt);
lcd.print("V");
lcd.setCursor(14, 1);
lcd.write(2);
if((charge_status==1) | (charge_status== 2))
{
lcd.write(6);
}
else
{
lcd.write(7);
}
lcd.setCursor(0,2);
lcd.write(3);
lcd.setCursor(2,2);
lcd.print(load_current);
lcd.print("A");
lcd.setCursor(13,2);
lcd.print(watts);
lcd.print("W");
lcd.setCursor(0,3);
lcd.print("Energy:");
lcd.print(wattHours);
lcd.print("WH");



 

}

jremington

#1
Aug 13, 2017, 12:34 am Last Edit: Aug 13, 2017, 12:36 am by jremington
Please read the "How to use this forum" post and follow the directions.

Edit your post to add code tags.

2trillion

https://forum.arduino.cc/index.php?topic=348108.0


It's your lcd() line.  The above topic should help.

kenwood120s

I think there's more than one library called LiquidCrystal_I2C.h.

The one I use doesn't like your lcd line, nor does it like the begin.

It seems to be a problem that authors have used the same name for different libraries. I do vaguely remember when I installed my library being warned to make sure I had the one that the sketch expected, although that's tricky of they have the same name: I was lucky to end up with the right one.

You could try a line like the below instead of yours, with your address, columns and rows:

Code: [Select]

LiquidCrystal_I2C lcd(0x3F, 16, 2); //address, columns, rows


And lose the line:

Code: [Select]

lcd.begin(20,4);

Thanks everyone for your help
I'll try to do your advises
Thanks again 

Go Up