Invalid Converson from 'int' to 't_backlighPol" [-fpermissive]

Hi guys, my arduino uses an I2C converter on the LCD. I'm following the Tech-Zen tutorial.

http://tech-zen.tv/episodes/shows/make-it-work/episodes/keypad-input-to-an-arduino-episode-11

But as the LCD is backlit it doesn't seem to like this code.

void setup()
{
 lcd.init();                      // initialize the lcd 
 //lcd.init();
 
 // Print a message to the LCD.
 lcd.backlight();
 
 displayCodeEntryScreen();
 
 //setup and turn off both LEDs
 pinMode(redLED, OUTPUT);
 pinMode(greenLED, OUTPUT);
 digitalWrite(redLED, LOW);
 digitalWrite(greenLED, LOW);
 
}

Can anyone help or tell me how to fix??

Windows 7 Professional. IDE 1.6.8.

Error Messages:
C:\Users\q\Documents\Arduino\Keypad_Basic_1\Keypad_Basic_1.ino:10:17: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* ourCode = "1234";

  • ^*
    Keypad_Basic_1:29: error: invalid conversion from 'int' to 't_backlighPol' [-fpermissive]
    LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
  • ^*
    In file included from C:\Users\q\Documents\Arduino\Keypad_Basic_1\Keypad_Basic_1.ino:2:0:
    C:\Users\q\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:53:4: error: initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)' [-fpermissive]
  • LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);*
  • ^*
    C:\Users\q\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h: In function 'void setup()':
    C:\Users\q\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:154:9: error: 'int LiquidCrystal_I2C::init()' is private
  • int init();*
  • ^*
    Keypad_Basic_1:33: error: within this context
  • lcd.init(); // initialize the lcd*
  • ^*
    exit status 1
    invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

Full code here:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//constants for LEDs
int greenLED = 12;
int redLED = 13;

//set our code
char* ourCode = "1234";
int currentPosition = 0;

//define the keypad
const byte rows = 4;
const byte cols = 4;

char keys[rows][cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPins[rows] = {11,10,9,8};
byte colPins[cols] = {7,6,5,4};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init();                      // initialize the lcd 
//lcd.init();

// Print a message to the LCD.
lcd.backlight();

displayCodeEntryScreen();

//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);

}

void loop()
{
int l;

char key = keypad.getKey();

if (int(key) != 0) {
  lcd.setCursor(14,3);
  lcd.print("    ");
  lcd.setCursor(14,3);
  
  for (l=0; l<=currentPosition; ++l)
  {
    lcd.print("*");
  }
  
  if (key == ourCode[currentPosition])
    {
      ++currentPosition;
      if (currentPosition == 4)
      {
        unlockDoor();
        currentPosition = 0;
      }
    } else {
      invalidCode();
      currentPosition = 0;
    }
  
  
}
}

void invalidCode()
{
digitalWrite(redLED, HIGH);
clearScreen();
lcd.setCursor(0,0);
lcd.print("********************");
lcd.setCursor(0,1);
lcd.print("** ACCESS DENIED! **");
lcd.setCursor(0,2);
lcd.print("**  INVALID CODE  **");
lcd.setCursor(0,3);
lcd.print("********************");

delay(5000);
digitalWrite(redLED, LOW);
displayCodeEntryScreen();
}

void unlockDoor()
{
digitalWrite(greenLED, HIGH);
clearScreen();
lcd.setCursor(0,0);
lcd.print("********************");
lcd.setCursor(0,1);
lcd.print("** ACCESS GRANTED **");
lcd.setCursor(0,2);
lcd.print("**   WELCOME!!    **");
lcd.setCursor(0,3);
lcd.print("********************");

//add any code to unlock the door here
delay(5000);
digitalWrite(greenLED, LOW);
displayCodeEntryScreen();
}

void displayCodeEntryScreen()
{
clearScreen();
lcd.setCursor(0,0);
lcd.print("Let's Make It Secret");
lcd.setCursor(0,1);
lcd.print("Code Project...");
lcd.setCursor(0,2);
lcd.print("Enter Secret Code:");
}

void clearScreen()
{
lcd.setCursor(0,0);
lcd.print("                    ");
lcd.setCursor(0,1);
lcd.print("                    ");
lcd.setCursor(0,2);
lcd.print("                    ");
lcd.setCursor(0,3);
lcd.print("                    ");
}

Your code is NOT posted correctly. You have not included the COMPLETE error message(s).

Read the stickies at the top of the forum, and try again.

Thanks for the response, apologies. Is that better?

