Skip to content

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Apr 26, 2022
1 parent 8de1423 commit fde1e4a
Show file tree
Hide file tree
Showing 9 changed files with 672 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Overview
2. Backlight, scroll, cursor and entry-mode control.
3. Custom character support + print class for numerical data.
4. Hardware I2C
5. Tested on size 16x02 only but may work on other sizes (20x4 , 16X4 etc).
5. Tested on size 16x02 + 20x04 (but may work on other sizes eg 16X4 but not tested).

* Author: Gavin Lyons

Expand All @@ -37,10 +37,14 @@ See link below for instruction for this and for the other methods too.
Output
---------------------

Output of custom character test in test file.
Output of custom character test in testrun example file on 16x02 display.

![ pic ](https://github.com/gavinlyonsrepo/HD44780_LCD_RPI/blob/main/extras/image/custom_output.jpg)

20x04 display.

![ pic2 ](https://github.com/gavinlyonsrepo/HD44780_LCD_PCF8574/blob/main/extras/image/2004.jpg)

Tested
------------------------

Expand Down
1 change: 1 addition & 0 deletions examples/TestRun/TestRun.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Notes:
* (1) For description of entry modes , cursor types, custom characters
* and more see here http://dinceraydin.com/lcd/commands.htm
* (2) This is for 16 column 2 row LCD
*/

// Section: Included library
Expand Down
303 changes: 303 additions & 0 deletions examples/TestRun20X04/TestRun20X04.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
/*
* File: TestRu20X04n.cpp
* Description:
* This file contains the "main" function for project, a set of test sequence
* to test the HD44780 LCD library 20x04
* Author: Gavin Lyons.
* Description: See URL for full details.
* URL: https://github.com/gavinlyonsrepo/HD44780_LCD_PCF8574
*
* Notes:
* (1) For description of entry modes , cursor types, custom characters
* and more see here http://dinceraydin.com/lcd/commands.htm
* (2) This file is for 20 cols 4 row LCD
*/

// Section: Included library
#include "HD44780_LCD_PCF8574.h"

// Section: Defines
#define DISPLAY_DELAY_1 1000
#define DISPLAY_DELAY_2 2000
#define DISPLAY_DELAY 5000

// Section: Globals
// myLCD(rows , cols , PCF8574 I2C address)
HD44780LCD myLCD( 4, 20, 0x27); // instantiate an object

// Section: Function Prototypes

void helloWorld(void);
void cursorMoveTest(void);
void scrollTest(void);
void gotoTest(void);
void clearLineTest(void);
void cursorTest(void);
void entryModeTest(void);
void writeNumTest(void);
void customChar(void);
void backLightTest(void);
void endTest(void);

// Section: Setup

void setup() {
delay(50);
myLCD.PCF8574_LCDInit(LCDCursorTypeOn);
myLCD.PCF8574_LCDClearScreen();
myLCD.PCF8574_LCDBackLightSet(true);

}

// Section: Main Loop

void loop() {

helloWorld();
cursorMoveTest();
scrollTest();
gotoTest();
clearLineTest();
cursorTest(); // Cursor type and screen reset test(4 off ) check,
// cursor mode is changed by calling reset.
entryModeTest(); // Text entry mode (4 off ) Note: if screen is reset
// non default entry mode setting will also be reset
writeNumTest(); // Print numerical data using print() test
customChar(); // Custom character from CGRAM test
backLightTest();

} // End of Main

// Section : Functions
void helloWorld(void) {
char teststr1[] = "Hello";
char teststr2[] = "World";
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 0);
myLCD.PCF8574_LCDSendString(teststr1);
myLCD.PCF8574_LCDGOTO(LCDLineNumberThree , 0);
myLCD.PCF8574_LCDSendString(teststr2); // Display a string
myLCD.PCF8574_LCDSendChar('!'); // Display a single character
delay(DISPLAY_DELAY_1);
}

void cursorMoveTest(void) {
myLCD.PCF8574_LCDMoveCursor(LCDMoveRight, 2);
delay(DISPLAY_DELAY);
myLCD.PCF8574_LCDMoveCursor(LCDMoveLeft, 2);
}

void scrollTest(void) {
for (uint8_t i = 0; i < 10; i++) {
myLCD.PCF8574_LCDScroll(LCDMoveRight, 1);
delay(DISPLAY_DELAY_2);
}
myLCD.PCF8574_LCDScroll(LCDMoveLeft, 10);
delay(DISPLAY_DELAY_2);
}

void gotoTest(void) {
myLCD.PCF8574_LCDClearScreen();

char teststr1[] = "Line 1";
char teststr2[] = "Line 2";
char teststr3[] = "Line 3";
char teststr4[] = "Line 4";
char testchar = '!';
int columnPos = 0;

// Print a string to each line

myLCD.PCF8574_LCDGOTO(LCDLineNumberOne, 0);
myLCD.PCF8574_LCDSendString(teststr1);
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo , 0);
myLCD.PCF8574_LCDSendString(teststr2);
myLCD.PCF8574_LCDGOTO(LCDLineNumberThree , 0);
myLCD.PCF8574_LCDSendString(teststr3);
myLCD.PCF8574_LCDGOTO(LCDLineNumberFour , 0);
myLCD.PCF8574_LCDSendString(teststr4);
delay(DISPLAY_DELAY);

myLCD.PCF8574_LCDClearScreen();

// Print out ASCII table one character at a time in every position
// with a unique goto command
for (columnPos = 0 ; columnPos <20 ; columnPos++)
{
myLCD.PCF8574_LCDGOTO(LCDLineNumberOne, columnPos);
myLCD.PCF8574_LCDSendChar(testchar++);
} //Line 1
delay(DISPLAY_DELAY_1);

for (columnPos = 0 ; columnPos <20 ; columnPos++)
{
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, columnPos);
myLCD.PCF8574_LCDSendChar(testchar++);
} //Line 2
delay(DISPLAY_DELAY_1);

