Liquidcristal

I have an issue when I’m trying to hook an LCD display to my Arduino Uno Wifi Rev2. The LCD was shipped with the MKR IoT bundle, so I assume it’s Arduino compatible.

It’s my first attempt to connect this type of display, and I thought I’d start off with a sample code I found online and looks like this:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lastUpdate = 0;
int currentIndex = 0;
char* lyrics[] = {
  "Drink all the...",
  "     BOOZE!     ",
  "Hack all the... ",
  "    THINGS!     "
};

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  int time = millis();

  if ((time  - lastUpdate) >= 800)
  {
    lcd.setCursor(0, 0);

    if (currentIndex == 0 || currentIndex == 2)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(lyrics[currentIndex]);
    }
    else
    {
      lcd.setCursor(0, 1);
      lcd.print(lyrics[currentIndex]);
    }

    if (currentIndex == 3)
    {
      currentIndex = 0;
    }
    else
    {
      currentIndex += 1;
    }

    lastUpdate = time;
  }
}

When compiling the sketch I get following errors:

Arduino: 1.8.11 (Windows 10), Board: “Arduino Uno WiFi Rev2, ATMEGA328”

C:\Users\x\OneDrive - Mynubo\Arduino\sketch_jun23b\sketch_jun23b.ino:12:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

};

^

C:\Users\x\OneDrive - Mynubo\Arduino\sketch_jun23b\sketch_jun23b.ino:12:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

C:\Users\x\OneDrive - Mynubo\Arduino\sketch_jun23b\sketch_jun23b.ino:12:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

C:\Users\x\OneDrive - Mynubo\Arduino\sketch_jun23b\sketch_jun23b.ino:12:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:45:36: error: expected class-name before ‘{’ token

class LiquidCrystal : public Print {

^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:86:9: error: ‘Print’ has not been declared

using Print::write;

^~~~~

exit status 1
Error compiling for board Arduino Uno WiFi Rev2.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Any idea on how to solve this?

In the end I just want to use the LCD to show the value of a counter which keeps track of the number of times something passes a sensor. That code is working well so I just need the screen to work so I can complete the project.

Thanks!

try change

char* lyrics[] = {

to

char lyrics[][16] = {

Your sketch, as presented, compiles without error for me with "Arduino Uno WiFi" selected as the board type in the IDE.

At least part of the problem (if not all of it) seems to be with the included library file...
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h

Have you modified that somehow?
Do we have the same board type selected? I do not see any reference to "Arduino Uno WiFi Rev2" in my IDE.

pcbbc:
Your sketch, as presented, compiles without error for me with “Arduino Uno WiFi” selected as the board type in the IDE.

At least part of the problem (if not all of it) seems to be with the included library file…
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h

Have you modified that somehow?
Do we have the same board type selected? I do not see any reference to “Arduino Uno WiFi Rev2” in my IDE.

I have not modified the LiquidCrystal.h file & have no problem selecting the Wifi Rev2 board and uploading other sketches to it, so I don’t believe that’s an issue.

There are several different libraries named LiquidCrystal. Which one are you using?

Before you go to the trouble of modifying a file maybe try the HD44780 library for LCDs. The library is available through the library manager. Use the hd44780_pinIO class.

groundFungus:
There are several different libraries named LiquidCrystal. Which one are you using?

Before you go to the trouble of modifying a file maybe try the HD44780 library for LCDs. The library is available through the library manager. Use the hd44780_pinIO class.

Ok, I managed to upload the sketch to the arduino this time with the HD44780 library. Now the screen is showing only black boxes. I tried a different demo sketch and also switched from the UNO Wifi Rev2 to an MKR1000 board but always with the same result. This internet is telling me to look for wiring issues but I can’t find any.

Everyone will tell you it's impossible to diagnose wiring issues by looking at a rats-nest of wires in a photo. Sorry.
But you have two boards and all kinds of unnecessary components there.
If something isn't working, start with the bare minimum of components necessary to test the non-functional component - For me that would be the LCD and ONE Arduino.
The UNO WiFi doesn't seem to have a ground connection to the breadboard?

Also, there seems to be no ground connection to the Arduino here:

pcbbc:
Do we have the same board type selected? I do not see any reference to "Arduino Uno WiFi Rev2" in my IDE.

You will not see the UNO WiFi Rev 2 board unless you have the Arduino megaavr boards loaded in the board manager. That board is based on the atmega4809 instead of an atmega328, despite having UNO in the name.

The error with Print is caused by a bug in version 1.8.6 of the megaavr boards package.

Have you tried adjusting the contrast on the display? I'm not near a computer where I can look up the proper wiring.

I cleared up the mess :slight_smile:

The diagram I replicated can be found here: https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

Adjusting the contrast does only dims the black squares unfortunately.

What Arduino board is that?

Please post the code that you tried.

groundFungus:
What Arduino board is that?

Please post the code that you tried.

It’s the MKR1000, but the result is identical with the Uno Wifi Rev 2.

The code is:

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
#if defined (ARDUINO_ARCH_ESP8266)
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
#else
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // for all other devices
#endif
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

#if defined (ARDUINO_ARCH_ESP8266)
#else
#endif


const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
	
	lcd.begin(LCD_COLS, LCD_ROWS);
	lcd.print("Hello, World!");
}

void loop() {}

Did you adjust either the code or the wiring to the appropriate pins? Your original code used pins 2, 3, 4, 5, 11, and 12, the last code you posted uses pins 4, 5, 6, 7, 8, and 9. The wiring looks appropriate for the original code, not the code from the hd44780 library.

You can correct the bug with Print.h by following the instructions in the following post: https://forum.arduino.cc/index.php?topic=678338.msg4572457#msg4572457 , although I prefer the HD44780 library myself.

Another way to eliminate the warning messages is to declare the array of char * as const:

const char* lyrics[] = {
  "Drink all the...",
  "     BOOZE!     ",
  "Hack all the... ",
  "    THINGS!     "
};

david_2018:
Did you adjust either the code or the wiring to the appropriate pins? Your original code used pins 2, 3, 4, 5, 11, and 12, the last code you posted uses pins 4, 5, 6, 7, 8, and 9. The wiring looks appropriate for the original code, not the code from the hd44780 library.

You can correct the bug with Print.h by following the instructions in the following post: https://forum.arduino.cc/index.php?topic=678338.msg4572457#msg4572457 , although I prefer the HD44780 library myself.

Another way to eliminate the warning messages is to declare the array of char * as const:

const char* lyrics[] = {

"Drink all the...",
  "    BOOZE!    ",
  "Hack all the... ",
  "    THINGS!    "
};

SOLVED! when switching from liquidcrystal.h to hd44780 I forgot to change the wiring. Thanks!