Printing using Bonezegei_LCD1602_I2C.h

I am attempting to print to a 1602 LCD screen with a PCF8574 I2C interface using the Bonezegei_LCD1602_I2C.h library. The project is a counter for a tipping bucket rain gauge. My setup works fine - the counter displays in the serial monitor, and the LCD screen works. The problem comes in when trying to display the number of tips (the count). The lcd.print statement works for a literal string (in quotes), but does not work for a string variable. My sketch:


//#include "Arduino.h"
#include <Bonezegei_LCD1602_I2C.h>

const int bucketPin = 2;  // the pin that the tipping bucket is on
int bucketTipsCounter = 0;  // counter for the number of tips
int bucketState = 1;       
int lastBucketState = 0;
float inchesRain;
    
Bonezegei_LCD1602_I2C lcd(0x27);

void setup() {
  lcd.begin();
  lcd.setBacklight(0);
  
  lcd.setPosition(0, 0);      //param1 = X   param2 = Y
  delay(2000);
  //lcd.setPosition(0, 0);
  lcd.print("Display ON");
   
  pinMode(bucketPin, INPUT_PULLUP);
  Serial.begin(9600);
}


void loop() {
  // read the bucket tip input pin:
      bucketState = digitalRead(bucketPin);
      if (bucketState != lastBucketState) {
    // if the state has changed, increment the counter
    if (bucketState == LOW) {
      bucketTipsCounter++;
      String strTips = String(bucketTipsCounter);
      inchesRain = bucketTipsCounter*0.0126;
      Serial.print("tip count ");
      Serial.println(bucketTipsCounter);
      Serial.print("strTips = ");
      Serial.println(strTips);
      Serial.print("inchesRain = ");
      Serial.println(inchesRain);
      //lcd.setPosition(0, 0);
      //lcd.print("tip count ");
      //lcd.print(tips);
      lcd.setPosition(0, 1);
      lcd.print("strTips =");
      lcd.print(strTips);
      
    } 
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastBucketState = bucketState;

}

I get the following error message upon compilation:

Compilation error: no matching function for call to 'Bonezegei_LCD1602_I2C::print(String&)'

I suppose it's something simple, but it has me stumped. There's very little documentation of this library's functions.

This is the only line with print followed by a String address (&). Try changing the line to use println()

That library does not inherit from print, and only defines functions for printing from a char array or a single char.

1 Like

@david_2018 pointed out that that display library doesn't inherit from Print.

Ugh.

Ditch it and use another library that does inherit from Print. The changes to your sketch are trivial. And you'll be able to lcd.print to your heart's content.

#include <LiquidCrystal_I2C.h>

const int bucketPin = 2;  // the pin that the tipping bucket is on
int bucketTipsCounter = 0;  // counter for the number of tips
int bucketState = 1;       
int lastBucketState = 0;
float inchesRain;
    
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.setBacklight(0);
  
  lcd.setCursor(0, 0);      //param1 = X   param2 = Y
  delay(2000);
  //lcd.setCursor(0, 0);
  lcd.print("Display ON");
   
  pinMode(bucketPin, INPUT_PULLUP);
  Serial.begin(9600);
}


void loop() {
  // read the bucket tip input pin:
      bucketState = digitalRead(bucketPin);
      if (bucketState != lastBucketState) {
    // if the state has changed, increment the counter
    if (bucketState == LOW) {
      bucketTipsCounter++;
      String strTips = String(bucketTipsCounter);
      inchesRain = bucketTipsCounter*0.0126;
      Serial.print("tip count ");
      Serial.println(bucketTipsCounter);
      Serial.print("strTips = ");
      Serial.println(strTips);
      Serial.print("inchesRain = ");
      Serial.println(inchesRain);
      //lcd.setCursor(0, 0);
      //lcd.print("tip count ");
      //lcd.print(tips);
      lcd.setCursor(0, 1);
      lcd.print("strTips =");
      lcd.print(strTips);
      
    } 
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastBucketState = bucketState;

}
1 Like

@van_der_decken Ditching the library was excellent advice - thank you! I had struggled with it, thinking there must be a way to print integers and strings. As a newbie, I always assume the problem is with me, not with something an expert wrote. The library you recommended is working fine.

Thanks to all who answered. I appreciate your help.

2 Likes

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