Skip to content

Commit

Permalink
0.1.4 I2C_LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Dec 30, 2023
1 parent 06dede8 commit 41cc694
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 58 deletions.
12 changes: 10 additions & 2 deletions libraries/I2C_LCD/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.4] - 2023-12-28
- changed return type of **begin()**. Returns false if LCD not found on I2C bus.
- made initialization delay(100) in **begin()** a bit smarter.
- add **repeat(c, times)**
- fix **center()** for non 20x4 LCD.
- add **I2C_LCD_custom_chars.h** with examples.
- add examples


## [0.1.3] - 2023-12-22
- add support for **16x4** + **10x4** display
- add support for **16x4** and **10x4** display.
- minimized footprint **setCursor()**
- add parameter to **moveCursorLeft(uint8_t n = 1)**
- add parameter to **moveCursorRight(uint8_t n = 1)**
- improve timing
- update examples
- minor edits


## [0.1.2] - 2023-12-21
- implement polarity backlight (and removed policy)
- add **size_t center(uint8_t row, const char \* message)**
Expand Down
27 changes: 21 additions & 6 deletions libraries/I2C_LCD/I2C_LCD.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: I2C_LCD.cpp
// AUTHOR: [email protected]
// VERSION: 0.1.3
// VERSION: 0.1.4
// DATE: 2023-12-16
// PUPROSE: Arduino library for I2C_LCD
// URL: https://github.com/RobTillaart/I2C_LCD
Expand Down Expand Up @@ -71,19 +71,22 @@ void I2C_LCD::config (uint8_t address, uint8_t enable, uint8_t readWrite, uint8_
}


void I2C_LCD::begin(uint8_t cols, uint8_t rows)
bool I2C_LCD::begin(uint8_t cols, uint8_t rows)
{
_cols = cols;
_rows = rows;

if (isConnected() == false) return false;

// ALL LINES LOW.
_wire->beginTransmission(_address);
_wire->write(0x00);
_wire->endTransmission();

// Figure 24 for procedure on 4-bit initialization
// wait for more than 15 ms
delay(100); // no need to optimize as this is called only once.
// if other objects initialize earlier there will be less blocking time.
while (millis() < 100) delay(1);

// Force 4 bit mode
write4bits(0x03);
Expand All @@ -102,6 +105,7 @@ void I2C_LCD::begin(uint8_t cols, uint8_t rows)
// default enable display
display();
clear();
return true;
}


Expand All @@ -118,7 +122,7 @@ bool I2C_LCD::isConnected()
//
void I2C_LCD::setBacklightPin(uint8_t pin, uint8_t polarity)
{
_backLightPin = ( 1 << pin);
_backLightPin = (1 << pin);
_backLightPol = polarity;
}

Expand Down Expand Up @@ -163,7 +167,7 @@ void I2C_LCD::clear()

void I2C_LCD::clearEOL()
{
for (int i = _pos; i < _cols; i++)
while(_pos < _cols)
{
print(' ');
}
Expand Down Expand Up @@ -346,7 +350,7 @@ size_t I2C_LCD::write(uint8_t c)
size_t I2C_LCD::center(uint8_t row, const char * message)
{
uint8_t len = strlen(message) + 1;
setCursor(10 - len/2, row);
setCursor((_cols - len) / 2, row);
return print(message);
}

Expand All @@ -359,6 +363,17 @@ size_t I2C_LCD::right(uint8_t col, uint8_t row, const char * message)
}


size_t I2C_LCD::repeat(uint8_t c, uint8_t times)
{
size_t n = 0;
while((times--) && (_pos < _cols))
{
n += write(c);
}
return n;
}


//////////////////////////////////////////////////////////
//
// PRIVATE
Expand Down
19 changes: 8 additions & 11 deletions libraries/I2C_LCD/I2C_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
//
// FILE: I2C_LCD.h
// AUTHOR: [email protected]
// VERSION: 0.1.3
// VERSION: 0.1.4
// DATE: 2023-12-16
// PUPROSE: Arduino library for I2C_LCD
// URL: https://github.com/RobTillaart/I2C_LCD


#define I2C_LCD_LIB_VERSION (F("0.1.3"))
#define I2C_LCD_LIB_VERSION (F("0.1.4"))

#include "Arduino.h"
#include "Wire.h"

#ifndef POSITIVE
#define POSITIVE 1
#endif

#ifndef NEGATIVE
#define NEGATIVE 0
#endif
const uint8_t POSITIVE = 1;
const uint8_t NEGATIVE = 0;