for (columnPos = 0 ; columnPos <20 ; columnPos++)
{
myLCD.PCF8574_LCDGOTO(LCDLineNumberThree, columnPos);
myLCD.PCF8574_LCDSendChar(testchar++);
} //Line 3
delay(DISPLAY_DELAY_1);

for (columnPos = 0 ; columnPos <20 ; columnPos++)
{
myLCD.PCF8574_LCDGOTO(LCDLineNumberFour, columnPos);
myLCD.PCF8574_LCDSendChar(testchar++);
} // Line 4
delay(DISPLAY_DELAY);
}

void clearLineTest(void)
{
myLCD.PCF8574_LCDClearLine(LCDLineNumberOne);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberTwo);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberThree);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberFour);
delay(DISPLAY_DELAY_2);
}

void cursorTest(void) {
char teststr1[] = "Cursor no 4";
char teststr2[] = "Cursor no 1";
char teststr3[] = "Cursor no 2";
char teststr4[] = "Cursor no 3";

myLCD.PCF8574_LCDResetScreen(LCDCursorTypeOnBlink); //type 4 cursor
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 0);
myLCD.PCF8574_LCDSendString(teststr1);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberTwo);

myLCD.PCF8574_LCDResetScreen(LCDCursorTypeOff); //type 1 cursor
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 0);
myLCD.PCF8574_LCDSendString(teststr2);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberTwo);

myLCD.PCF8574_LCDResetScreen(LCDCursorTypeBlink); //type 2 cursor
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 0);
myLCD.PCF8574_LCDSendString(teststr3);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberTwo);

myLCD.PCF8574_LCDResetScreen(LCDCursorTypeOn); // Back to initial state , type 3
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 0);
myLCD.PCF8574_LCDSendString(teststr4);
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearLine(LCDLineNumberTwo);
}