Go to your installation directory, change to the libraries\LiquidCrystal_I2C directory and examine the corresponding header file you are including. My version of the library does not have a function named backlight().

Mine Seems to, or am I mistaken?

// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - Under creative commons license 3.0:
//        Attribution-ShareAlike CC BY-SA
//
// This software is furnished "as is", without technical support, and with no 
// warranty, express or implied, as to its usefulness for any purpose.
//
// Thread Safe: No
// Extendable: Yes
//
// @file LiquidCrystal_I2C.c
// This file implements a basic liquid crystal library that comes as standard
// in the Arduino SDK but using an I2C IO extension board.
// 
// @brief 
// This is a basic implementation of the LiquidCrystal library of the
// Arduino SDK. The original library has been reworked in such a way that 
// this class implements the all methods to command an LCD based
// on the Hitachi HD44780 and compatible chipsets using I2C extension
// backpacks such as the I2CLCDextraIO with the PCF8574* I2C IO Expander ASIC.
//
// The functionality provided by this class and its base class is identical
// to the original functionality of the Arduino LiquidCrystal library.
//
//
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#if (ARDUINO <  100)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <inttypes.h>
#include "I2CIO.h"
#include "LiquidCrystal_I2C.h"

// CONSTANT  definitions
// ---------------------------------------------------------------------------

// flags for backlight control
/*!
 @defined 
 @abstract   LCD_NOBACKLIGHT
 @discussion NO BACKLIGHT MASK
 */
#define LCD_NOBACKLIGHT 0x00

/*!
 @defined 
 @abstract   LCD_BACKLIGHT
 @discussion BACKLIGHT MASK used when backlight is on
 */
#define LCD_BACKLIGHT   0xFF


// Default library configuration parameters used by class constructor with
// only the I2C address field.
// ---------------------------------------------------------------------------
/*!
 @defined 
 @abstract   Enable bit of the LCD
 @discussion Defines the IO of the expander connected to the LCD Enable
 */
#define EN 6  // Enable bit

/*!
 @defined 
 @abstract   Read/Write bit of the LCD
 @discussion Defines the IO of the expander connected to the LCD Rw pin
 */
#define RW 5  // Read/Write bit

/*!
 @defined 
 @abstract   Register bit of the LCD
 @discussion Defines the IO of the expander connected to the LCD Register select pin
 */
#define RS 4  // Register select bit

/*!
 @defined 
 @abstract   LCD dataline allocation this library only supports 4 bit LCD control
 mode.
 @discussion D4, D5, D6, D7 LCD data lines pin mapping of the extender module
 */
#define D4 0
#define D5 1
#define D6 2
#define D7 3


// CONSTRUCTORS
// ---------------------------------------------------------------------------
LiquidCrystal_I2C::LiquidCrystal_I2C( uint8_t lcd_Addr )
{
   config(lcd_Addr, EN, RW, RS, D4, D5, D6, D7);
}


LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t backlighPin, 
                                     t_backlighPol pol = POSITIVE)
{
   config(lcd_Addr, EN, RW, RS, D4, D5, D6, D7);
   setBacklightPin(backlighPin, pol);
}

LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
                                     uint8_t Rs)
{
   config(lcd_Addr, En, Rw, Rs, D4, D5, D6, D7);
}

LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
                                     uint8_t Rs, uint8_t backlighPin, 
                                     t_backlighPol pol = POSITIVE)
{
   config(lcd_Addr, En, Rw, Rs, D4, D5, D6, D7);
   setBacklightPin(backlighPin, pol);
}

LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
                                     uint8_t Rs, uint8_t d4, uint8_t d5,
                                     uint8_t d6, uint8_t d7 )
{
   config(lcd_Addr, En, Rw, Rs, d4, d5, d6, d7);
}

LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
                                     uint8_t Rs, uint8_t d4, uint8_t d5,
                                     uint8_t d6, uint8_t d7, uint8_t backlighPin, 
                                     t_backlighPol pol = POSITIVE )
{
   config(lcd_Addr, En, Rw, Rs, d4, d5, d6, d7);
   setBacklightPin(backlighPin, pol);
}

// PUBLIC METHODS
// ---------------------------------------------------------------------------

//
// begin
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
{
   
   init();     // Initialise the I2C expander interface
   LCD::begin ( cols, lines, dotsize );   
}


// User commands - users can expand this section
//----------------------------------------------------------------------------
// Turn the (optional) backlight off/on

//
// setBacklightPin
void LiquidCrystal_I2C::setBacklightPin ( uint8_t value, t_backlighPol pol = POSITIVE )
{
   _backlightPinMask = ( 1 << value );
   _polarity = pol;
   setBacklight(BACKLIGHT_OFF);
}