class I2C_LCD : public Print
Expand All @@ -34,8 +29,8 @@ class I2C_LCD : public Print
uint8_t backLight, uint8_t polarity);

// only supports 5x8 char set for now.
// blocks 100+ millisec to give device chance to reset
void begin(uint8_t cols = 20, uint8_t rows = 4);
// blocks up to 100 milliseconds to give LCD time to boot
bool begin(uint8_t cols = 20, uint8_t rows = 4);
bool isConnected();


Expand Down Expand Up @@ -86,6 +81,8 @@ class I2C_LCD : public Print
size_t write(uint8_t c);
size_t center(uint8_t row, const char * message);
size_t right(uint8_t col, uint8_t row, const char * message);
size_t repeat(uint8_t c, uint8_t times);


// DEBUG development
uint8_t getColumn() { return _pos; }; // works.
Expand Down
217 changes: 217 additions & 0 deletions libraries/I2C_LCD/I2C_LCD_custom_chars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#pragma once
//
// FILE: I2C_LCD_custom_chars.h
// AUTHOR: [email protected]
// VERSION: see library.properties
// PUPROSE: Arduino library for I2C_LCD
// URL: https://github.com/RobTillaart/I2C_LCD
// https://maxpromer.github.io/LCD-Character-Creator/
//
// See examples for some more


////////////////////////////////////
//
// Special
//

// one-liners easier to search?
// uint8_t paragraph[] = { 0x06, 0x09, 0x04, 0x10, 0x04, 0x12, 0x0E, 0x00 };

uint8_t paragraph[] = {
B00110,
B01001,
B00100,
B01010,
B00100,
B10010,
B01110,
B00000
};

uint8_t copyRight[] = {
B00000,
B11111,
B10001,
B10111,
B10111,
B10001,
B11111,
B00000
};


////////////////////////////////////
//
// Math
//
uint8_t lessThan[] = {
B00000,
B00010,
B00100,
B01000,
B00100,
B00010,
B00000,
B11111
};

uint8_t moreThan[] = {
B00000,
B01000,
B00100,
B00010,
B00100,
B01000,
B00000,
B11111
};

uint8_t notEqual[] = {
B00000,
B00010,
B00010,
B11111,
B00100,
B11111,
B01000,
B01000
};

////////////////////////////////////
//
// ARROWS
//
uint8_t doubleUP[] = {
B00100,
B01110,
B11111,
B00000,
B00100,
B01110,
B11111,
B00000
};

uint8_t doubleDOWN[] = {
B11111,
B01110,
B00100,
B00000,
B11111,
B01110,
B00100,
B00000
};

uint8_t openUP[] = {
B00000,
B00100,
B01010,
B01010,
B10001,
B10001,
B11111,
B00000
};

uint8_t openDown[] = {
B00000,
B11111,
B10001,
B10001,
B01010,
B01010,
B00100,
B00000
};

////////////////////////////////////
//
// BRACKETS --[]--
//
uint8_t bracketRight[] = {
B11100,
B00100,
B00100,
B00111,
B00100,
B00100,
B11100,
B00000
};

uint8_t bracketLeft[] = {
B00111,
B00100,
B00100,
B11100,
B00100,
B00100,
B00111,
B00000
};

uint8_t singleLine[] = {
B00000,
B00000,
B00000,
B11111,
B00000,
B00000,
B00000,
B00000
};

uint8_t doubleLine[] = {
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B00000
};


////////////////////////////////////
//
// Other
//
uint8_t OnOff[] = {
B00100,
B00100,
B01110,
B10101,
B10101,
B10001,
B01110,
B00000
};

uint8_t smiley[] = {
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000
};

uint8_t heart[] = {
B00000,
B01010,
B10101,
B10001,
B01010,
B00100,
B00000,
B00000
};


// -- END OF FILE --

6 changes: 5 additions & 1 deletion libraries/I2C_LCD/I2C_LCD_special_chars.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
// URL: https://github.com/RobTillaart/I2C_LCD


// SPECIAL CHARS, might not work on all displays.
// SPECIAL CHARS,
// will only work on displays with ROM CODE A00
//

const char LCD_ALPHA = 0xE0;
const char LCD_BETA = 0xE2;
const char LCD_EPSILON = 0xE3;
const char LCD_MU = 0xE4;
const char LCD_RHO = 0xE5;
const char LCD_SQROOT = 0xE7;

const char LCD_THETA = 0xF2;
const char LCD_INFINITY = 0xF3;
const char LCD_OHM = 0xF4;
Expand Down
Loading

0 comments on commit 41cc694

Please sign in to comment.