void writeNumTest()
{
int numPos = 193;
int numNeg = -8582;
double myPI = 3.1456;

myLCD.PCF8574_LCDGOTO(LCDLineNumberOne, 0);
myLCD.print(numPos);
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo , 0);
myLCD.print(numNeg);
myLCD.PCF8574_LCDMoveCursor(LCDMoveRight, 2);
myLCD.print(myPI,3);

delay(DISPLAY_DELAY);
myLCD.PCF8574_LCDClearScreen();

myLCD.PCF8574_LCDGOTO(LCDLineNumberOne, 0); // 11
myLCD.print(11);
myLCD.PCF8574_LCDMoveCursor(LCDMoveRight, 2); // 13
myLCD.print(11,OCT);
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo , 0); // B
myLCD.print(11, HEX);
myLCD.PCF8574_LCDMoveCursor(LCDMoveRight, 2); // 1011
myLCD.print(11,BIN);

delay(DISPLAY_DELAY);
}

void customChar(void) {

// Data to test custom function
uint8_t bellChar[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t noteChar[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clockChar[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
uint8_t heartChar[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duckChar[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t checkChar[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t crossChar[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t enterChar[8] = {0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};

myLCD.PCF8574_LCDClearScreen();

// Load the CGRAM with the data , custom characters
// location argument must be 0 to 7
myLCD.PCF8574_LCDCreateCustomChar(0, bellChar); // Location 0
myLCD.PCF8574_LCDCreateCustomChar(1, noteChar);
myLCD.PCF8574_LCDCreateCustomChar(2, clockChar);
myLCD.PCF8574_LCDCreateCustomChar(3, heartChar);
myLCD.PCF8574_LCDCreateCustomChar(4, duckChar);
myLCD.PCF8574_LCDCreateCustomChar(5, checkChar);
myLCD.PCF8574_LCDCreateCustomChar(6, crossChar);
myLCD.PCF8574_LCDCreateCustomChar(7, enterChar); // Location 7

myLCD.PCF8574_LCDGOTO(LCDLineNumberThree, 0);

// Print out custom characters from
// CGRAM locations 0-7
// location argument must be 0 to 7
for (uint8_t i = 0; i < 8; i++) {
myLCD.PCF8574_LCDPrintCustomChar(i);
myLCD.PCF8574_LCDMoveCursor(LCDMoveRight, 1);
}

delay(DISPLAY_DELAY);
myLCD.PCF8574_LCDClearScreen();
}

void backLightTest(void)
{
char teststr4[] = "Back Light";
// Needs another command/data before it changes Light
myLCD.PCF8574_LCDBackLightSet(false);

myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo , 1);
myLCD.PCF8574_LCDSendString(teststr4);
delay(DISPLAY_DELAY);
myLCD.PCF8574_LCDBackLightSet(true);
myLCD.PCF8574_LCDClearScreen();
}

void entryModeTest(void) {

char teststr8[] = "1234";

myLCD.PCF8574_LCDChangeEntryMode(LCDEntryModeOne);
myLCD.PCF8574_LCDGOTO(LCDLineNumberOne, 8);
myLCD.PCF8574_LCDSendString(teststr8); // <-C4321
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearScreenCmd();

myLCD.PCF8574_LCDChangeEntryMode(LCDEntryModeTwo);
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 8);
myLCD.PCF8574_LCDSendString(teststr8); // C4321->
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearScreenCmd();

myLCD.PCF8574_LCDChangeEntryMode(LCDEntryModeFour);
myLCD.PCF8574_LCDGOTO(LCDLineNumberTwo, 8);
myLCD.PCF8574_LCDSendString(teststr8); // <-1234C
delay(DISPLAY_DELAY_2);
myLCD.PCF8574_LCDClearScreenCmd();

myLCD.PCF8574_LCDChangeEntryMode(LCDEntryModeThree); // Set back to default entry mode
myLCD.PCF8574_LCDClearScreenCmd();
delay(DISPLAY_DELAY_1);
}

// *** EOF ***
Loading

0 comments on commit fde1e4a

Please sign in to comment.