Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Sep 16, 2022
1 parent b90489a commit 231533c
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 48 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)


![ lcd ](https://github.com/gavinlyonsrepo/pic_16F1619_projects/blob/master/images/LCDPCF.jpg)

Expand All @@ -22,6 +24,7 @@ Overview
3. Custom character support + print class for numerical data.
4. Hardware I2C
5. Tested on size 16x02 + 20x04 (but may work on other sizes eg 16X4 but not tested).
6. Can support both I2C ports on the STM32 see tested section.

* Author: Gavin Lyons

Expand Down Expand Up @@ -50,12 +53,13 @@ Tested

Tested on following MCUs.
The example files are setup for an UNO/NANO for the pin connections used
by for other MCU testing see extras/doc folder GPIO_MCU_used.txt file.
by for other MCU testing see extras/doc folder GPIO_MCU_used.MD file.

1. Arduino UNO & NANO v3
2. ESP8266
3. ESP32
4. STM32 "blue pill"
4. STM32 "blue pill", Can support both I2C ports , In example files comment in #define STM32_BLUE_PILL_SETUP
and pick which port you want. Added in Version 1.2.0.

Ports
------------------------
Expand Down
32 changes: 21 additions & 11 deletions examples/HelloWorld/HelloWorld.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
* URL: https://github.com/gavinlyonsrepo/HD44780_LCD_PCF8574
*/

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

// Section: Defines
#define DISPLAY_DELAY_INIT 50 // mS
// **** NOTE :: Comment in If using STM32 bluepill ****
//#define STM32_BLUE_PILL_SETUP


// Section: Globals
#ifdef STM32_BLUE_PILL_SETUP // *** STM32 Blue Pill ***
// Set-up Choice I2C interface 1 or 2 :: pick one and one only
TwoWire Wire2(1,I2C_FAST_MODE); // Use STM32 I2C1
//TwoWire Wire2(2,I2C_FAST_MODE); // Use STM32 I2C2
HD44780LCD myLCD(2, 16, 0x27, &Wire2); // LCD object.rows ,cols ,PCF8574 I2C addr, Interface)
#else
// myLCD(rows , cols , PCF8574 I2C address)
HD44780LCD myLCD( 2, 16, 0x27); // instantiate a LCD object
HD44780LCD myLCD( 2, 16, 0x27); // instantiate an object
#endif

// Section: Setup

void setup()
{
delay(50);
void setup() {
delay(DISPLAY_DELAY_INIT);
myLCD.PCF8574_LCDInit(LCDCursorTypeOn);
myLCD.PCF8574_LCDClearScreen();
myLCD.PCF8574_LCDBackLightSet(true);
Expand All @@ -25,13 +37,11 @@ void setup()

// Section: Main Loop

void loop()
{
void loop() {
char testString[] = "Hello World";
myLCD.PCF8574_LCDSendString(testString);
myLCD.PCF8574_LCDSendChar('!'); // Display a single character
while(true){};

}
myLCD.PCF8574_LCDSendChar('!'); // Display a single character
while (true) {};
}

// EOF
9 changes: 9 additions & 0 deletions examples/TestRun/TestRun.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@
#define DISPLAY_DELAY_1 1000
#define DISPLAY_DELAY_2 2000
#define DISPLAY_DELAY 5000
// **** NOTE :: Comment in If using STM32 bluepill ****
//#define STM32_BLUE_PILL_SETUP

// Section: Globals
#ifdef STM32_BLUE_PILL_SETUP // *** STM32 Blue Pill ***
// Set-up Choice I2C interface 1 or 2 :: pick one and one only
TwoWire Wire2(1,I2C_FAST_MODE); // Use STM32 I2C1
//TwoWire Wire2(2,I2C_FAST_MODE); // Use STM32 I2C2
HD44780LCD myLCD(2, 16, 0x27, &Wire2); // LCD object.rows ,cols ,PCF8574 I2C addr, Interface)
#else
// myLCD(rows , cols , PCF8574 I2C address)
HD44780LCD myLCD( 2, 16, 0x27); // instantiate an object
#endif

// Section: Function Prototypes

Expand Down
9 changes: 9 additions & 0 deletions examples/TestRun20X04/TestRun20X04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@
#define DISPLAY_DELAY_1 1000
#define DISPLAY_DELAY_2 2000
#define DISPLAY_DELAY 5000
// **** NOTE :: Comment in If using STM32 bluepill ****
//#define STM32_BLUE_PILL_SETUP

// Section: Globals
#ifdef STM32_BLUE_PILL_SETUP // *** STM32 Blue Pill ***
// Set-up Choice I2C interface 1 or 2 :: pick one and one only
TwoWire Wire2(1,I2C_FAST_MODE); // Use STM32 I2C1
//TwoWire Wire2(2,I2C_FAST_MODE); // Use STM32 I2C2
HD44780LCD myLCD(4, 20, 0x27, &Wire2); // LCD object.rows ,cols ,PCF8574 I2C addr, Interface)
#else
// myLCD(rows , cols , PCF8574 I2C address)
HD44780LCD myLCD( 4, 20, 0x27); // instantiate an object
#endif

// Section: Function Prototypes

Expand Down
3 changes: 2 additions & 1 deletion extras/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* version 1.1.0 April 2022
* Tested on 20x04 for first time and github issue 1 closed off.
* Example file added for 20x04

* version 1.2.0 September 2022
* Option added for User to pick I2C port for STM32 bluepill, github issue 2.
28 changes: 28 additions & 0 deletions extras/doc/GPIO_MCU_used.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GPIO used in testing for I2C
--------------------------------------

UNO/NANO I2C

1. A4 SDA
2. A5 SCLK

ESP8266 HARDWARE I2C

3. D1 GPIO5 20 SCK
4. D2 GPIO4 19 SDA

ESP32 HARDWARE I2C

5. D22 GPIO22 SCK
6. D21 GPIO21 SDA

STM32 STM32F103C8T6 "blue pill" I2C

| Pin Name | Pin | Arduino Pin | PCB Label | Func | I2C Channel |
| -- | -- | -- | -- | -- | -- |
| PB6 | 42 | 22 | B6 | SCK | I2C1 |
| PB7 | 43 | 23 | B7 | SDA | I2C1 |
| PB10 | 21 | 26 | B10 | SCK | I2C2 |
| PB11 | 22 | 27 | B11 | SDA | I2C2 |


19 changes: 0 additions & 19 deletions extras/doc/GPIO_MCU_used.txt

This file was deleted.

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=HD44780_LCD_PCF8574
version=1.1.0
version=1.2.0
author=Gavin Lyons <[email protected]>
maintainer=Gavin Lyons <[email protected]>
sentence=Library to Support the HD44780 LCD I2C driven by the PCF8574 controller
Expand Down
25 changes: 14 additions & 11 deletions src/HD44780_LCD_PCF8574.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

// Section : constructor

HD44780LCD :: HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress)
HD44780LCD :: HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress,TwoWire *twi)
{
_NumRowsLCD = NumRow;
_NumColsLCD = NumCol;
_LCDSlaveAddresI2C = I2Caddress;
wire = twi;
}


// Section : Functions

// Func Desc: Send data byte to LCD via I2C
Expand All @@ -27,9 +29,9 @@ void HD44780LCD::PCF8574_LCDSendData(unsigned char data) {
dataI2C[2] = dataLower | (LCD_DATA_BYTE_ON & _LCDBackLight); //enable=1 and rs =1 1101 YYYY-X-en-X-rs
dataI2C[3] = dataLower | (LCD_DATA_BYTE_OFF & _LCDBackLight); //enable=0 and rs =1 1001 YYYY-X-en-X-rs

Wire.beginTransmission(_LCDSlaveAddresI2C);
Wire.write(dataI2C, 4) ;
TransmissionCode = Wire.endTransmission();
wire->beginTransmission(_LCDSlaveAddresI2C);
wire->write(dataI2C, 4) ;
TransmissionCode = wire->endTransmission();
if (TransmissionCode!= 0)
{
#ifdef LCD_SERIAL_DEBUG
Expand Down Expand Up @@ -58,9 +60,9 @@ void HD44780LCD::PCF8574_LCDSendCmd(unsigned char cmd) {
cmdI2C[2] = cmdLower | (LCD_CMD_BYTE_ON & _LCDBackLight); // YYYY-1100 YYYY-led-en-rw-rs ,enable=1 and rs =0
cmdI2C[3] = cmdLower | (LCD_CMD_BYTE_OFF & _LCDBackLight); // YYYY-1000 YYYY-led-en-rw-rs ,enable=0 and rs =0

Wire.beginTransmission(_LCDSlaveAddresI2C);
Wire.write(cmdI2C, 4) ;
TransmissionCode = Wire.endTransmission();
wire->beginTransmission(_LCDSlaveAddresI2C);
wire->write(cmdI2C, 4) ;
TransmissionCode = wire->endTransmission();
if (TransmissionCode!= 0)
{
#ifdef LCD_SERIAL_DEBUG
Expand Down Expand Up @@ -283,10 +285,11 @@ void HD44780LCD::PCF8574_LCDBackLightSet(bool OnOff)
bool HD44780LCD::PCF8574_LCD_I2C_ON()
{
uint8_t TransmissionCode = 0;
Wire.begin();
Wire.setClock(100000UL);
Wire.beginTransmission(_LCDSlaveAddresI2C);
TransmissionCode = Wire.endTransmission();

wire->begin();
//Wire.setClock(100000UL); // V 1.2.0
wire->beginTransmission(_LCDSlaveAddresI2C);
TransmissionCode = wire->endTransmission();
if (TransmissionCode!= 0)
{
#ifdef LCD_SERIAL_DEBUG
Expand Down
7 changes: 4 additions & 3 deletions src/HD44780_LCD_PCF8574.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#endif

#include "Wire.h"



#ifndef LCD_HD44780_H
#define LCD_HD44780_H

Expand Down Expand Up @@ -92,7 +93,7 @@ typedef enum {

class HD44780LCD : public Print{
public:
HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress);
HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress, TwoWire *twi = &Wire);
~HD44780LCD(){};

void PCF8574_LCDInit (LCDCursorType_e);
Expand Down Expand Up @@ -130,7 +131,7 @@ class HD44780LCD : public Print{
uint8_t _LCDSlaveAddresI2C = 0x27 ;
uint8_t _NumRowsLCD = 2;
uint8_t _NumColsLCD = 16;
TwoWire *wire;
}; // end of HD44780LCD class

#endif // guard header ending

0 comments on commit 231533c

Please sign in to comment.