Skip to content

Commit

Permalink
Merge pull request #12 from hasenradball/develop
Browse files Browse the repository at this point in the history
provide new wire interface
  • Loading branch information
hasenradball authored Sep 5, 2024
2 parents 32cfb67 + 5b50705 commit 16f34ba
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 65 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ only a current source to VCC is active.
A detailed description of the PCF8574 you will find in the [pcf8574.pdf](./docs/pcf8574.pdf).

## Library Usage
Possibly make a weather station.

![Weather](./docs/LCD_Temp_Hum.JPG)

# License
This library is licensed under MIT Licence.
Expand Down
Binary file added docs/LCD_Temp_Hum.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions examples/Custom_Chars/Custom_Chars.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <LCD-I2C.h>
#include <Wire.h>

// Default address of most PCF8574 modules, change according

Expand Down Expand Up @@ -62,20 +63,20 @@ uint8_t snow[8] =
};

void setup() {
lcd.begin();
lcd.display();
lcd.backlight();
Wire.begin();
lcd.begin(&Wire);
lcd.display();
lcd.backlight();

lcd.createChar(0, happy);
lcd.createChar(1, wow);
lcd.createChar(2, anchor);
lcd.createChar(3, snow);
lcd.createChar(0, happy);
lcd.createChar(1, wow);
lcd.createChar(2, anchor);
lcd.createChar(3, snow);


lcd.write(0);
lcd.write(1);
lcd.write(2);
lcd.write(3);
lcd.write(0);
lcd.write(1);
lcd.write(2);
lcd.write(3);
}

