Skip to content

Commit

Permalink
version 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Jan 28, 2024
1 parent 470d5dd commit 2c0c301
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 91 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@
## Installation


1. Install the dependency bcm2835 Library if not installed( see notes about issue 1.73)
1. Install the dependency bcm2835 Library if not installed.
* Install the C libraries of bcm2835, [Installation instructions here](http://www.airspayce.com/mikem/bcm2835/)

2. Download the HD44780_LCD_RPI library
* Open a Terminal in a folder where you want to download,build & test library
* Run following command to download from github.

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

3. 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.2
cd HD44780_LCD_RPI-1.3.3
make
sudo make install
```
Expand Down Expand Up @@ -105,14 +105,14 @@ Hardware I2C.
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.
2. I2C Clock rate can be a passed into in the LCD class constructor method as a argument,
User 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.
See image below for bcm2835I2CReasonCodes. User can set error timeout between retry attempts and number of retry attempts
and can monitor the Error flag to see current 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.
Expand Down Expand Up @@ -148,9 +148,11 @@ Output of custom character test in test file.
## Notes and issues


1. If you upgrade to V 1.73 of the bcm2835 dependancy (the latest at time of writing ) you may see Intermittant
BCM2835_I2C_REASON_ERROR_TIMEOUT [errors on I2C write operations](https://groups.google.com/g/bcm2835/c/45O8Y_5yv00). Best stay on 1.71 until a new upgrade is released.

1. If you upgrade to V 1.73 of the bcm2835 dependancy (the latest at time of writing Jan 2024) you may see Intermittant
BCM2835_I2C_REASON_ERROR_TIMEOUT. This timeout error was introduced in that release.
Best stay on 1.71 until a new upgrade is released or run at BCM2835_I2C_CLOCK_DIVIDER_626 I saw zero errors at this I2C clock rate.
It was only present at BCM2835_I2C_CLOCK_DIVIDER_2500(100K).


2. For detailed graphical description of entry modes , cursor types, custom characters
and more see here [link](http://dinceraydin.com/lcd/commands.htm)
Expand Down
3 changes: 2 additions & 1 deletion examples/src/CLOCK_16x02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

// Section: Function Prototypes
bool setup(void);
Expand Down Expand Up @@ -67,6 +67,7 @@ bool setup(void) {
if (!myLCD.LCD_I2C_ON())
{
std::cout << "Error 1202: bcm2835_i2c_begin :Cannot start I2C, Running as root?" << std::endl;
bcm2835_close(); // Close the library
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/src/HELLO_16x02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

// Section: Function Prototypes
bool setup(void);
Expand Down Expand Up @@ -50,6 +50,7 @@ bool setup(void) {
if (!myLCD.LCD_I2C_ON())
{
std::cout << "Error 1202: bcm2835_i2c_begin :Cannot start I2C, Running as root?" << std::endl;
bcm2835_close(); // Close the library
return false;
}
myLCD.LCDDebugSet(false);
Expand Down
7 changes: 3 additions & 4 deletions examples/src/TEST_16x02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

// Section: Function Prototypes
bool setup(void);
Expand All @@ -50,7 +50,6 @@ void endTest(void);
int main(int argc, char **argv)
{
if (!setup()) return -1;

helloWorld();
cursorMoveTest();
scrollTest();
Expand Down Expand Up @@ -79,12 +78,13 @@ bool setup(void) {
return false;
}

bcm2835_delay(250);
bcm2835_delay(500);

// 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;
bcm2835_close(); // Close the library
return false;
}

Expand All @@ -100,7 +100,6 @@ bool setup(void) {
std::cout << "HD44780_LCD_RPI lib Version Num :" << 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;
}

Expand Down
5 changes: 3 additions & 2 deletions examples/src/TEST_20x04/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

// Section: Function Prototypes
bool setup(void);
Expand Down Expand Up @@ -81,10 +81,11 @@ bool setup(void) {

bcm2835_delay(250);

// Turn on I2C bus (optionally it may already be on)
// Turn on I2C bus (optional, 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;
bcm2835_close(); // Close the library
return false;
}

Expand Down
20 changes: 12 additions & 8 deletions examples/src/TEST_I2C_16x02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

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

// Section: Function Prototypes
bool setup(void);
void helloWorld(void);
void test(void);
void endTest(void);

// Section: Main Loop
int main(int argc, char **argv)
{
if (!setup()) return -1;
helloWorld();
test();
endTest();
return 0;
}
Expand All @@ -49,15 +49,17 @@ bool setup(void) {
if (!myLCD.LCD_I2C_ON())
{
std::cout << "Error 1202: bcm2835_i2c_begin :Cannot start I2C, Running as root?" << std::endl;
bcm2835_close(); // Close the library
return false;
}

bcm2835_delay(1000);
myLCD.LCDDebugSet(true); // Turn debug messages on
myLCD.LCDDebugSet(false); // Turn debug messages on
myLCD.LCD_I2C_SetSpeed();
if (myLCD.LCDCheckConnection() != 0)
{
std::cout << "Error 1203: bcm2835_i2c_begin :LCD not on bus?" << std::endl;
bcm2835_close(); // Close the library
return false;
}

Expand All @@ -66,20 +68,22 @@ bool setup(void) {
std::cout << "HD44780_LCD_RPI lib Version Num :" << 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 ;
std::cout << "I2C Debug Error : " << myLCD.LCDI2CErrorGet() << std::endl; // Print I2C error flag
std::cout << "I2C Error Timeout mS : " << myLCD.LCDI2CErrorTimeoutGet() << std::endl; // Print I2C Timeout

std::cout << "I2C Debug Error : " << +myLCD.LCDI2CErrorGet() << std::endl; // Print I2C error flag
std::cout << "I2C Error Timeout mS : " << myLCD.LCDI2CErrorTimeoutGet() << std::endl; // Print I2C error Timeout
std::cout << "I2C Error retry attempts counts: " << +myLCD.LCDI2CErrorRetryNumGet() << std::endl; // Print I2C error retry count
myLCD.LCDInit(myLCD.LCDCursorTypeOn);
myLCD.LCDClearScreen();
return true;
}

void helloWorld(void)
void test(void)
{
std::cout << "Test" << std::endl;
char testString[] = "I2C Test";
myLCD.LCDGOTO(myLCD.LCDLineNumberOne, 0);
myLCD.LCDSendString(testString);
bcm2835_delay(5000);
myLCD.LCDClearScreen();
}


Expand Down
6 changes: 5 additions & 1 deletion extras/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
* Minor various optimizations
* Changed Makefile so it will compile on 64 bit OS
* Added Hello world example

* Version 1.3.3 Jan 2024
* Minor update
* Changed default I2C speed to deal with latest bcm2835 release v1.73 problems: Intermittent
timeout errors on 100K,
* Added user ability to set I2C error timeout and number of retries attempts.
28 changes: 13 additions & 15 deletions include/HD44780_LCD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
@file HD44780_LCD.hpp
@author Gavin Lyons
@brief HD44780-based character LCD I2C(PCF8574)library header file for RPI
@note
-# 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
-# URL: https://github.com/gavinlyonsrepo/HD44780_LCD_RPI
@details URL: https://github.com/gavinlyonsrepo/HD44780_LCD_RPI
*/

#include <bcm2835.h>
Expand Down Expand Up @@ -68,19 +64,20 @@ class HD44780PCF8574LCD : public Print{
void LCDBackLightSet(bool);
bool LCDBackLightGet(void);

void LCDDebugSet(bool);
bool LCDDebugGet(void);

int16_t LCDVerNumGet(void);

bool LCD_I2C_ON(void);
void LCD_I2C_SetSpeed(void);
void LCD_I2C_OFF(void);
int16_t LCDCheckConnection(void);
bool LCDI2CErrorGet(void);
uint8_t LCDCheckConnection(void);
uint8_t LCDI2CErrorGet(void);
uint16_t LCDI2CErrorTimeoutGet(void);
void LCDI2CErrorTimeoutSet(uint16_t);

uint8_t LCDI2CErrorRetryNumGet(void);
void LCDI2CErrorRetryNumSet(uint8_t);
bool LCDDebugGet(void);
void LCDDebugSet(bool);

void LCDSendString (char *str);
void LCDSendChar (char data);
virtual size_t write(uint8_t);
Expand Down Expand Up @@ -123,14 +120,15 @@ class HD44780PCF8574LCD : public Print{
enum LCDBackLight_e _LCDBackLight= LCDBackLightOnMask; /**< Enum to store backlight status*/


const int16_t _LibVersionNum = 132; /**< library version number */
const int16_t _LibVersionNum = 133; /**< library version number */
bool _DebugON = false; /**< debug flag , if true error messages will be printed to console */

const uint8_t LCD_I2C_ADDRESS = 0x27; /**< Default I2C address for I2C module PCF8574 backpack on LCD */
uint8_t _LCDSlaveAddresI2C = LCD_I2C_ADDRESS ; /**< I2C address for I2C module PCF8574 backpack on LCD*/
uint16_t _LCDSpeedI2C = 0x00; /**< I2C speed default 0(100K) or BCM2835_I2C_CLOCK_DIVIDER enum values */
uint16_t _I2C_ErrorDelay = 100; /**<I2C delay in event of error in mS*/
uint16_t _I2C_Error = 0; /**< In event of I2C error holds bcm2835 I2C reason code */
uint16_t _LCDSpeedI2C = BCM2835_I2C_CLOCK_DIVIDER_626 ; /**< I2C speed default 0(100K) or BCM2835_I2C_CLOCK_DIVIDER enum values */
uint16_t _I2C_ErrorDelay = 100; /**<I2C delay(in between retry attempts) in event of error in mS*/
uint8_t _I2C_ErrorRetryNum = 3; /**< In event of I2C error number of retry attempts*/
uint8_t _I2C_ErrorFlag = 0; /**< In event of I2C error holds bcm2835 I2C reason code 0x00 = success*/

uint8_t _NumRowsLCD = 2; /**< number of rows on LCD*/
uint8_t _NumColsLCD = 16; /**< number of columns on LCD*/
Expand Down
11 changes: 6 additions & 5 deletions include/HD44780_LCD_Print.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*!
@file SSD1306_OLED_Print.hpp
@brief Base class that provides print() and println() for SSD1306_OLED_RPI library
@file HD44780_Print.hpp
@brief Base class that provides print() and println() for HD44780_LCD library
@note Port of arduino built-in print class, G Lyons 2022.
*/


#pragma once

#include <inttypes.h>
#include <stdio.h> // for size_t
#include <cstring> // for strlen
#include <cinttypes>
#include <cstdio> // for size_t
#include <cstring>
#include <cmath>
#include <string>

#define PGM_P const char*
Expand Down
Loading

0 comments on commit 2c0c301

Please sign in to comment.