I have a project where I’ll have to interface 5-6 sensors with arduino via LCD and wireless module as well. I’m trying to interface LCD for now without any sensors.
I’m unable to interface my 20x4 LCD with Arduino.
Initially I tried to connect it directly with Arduino, all I was getting was some Chinese characters moving quickly through the display.
I switched to using an I2C Port Expander Module , still I’m not getting any viable results. All I get is one row of boxes followed by an empty one then another row of boxes followed by another empty row.
I picked up the code from circuito.io, and patched according to its intstructions.
https://www.circuito.io/app?components=512,11021,417987
Moreover, I’m getting an error LCD not found at serial monitor.
The code I’m using is
// Include Libraries
#include "Arduino.h"
#include "LiquidCrystal_PCF8574.h"
// Pin Definitions
// Global variables and defines
// There are several different versions of the LCD I2C adapter, each might have a different address.
// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints.
// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example.
#define LCD_ADDRESS 0x3F
//#define LCD_ADDRESS 0x27
// Define LCD characteristics
#define LCD_ROWS 4
#define LCD_COLUMNS 20
#define SCROLL_DELAY 150
#define BACKLIGHT 255
// object initialization
LiquidCrystal_PCF8574 lcd20x4;
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");
// initialize the lcd
lcd20x4.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT);
menuOption = menu();
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
if(menuOption == '1') {
// LCD Display 20x4 I2C - Test Code
// The LCD Screen will display the text of your choice.
lcd20x4.clear(); // Clear LCD screen.
lcd20x4.selectLine(2); // Set cursor at the begining of line 2
lcd20x4.print(" Circuito.io "); // Print print String to LCD on first line
lcd20x4.selectLine(3); // Set cursor at the begining of line 3
lcd20x4.print(" Rocks! "); // Print print String to LCD on second line
delay(1000);
}
if (millis() - time0 > timeout)
{
menuOption = menu();
}
}
// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{
Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) LCD Display 20x4 I2C"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());
// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{
if(c == '1')
Serial.println(F("Now Testing LCD Display 20x4 I2C"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}