void loop() {
Expand Down
8 changes: 5 additions & 3 deletions examples/Functions/Functions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <LCD-I2C.h>
#include <Wire.h>

// Default address of most PCF8574 modules, change according

Expand All @@ -22,9 +23,10 @@ LCD_I2C lcd(0x27, 16, 2);
*/

void setup() {
lcd.begin();
lcd.display();
lcd.backlight();
Wire.begin();
lcd.begin(&Wire);
lcd.display();
lcd.backlight();
}

void loop()
Expand Down
5 changes: 3 additions & 2 deletions examples/Hello_World/Hello_World.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/

#include <LCD-I2C.h>

#include <Wire.h>

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according

void setup() {
// If you are using more I2C devices using the Wire library use lcd.begin(false)
// this stop the library(LCD-I2C) from calling Wire.begin()
lcd.begin();
Wire.begin();
lcd.begin(&Wire);
lcd.display();
lcd.backlight();
}
Expand Down
5 changes: 3 additions & 2 deletions examples/write_character_codes/write_character_codes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/

#include <LCD-I2C.h>

#include <Wire.h>

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according

void setup() {
// If you are using more I2C devices using the Wire library use lcd.begin(false)
// this stop the library(LCD-I2C) from calling Wire.begin()
lcd.begin();
Wire.begin();
lcd.begin(&Wire);
lcd.display();
lcd.backlight();
}
Expand Down
40 changes: 20 additions & 20 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ setCursor KEYWORD2
HD44780_CLEAR_DISPLAY LITERAL1
HD44780_CURSOR_HOME LITERAL1
HD44780_ENTRY_MODE_SET LITERAL1
HD44780_ACCOMPANIES_DISPLAY_SHIFT LITERAL1
HD44780_ENTRY_SHIFTINCREMENT LITERAL1
HD44780_ENTRY_SHIFTDECREMENT LITERAL1
HD44780_DISPLAY_CONTROL LITERAL1
HD44780_BLINK_ON LITERAL1
HD44780_CURSOR_ON LITERAL1
HD44780_DISPLAY_ON LITERAL1
HD44780_CURSOR_OR_DISPLAY_SHIFT LITERAL1
HD44780_SHIFT_RIGHT LITERAL1
HD44780_DISPLAY_SHIFT LITERAL1
HD44780_CURSOR_MOVE LITERAL1
HD44780_FUNCTION_SET LITERAL1
HD44780_5x10_DOTS LITERAL1
HD44780_5x8_DOTS LITERAL1
HD44780_2_LINE LITERAL1
HD44780_1_LINE LITERAL1
HD44780_8_BIT_MODE LITERAL1
HD44780_4_BIT_MODE LITERAL1
HD44780_SET_CGRAM_ADDR LITERAL1
HD44780_SET_DDRRAM_ADDR LITERAL1
HD44780_ACCOMPANIES_DISPLAY_SHIFT LITERAL1
HD44780_ENTRY_SHIFTINCREMENT LITERAL1
HD44780_ENTRY_SHIFTDECREMENT LITERAL1
HD44780_DISPLAY_CONTROL LITERAL1
HD44780_BLINK_ON LITERAL1
HD44780_CURSOR_ON LITERAL1
HD44780_DISPLAY_ON LITERAL1
HD44780_CURSOR_OR_DISPLAY_SHIFT LITERAL1
HD44780_SHIFT_RIGHT LITERAL1
HD44780_DISPLAY_SHIFT LITERAL1
HD44780_CURSOR_MOVE LITERAL1
HD44780_FUNCTION_SET LITERAL1
HD44780_5x10_DOTS LITERAL1
HD44780_5x8_DOTS LITERAL1
HD44780_2_LINE LITERAL1
HD44780_1_LINE LITERAL1
HD44780_8_BIT_MODE LITERAL1
HD44780_4_BIT_MODE LITERAL1
HD44780_SET_CGRAM_ADDR LITERAL1
HD44780_SET_DDRRAM_ADDR LITERAL1
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LCD-I2C",
"version": "0.3.0",
"version": "1.0.0",
"repository":
{
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=LCD-I2C
version=0.3.0
version=1.0.0
author=Frank Häfele <[email protected]>
maintainer=Frank Häfele <[email protected]>
sentence=C++ Library for Liquid Crystal Displays (LCD) with the Hitachi HD44780 display driver.
Expand Down
25 changes: 12 additions & 13 deletions src/LCD-I2C.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "LCD-I2C.h"
#include "Wire.h"
#include <LCD_Constants.h>

/**
* @brief function begin
*
* @param beginWire if true start I²C wire
*/
void LCD_I2C::begin(bool beginWire) {
if (beginWire)
Wire.begin();

// Clear i2c adapter
I2C_Write(0b00000000);
// Wait more than 40 ms after powerOn
delay(50);
InitializeLCD();
void LCD_I2C::begin(TwoWire *wire) {
_wire = wire;

// Clear i2c adapter
I2C_Write(0b00000000);
// Wait more than 40 ms after powerOn
delay(50);
InitializeLCD();
}

/**
Expand Down Expand Up @@ -370,9 +369,9 @@ void LCD_I2C::writeCharCode(uint8_t code) {
* @param output data to write
*/
void LCD_I2C::I2C_Write(uint8_t output) {
Wire.beginTransmission(_address);
Wire.write(output);
Wire.endTransmission();
_wire->beginTransmission(_address);
_wire->write(output);
_wire->endTransmission();
}

/**
Expand Down
23 changes: 12 additions & 11 deletions src/LCD-I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _LCD_I2C_H_

#include "Arduino.h"
#include <LCD_Constants.h>
#include "Wire.h"

/*
This struct helps us constructing the I2C output based on data and control outputs.
Expand Down Expand Up @@ -46,7 +46,7 @@ class LCD_I2C : public Print {
LCD_I2C(uint8_t address, uint8_t columns = 16, uint8_t rows = 2)
: _address(address), _columnMax(--columns), _rowMax(--rows) {}

void begin(bool beginWire = true);
void begin(TwoWire *wire);
void backlight();
void backlightOff();

Expand All @@ -72,16 +72,17 @@ class LCD_I2C : public Print {


private:
uint8_t _address;
uint8_t _columnMax;
uint8_t _rowMax;
OutputState _output;
uint8_t _displayState = 0x00;
uint8_t _entryState = 0x00;
TwoWire *_wire{nullptr};
uint8_t _address;
uint8_t _columnMax;
uint8_t _rowMax;
OutputState _output;
uint8_t _displayState = 0x00;
uint8_t _entryState = 0x00;

void InitializeLCD();
void I2C_Write(uint8_t output);
void LCD_Write(uint8_t output, bool initialization = false);
void InitializeLCD();
void I2C_Write(uint8_t output);
void LCD_Write(uint8_t output, bool initialization = false);
};

#endif

0 comments on commit 16f34ba

Please sign in to comment.