Skip to content

Commit 231533c

Browse files
Version 1.2.0
1 parent b90489a commit 231533c

File tree

10 files changed

+94
-48
lines changed

10 files changed

+94
-48
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)
2+
13

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

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

2629
* Author: Gavin Lyons
2730

@@ -50,12 +53,13 @@ Tested
5053

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

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

6064
Ports
6165
------------------------

examples/HelloWorld/HelloWorld.ino

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,30 @@
55
* URL: https://github.com/gavinlyonsrepo/HD44780_LCD_PCF8574
66
*/
77

8-
// Section: Included library
8+
// Section: Included library
99
#include "HD44780_LCD_PCF8574.h"
1010

11+
// Section: Defines
12+
#define DISPLAY_DELAY_INIT 50 // mS
13+
// **** NOTE :: Comment in If using STM32 bluepill ****
14+
//#define STM32_BLUE_PILL_SETUP
15+
16+
1117
// Section: Globals
18+
#ifdef STM32_BLUE_PILL_SETUP // *** STM32 Blue Pill ***
19+
// Set-up Choice I2C interface 1 or 2 :: pick one and one only
20+
TwoWire Wire2(1,I2C_FAST_MODE); // Use STM32 I2C1
21+
//TwoWire Wire2(2,I2C_FAST_MODE); // Use STM32 I2C2
22+
HD44780LCD myLCD(2, 16, 0x27, &Wire2); // LCD object.rows ,cols ,PCF8574 I2C addr, Interface)
23+
#else
1224
// myLCD(rows , cols , PCF8574 I2C address)
13-
HD44780LCD myLCD( 2, 16, 0x27); // instantiate a LCD object
25+
HD44780LCD myLCD( 2, 16, 0x27); // instantiate an object
26+
#endif
1427

1528
// Section: Setup
1629

17-
void setup()
18-
{
19-
delay(50);
30+
void setup() {
31+
delay(DISPLAY_DELAY_INIT);
2032
myLCD.PCF8574_LCDInit(LCDCursorTypeOn);
2133
myLCD.PCF8574_LCDClearScreen();
2234
myLCD.PCF8574_LCDBackLightSet(true);
@@ -25,13 +37,11 @@ void setup()
2537

2638
// Section: Main Loop
2739

28-
void loop()
29-
{
40+
void loop() {
3041
char testString[] = "Hello World";
3142
myLCD.PCF8574_LCDSendString(testString);
32-
myLCD.PCF8574_LCDSendChar('!'); // Display a single character
33-
while(true){};
34-
35-
}
43+
myLCD.PCF8574_LCDSendChar('!'); // Display a single character
44+
while (true) {};
45+
}
3646

3747
// EOF

examples/TestRun/TestRun.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@
2020
#define DISPLAY_DELAY_1 1000
2121
#define DISPLAY_DELAY_2 2000
2222
#define DISPLAY_DELAY 5000
23+
// **** NOTE :: Comment in If using STM32 bluepill ****
24+
//#define STM32_BLUE_PILL_SETUP
2325

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

2837
// Section: Function Prototypes
2938

examples/TestRun20X04/TestRun20X04.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@
2020
#define DISPLAY_DELAY_1 1000
2121
#define DISPLAY_DELAY_2 2000
2222
#define DISPLAY_DELAY 5000
23+
// **** NOTE :: Comment in If using STM32 bluepill ****
24+
//#define STM32_BLUE_PILL_SETUP
2325

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

2837
// Section: Function Prototypes
2938

extras/doc/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
* version 1.1.0 April 2022
66
* Tested on 20x04 for first time and github issue 1 closed off.
77
* Example file added for 20x04
8-
8+
* version 1.2.0 September 2022
9+
* Option added for User to pick I2C port for STM32 bluepill, github issue 2.

extras/doc/GPIO_MCU_used.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
GPIO used in testing for I2C
2+
--------------------------------------
3+
4+
UNO/NANO I2C
5+
6+
1. A4 SDA
7+
2. A5 SCLK
8+
9+
ESP8266 HARDWARE I2C
10+
11+
3. D1 GPIO5 20 SCK
12+
4. D2 GPIO4 19 SDA
13+
14+
ESP32 HARDWARE I2C
15+
16+
5. D22 GPIO22 SCK
17+
6. D21 GPIO21 SDA
18+
19+
STM32 STM32F103C8T6 "blue pill" I2C
20+
21+
| Pin Name | Pin | Arduino Pin | PCB Label | Func | I2C Channel |
22+
| -- | -- | -- | -- | -- | -- |
23+
| PB6 | 42 | 22 | B6 | SCK | I2C1 |
24+
| PB7 | 43 | 23 | B7 | SDA | I2C1 |
25+
| PB10 | 21 | 26 | B10 | SCK | I2C2 |
26+
| PB11 | 22 | 27 | B11 | SDA | I2C2 |
27+
28+

extras/doc/GPIO_MCU_used.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=HD44780_LCD_PCF8574
2-
version=1.1.0
2+
version=1.2.0
33
author=Gavin Lyons <[email protected]>
44
maintainer=Gavin Lyons <[email protected]>
55
sentence=Library to Support the HD44780 LCD I2C driven by the PCF8574 controller

src/HD44780_LCD_PCF8574.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
// Section : constructor
66

7-
HD44780LCD :: HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress)
7+
HD44780LCD :: HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress,TwoWire *twi)
88
{
99
_NumRowsLCD = NumRow;
1010
_NumColsLCD = NumCol;
1111
_LCDSlaveAddresI2C = I2Caddress;
12+
wire = twi;
1213
}
1314