//
// setBacklight
void LiquidCrystal_I2C::setBacklight( uint8_t value ) 
{
   // Check if backlight is available
   // ----------------------------------------------------
   if ( _backlightPinMask != 0x0 )
   {
      // Check for polarity to configure mask accordingly
      // ----------------------------------------------------------
      if  (((_polarity == POSITIVE) && (value > 0)) || 
           ((_polarity == NEGATIVE ) && ( value == 0 )))
      {
         _backlightStsMask = _backlightPinMask & LCD_BACKLIGHT;
      }
      else 
      {
         _backlightStsMask = _backlightPinMask & LCD_NOBACKLIGHT;
      }
      _i2cio.write( _backlightStsMask );
   }
}


// PRIVATE METHODS
// ---------------------------------------------------------------------------

//
// init
int LiquidCrystal_I2C::init()
{
   int status = 0;
   
   // initialize the backpack IO expander
   // and display functions.
   // ------------------------------------------------------------------------
   if ( _i2cio.begin ( _Addr ) == 1 )
   {
      _i2cio.portMode ( OUTPUT );  // Set the entire IO extender to OUTPUT
      _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
      status = 1;
      _i2cio.write(0);  // Set the entire port to LOW
   }
   return ( status );
}

//
// config
void LiquidCrystal_I2C::config (uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs, 
                                uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 )
{
   _Addr = lcd_Addr;
   
   _backlightPinMask = 0;
   _backlightStsMask = LCD_NOBACKLIGHT;
   _polarity = POSITIVE;
   
   _En = ( 1 << En );
   _Rw = ( 1 << Rw );
   _Rs = ( 1 << Rs );
   
   // Initialise pin mapping
   _data_pins[0] = ( 1 << d4 );
   _data_pins[1] = ( 1 << d5 );
   _data_pins[2] = ( 1 << d6 );
   _data_pins[3] = ( 1 << d7 );   
}



// low level data pushing commands
//----------------------------------------------------------------------------

//
// send - write either command or data
void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) 
{
   // No need to use the delay routines since the time taken to write takes
   // longer that what is needed both for toggling and enable pin an to execute
   // the command.
   
   if ( mode == FOUR_BITS )
   {
      write4bits( (value & 0x0F), COMMAND );
   }
   else 
   {
      write4bits( (value >> 4), mode );
      write4bits( (value & 0x0F), mode);
   }
}

//
// write4bits
void LiquidCrystal_I2C::write4bits ( uint8_t value, uint8_t mode ) 
{
   uint8_t pinMapValue = 0;
   
   // Map the value to LCD pin mapping
   // --------------------------------
   for ( uint8_t i = 0; i < 4; i++ )
   {
      if ( ( value & 0x1 ) == 1 )
      {
         pinMapValue |= _data_pins[i];
      }
      value = ( value >> 1 );
   }
   
   // Is it a command or data
   // -----------------------
   if ( mode == DATA )
   {
      mode = _Rs;
   }
   
   pinMapValue |= mode | _backlightStsMask;
   pulseEnable ( pinMapValue );
}

//
// pulseEnable
void LiquidCrystal_I2C::pulseEnable (uint8_t data)
{
   _i2cio.write (data | _En);   // En HIGH
   _i2cio.write (data & ~_En);  // En LOW
}

In the posted code I cannot find that "function named backlight()" neither.

However,t_backlighPolis used a couple of times as the type of an optional parameter.

Your line

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

is rubbish of course. A better one could be selected from
LiquidCrystal_I2C.h (you included the .cpp instead), but there are no candidates, where ...,20,4); makes any sense.

perhaps:

LiquidCrystal_I2C lcd(0x27);

And you're missing an lcd.begin call ( where you might specify cols, lines, and dotsize )

Great thanks! It also doesn't like the line to initialise the lcd. I have changed

lcd.init();

to

lcd.begin();

and I am getting the error message:

C:\Users\q\Documents\Arduino\Keypad_Basic_1\Keypad_Basic_1.ino: In function 'void setup()':
Keypad_Basic_1:33: error: no matching function for call to 'LiquidCrystal_I2C::begin()'

  • lcd.begin(); // initialize the lcd*

^
Any thoughts?

Do this is Solution for your problem..
I did found because I was facing same problem but found this solution...

@michael_x said instead
using of LiquidCrystal_I2C lcd(0x27);
is suggested and then declare rows and column in begin

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27);

void setup() {
lcd.begin(16,2);
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}