Skip to content

Commit

Permalink
V 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Dec 23, 2023
1 parent 93b7bfd commit a513d20
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 537 deletions.
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# Makefile to install library for HD44780_LCD library.
# URL: https://github.com/gavinlyonsrepo/HD44780_LCD_RPI
# Library is installed to /usr/lib and include files are placed at /usr/include.
# Uninstall and clean options provided

# ***************************
# Options
# 1. make = install library
# 2. clean = deletes .o files generated by step 1 from build directory
# 3. make uninstall = uninstalls library
# ***************************
# == Options ==
# 1. make = compile library
# 2. make install = install library to filesystem may need sudo)
# 3. make clean = deletes .o files generated by step 1 from build directory
# 4. make uninstall = uninstalls library (may need sudo)
# =============

# Where you want it installed
PREFIX=/usr
# where to place the libray
# where to place the library
LIBDIR=$(PREFIX)/lib
# library name
LIB=libHD44780_LCD_RPI
Expand All @@ -26,17 +27,17 @@ SRCS = $(wildcard $(SRC)/*.cpp)
OBJS = $(patsubst $(SRC)%.cpp, $(OBJ)/%.o, $(SRCS))

CXX=g++
CCFLAGS= -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -Iinclude/
CCFLAGS= -march=native -mtune=native -mcpu=native -Iinclude/
LDFLAGS= -lbcm2835

# make all
# reinstall the library after each recompilation
all: pre-build HD44780_LCD_RPI install
all: clean pre-build HD44780_LCD_RPI

pre-build:
@echo
@echo "*****************"
@echo "[START!]"
@echo "[MAKE LIBRARY]"
@echo
$(MD) -vp $(OBJ)

Expand All @@ -61,7 +62,7 @@ install:
@rm -rvf ${LIB}.*
@echo "*****************"
@echo
@echo "[INSTALL HEADERS]"
@echo "[INSTALL LIBRARY HEADERS]"
@if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
@cp -vf include/HD44780_LCD.hpp $(PREFIX)/include
@cp -vf include/HD44780_LCD_Print.hpp $(PREFIX)/include
Expand All @@ -73,7 +74,7 @@ uninstall:
@echo "[UNINSTALL LIBRARY]"
@rm -vf ${LIBDIR}/${LIB}.*

@echo "[UNINSTALL HEADERS]"
@echo "[UNINSTALL LIBRARY HEADERS]"
@rm -rvf $(PREFIX)/include/HD44780_LCD.*
@rm -rvf $(PREFIX)/include/HD44780_LCD_Print.*
@echo "[DONE!]"
Expand Down
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
6. Tested on size 16x02 and 20x04 (but may work on other sizes eg 16x04 , untested)

* Author: Gavin Lyons
* Developed on
* Development Tool chain.
1. Raspberry PI 3 model b
2. C++, g++ (Raspbian 8.3.0-6+rpi1) 8.3.0
3. Raspbian 10 stretch OS, armv7l Linux 5.10.63-v7+
4. bcm2835 Library 1.68
3. Raspbian 10 Buster OS, armv7l Linux 5.10.63-v7+ , 32 bit.
4. bcm2835 Library 1.73 (dependency)


## Installation

1. Make sure I2C bus is enabled on your raspberry PI

2. Install the dependency bcm2835 Library if not installed (at time of writing latest version is 1.68.)
2. Install the dependency bcm2835 Library if not installed (at time of writing latest version is 1.73.)
* The bcm2835 library is a dependency and provides low level I2C bus, delays and GPIO control.
* Install the C libraries of bcm2835, [Installation instructions here](http://www.airspayce.com/mikem/bcm2835/)

Expand All @@ -52,15 +52,16 @@
* Run following command to download from github.

```sh
curl -sL https://github.com/gavinlyonsrepo/HD44780_LCD_RPI/archive/1.3.1.tar.gz | tar xz
curl -sL https://github.com/gavinlyonsrepo/HD44780_LCD_RPI/archive/1.3.2.tar.gz | tar xz
```

4. Run "make" to run the makefile in repo base folder to install library, it will be
installed to usr/lib and usr/include

```sh
cd HD44780_LCD_RPI-1.3.1
sudo make
cd HD44780_LCD_RPI-1.3.2
make
sudo make install
```

## Test
Expand All @@ -76,13 +77,14 @@ make
make run
```

2. There are 3 examples files.
2. There are 4 examples files.
To decide which one the makefile builds simply edit "SRC" variable at top of the makefile in examples folder.
in the "User SRC directory Option Section". Pick an example "SRC" directory path and ONE ONLY.
Comment out the rest and repeat: make & make run.

| Filepath | File Function | Screen Size |
| ---- | ---- | ---- |
| src/HELLO_16x02 | Hello world basic use case | 16x02 |
| src/TEST_16x02 | Carries out test sequence testing features | 16x02 |
| src/TEST_20x04 | Carries out test sequence testing features | 20x04 |
| src/CLOCK_16x02 | A basic clock Demo | 16x02 |
Expand All @@ -99,24 +101,32 @@ Connections
### I2C

Hardware I2C.
Clock rate Settings and I2C Address is set in the constructor in main.cpp.

1. I2C LCD Slave Address is set to 0x27 by default(your module could be different).
2. I2C Clock rate can be a passed into in the constructor as a argument, five possible values :
1. I2C Address is set by default to 0x27(your module could be different,
user can change argument passed into LCD class constructor).

2. I2C Clock rate can be a passed into in the LCD class constructor method as a argument, five possible values :
If you send 0 (the default) It sets it to 100KHz and uses bcm2835_i2c_set_baudrate to do so.
Alternatively you can pass 1 of 4 BCM2835_I2C_CLOCK_DIVIDER values 2500, 626 150 or 148.
See image below.

3. In the event of an error writing a byte, debug info with error code will be written to console.
This error code is the bcm2835I2CReasonCodes enum. Debug flag must be set to true to see this output.
See image below for bcm2835I2CReasonCodes.

4. If you have multiple devices on I2C bus at different clock speeds.
The I2C clock speed function may have to called before each tranche of LCD commands.
and not just at start.

![ bcm ](https://github.com/gavinlyonsrepo/SSD1306_OLED_RPI/blob/main/extras/image/bcm.jpg)


| Value | Method | I2C speed |
| ---- | ---- | ---- |
| 0 (default) | bcm2835_i2c_set_baudrate(100000) | 100Khz |
| 2500 | bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_2500) | 100Khz |
| 626 | bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_626) | 399.4 kHz |
| 150 | bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_150) | 1.666 MHz |
| 148 | bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_148) | 1.689 MHz |

For more info on bcm2835I2CClockDivider & bcm2835I2CReasonCodes see [bcm2835 doc's for details](http://www.airspayce.com/mikem/bcm2835/group__constants.html)

### Debug

User can turn on debug messages with PCF8574_DebugSet method see example file.
User can turn on debug messages with LCDDebugSet method see example file.

### API

Expand Down
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# Pick on example "SRC" dir path and ONE Only.
# Comment out the other's.

SRC=src/TEST_16x02
SRC=src/HELLO_16x02
#SRC=src/TEST_16x02
#SRC=src/TEST_20x04
#SRC=src/CLOCK_16x02

Expand Down
97 changes: 52 additions & 45 deletions examples/src/CLOCK_16x02/main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
/*
* File: main.cpp
* Description:
* This file contains the "main" function for a clock demo (16x02 LCD)
* to test the HD44780 LCD library, see issue one github
* Author: Gavin Lyons.
* Compiler: C++ g++ (Raspbian 8.3.0-6+rpi1) 8.3.0
* Tested: Raspbian 10, armv7l Linux 5.10.63-v7+ , RPI M3B Rev 1.2
* Created : Jan 2023
* Description: See URL for full details.
* URL: https://github.com/gavinlyonsrepo/HD44780_LCD_RPI
*
* Notes:
*
* (1) set PCF8574_DebugSet(false) to true in Setup() for debug
*
* (2) For description of entry modes , cursor types, custom characters
* and more see here http://dinceraydin.com/lcd/commands.htm
*
* (3) -std=c++2a required in makefile
*
* (4) press ctrl + c to quit
/*!
@file main.cpp
@author Gavin Lyons
@brief This file contains the "main" function for a clock demo (16x02 LCD)
to test the HD44780 LCD library, see issue one github
@note
-# set DebugSet(false) to true in Setup() for debug
-# For description of entry modes , cursor types, custom characters and more see here http://dinceraydin.com/lcd/commands.htm
-# -std=c++2a required in makefile
-# press ctrl + c to quit
*/

// Section: Included library
Expand All @@ -34,10 +23,10 @@

// Section: Globals
// myLCD(rows , cols , PCF8574 I2C address, I2C speed)
HD44780LCD myLCD( 2, 16, 0x27, 0); // instantiate an object
HD44780PCF8574LCD myLCD( 2, 16, 0x27, 0); // instantiate an object

// Section: Function Prototypes
void setup(void);
bool setup(void);
void DisplayInfo(void);
void endTest(void);
std::string UTC_string(void);
Expand All @@ -48,13 +37,8 @@ void signal_callback_handler(int signum);
int main(int argc, char **argv)
{
signal(SIGINT, signal_callback_handler);
if(!bcm2835_init())
{
std::cout << "Library bcm2835 failed init" << std::endl ;
return -1;
}

setup();
if (!setup()) return -1;
while(1)
{
DisplayInfo();
Expand All @@ -67,37 +51,60 @@ int main(int argc, char **argv)

// Section : Functions

void setup(void)
{
std::cout << "LCD Begin" << std::endl;
myLCD.PCF8574_LCD_I2C_ON();
bcm2835_delay(DISPLAY_DELAY_1);
myLCD.PCF8574_LCDInit(myLCD.LCDCursorTypeOn);
myLCD.PCF8574_LCDClearScreen();
myLCD.PCF8574_LCDBackLightSet(true);
myLCD.PCF8574_DebugSet(false); // Set to true to turn on debug mode
bool setup(void) {
std::cout << "LCD Clock Demo Begin" << std::endl;
std::cout << "Press 'ctrl + c' to quit" << std::endl;
// Check if Bcm28235 lib installed and print version.
if(!bcm2835_init())
{
std::cout << "Error 1201: init bcm2835 library , Is it installed ?" << std::endl;
return false;
}

bcm2835_delay(250);

// Turn on I2C bus (optionally it may already be on)
if (!myLCD.LCD_I2C_ON())
{
std::cout << "Error 1202: bcm2835_i2c_begin :Cannot start I2C, Running as root?" << std::endl;
return false;
}

myLCD.LCDDebugSet(false); // Set to true to turn on debug mode
myLCD.LCD_I2C_SetSpeed();
myLCD.LCDInit(myLCD.LCDCursorTypeOn);
myLCD.LCDClearScreen();
myLCD.LCDBackLightSet(true);

// print out library versions & flag status( Note optional)
std::cout << "bcm2835 library Version Number :" << bcm2835_version() << std::endl;
std::cout << "HD44780_LCD_RPI :" << myLCD.LCDVerNumGet() << std::endl;
std::cout << "Debug status is : " << (myLCD.LCDDebugGet() ? "On" : "Off") << std::endl ;
std::cout << "Backlight status is : " << (myLCD.LCDBackLightGet() ? "On" : "Off")<< std::endl ;

return true;
}

void DisplayInfo(void)
{
std::string TimeString = UTC_string();
std::cout<< TimeString << "\r" << std::flush;
auto timeInfo = TimeString.substr(0, 10);
myLCD.PCF8574_LCDGOTO(myLCD.LCDLineNumberOne, 0);
myLCD.print(timeInfo);
auto DateInfo = TimeString.substr(11);
myLCD.PCF8574_LCDGOTO(myLCD.LCDLineNumberTwo, 0);
myLCD.LCDGOTO(myLCD.LCDLineNumberOne, 0);
myLCD.print(timeInfo);
myLCD.LCDGOTO(myLCD.LCDLineNumberTwo, 0);
myLCD.print(DateInfo);
}


void endTest()
{
myLCD.PCF8574_LCDDisplayON(false); //Switch off display
myLCD.PCF8574_LCD_I2C_OFF();
myLCD.LCDDisplayON(false); //Switch off display
myLCD.LCD_I2C_OFF();
bcm2835_close(); // Close the library
std::cout << std::endl;
std::cout << "LCD End" << std::endl ;
std::cout << "LCD Clock Demo End" << std::endl ;
}

//Return UTC time as a std:.string with format "yyyy-mm-dd hh:mm:ss".
Expand Down
Loading

0 comments on commit a513d20

Please sign in to comment.