15+
1416
// Section : Functions
1517

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

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

61-
Wire.beginTransmission(_LCDSlaveAddresI2C);
62-
Wire.write(cmdI2C, 4) ;
63-
TransmissionCode = Wire.endTransmission();
63+
wire->beginTransmission(_LCDSlaveAddresI2C);
64+
wire->write(cmdI2C, 4) ;
65+
TransmissionCode = wire->endTransmission();
6466
if (TransmissionCode!= 0)
6567
{
6668
#ifdef LCD_SERIAL_DEBUG
@@ -283,10 +285,11 @@ void HD44780LCD::PCF8574_LCDBackLightSet(bool OnOff)
283285
bool HD44780LCD::PCF8574_LCD_I2C_ON()
284286
{
285287
uint8_t TransmissionCode = 0;
286-
Wire.begin();
287-
Wire.setClock(100000UL);
288-
Wire.beginTransmission(_LCDSlaveAddresI2C);
289-
TransmissionCode = Wire.endTransmission();
288+
289+
wire->begin();
290+
//Wire.setClock(100000UL); // V 1.2.0
291+
wire->beginTransmission(_LCDSlaveAddresI2C);
292+
TransmissionCode = wire->endTransmission();
290293
if (TransmissionCode!= 0)
291294
{
292295
#ifdef LCD_SERIAL_DEBUG

src/HD44780_LCD_PCF8574.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#endif
1717

1818
#include "Wire.h"
19-
19+
20+
2021
#ifndef LCD_HD44780_H
2122
#define LCD_HD44780_H
2223

@@ -92,7 +93,7 @@ typedef enum {
9293

9394
class HD44780LCD : public Print{
9495
public:
95-
HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress);
96+
HD44780LCD(uint8_t NumRow, uint8_t NumCol, uint8_t I2Caddress, TwoWire *twi = &Wire);
9697
~HD44780LCD(){};
9798

9899
void PCF8574_LCDInit (LCDCursorType_e);
@@ -130,7 +131,7 @@ class HD44780LCD : public Print{
130131
uint8_t _LCDSlaveAddresI2C = 0x27 ;
131132
uint8_t _NumRowsLCD = 2;
132133
uint8_t _NumColsLCD = 16;
133-
134+
TwoWire *wire;
134135
}; // end of HD44780LCD class
135136

136137
#endif // guard header ending

0 commit comments

Comments
 (0)