Fast LCD I2C driver 1.0
Fast driver for LCDs on I2C for Pi-Pico and Arduino
The C language interface

Detailed Description

On the Pi Pico, if you prefer to work in C a reasonably complete subset of the program interface is available here with almost all of the functionality of the C++ version. The advanced buffering commands are not available. Even without them, substantial speed improvements are still achieved. (But C++ is still recommended.)

Initialization

Set up the lcd display. The I2C pins are not initialized. See LCD_I2C_Setup().

void lcd_init (byte address, byte columns, byte rows, i2c_inst_t *I2C)
 Initialize the lcd display. More...
 

Writing to the screen on the Pi Pico in C

These are the simplist output routines for writing characters to the LCD screen. They are in the spirit of the example in the Pi Pico SDK.

Also see the Theory of Operation for hints on maximizing display speed.

void lcd_writeChar (byte val)
 Output a character to the screen. More...
 
void lcd_writeString (const char str[])
 Output a string to the screen. Naming is more in the style of the Pico SDK, and the Enable_Buffering parameter can be utilized. More...
 
void lcd_writeBuffer (const uint8_t *buffer, size_t size)
 Write array of bytes. More...
 

Simple display control

void lcd_setCursor (byte line, byte position)
 Move the input cursor to a location on the screen. More...
 
void lcd_clear (void)
 Clear the display. More...
 
void lcd_home (void)
 "Home" the display. More...
 
void lcd_backlight (void)
 Turn on the display backlight. More...
 
void lcd_noBacklight (void)
 Turn off the display backlight
More...
 
void lcd_display (void)
 Turns the display on without modifying data on it. More...
 
void lcd_noDisplay (void)
 Turns the display off without modifying data on it. More...
 

Cursor Appearance Controls

The cursor can be displayed on the screen as an underscore at the current location, or as a blinking inversion of the character at the cursor location. Both of these modes can be enabled at once, or they can both be turned off, making the cursor invisible!

void lcd_cursor (void)
 Display the underline cursor at the current cursor location. More...
 
void lcd_noCursor (void)
 Hides the underline cursor at the current cursor location. More...
 
void lcd_blink (void)
 Display the blinking inverted cursor at the current cursor location. More...
 
void lcd_noBlink (void)
 Disable the blinking inverted cursor at the current cursor location. More...
 

Advanced Display Control

void lcd_scrollDisplayLeft (void)
 Scrolls the display and cursor one position to the left. home() will restore it to its original position. More...
 
void lcd_scrollDisplayRight (void)
 Scrolls the display and cursor one position to the right. home() will restore it to its original position. More...
 
void lcd_autoscroll (void)
 Turns on automatic scrolling of the display. More...
 
void lcd_noAutoscroll (void)
 Turns off automatic scrolling of the display. More...
 
void lcd_leftToRight (void)
 Sets the text direction to left to right. Each character output advances the cursor one position to the right. This is the default condition. More...
 
void lcd_rightToLeft (void)
 Sets the text direction to right to left. Each character output advances the cursor one position to the left. More...
 

Custom Characters

The display can store 8 user defined custom characters. They are stored at "memory addresses" 0-7. They are displayed when character codes 0-7 are written to the display. Of course, character value "0" cannot be included in a string because it would be the string terminator. A 0 can be written using the write single character routines, or the write() method with an array of characters and a character count. As an alternative, the display controller also duplicates the special characters as character codes 8-15 (0x8-0xf), which can be encoded and written as strings.

void lcd_createChar (byte charnum, const byte char_map[])
 Create a custom character. More...
 

Function Documentation

◆ lcd_autoscroll()

void lcd_autoscroll ( void  )
noexcept

Turns on automatic scrolling of the display.

◆ lcd_backlight()

void lcd_backlight ( void  )
noexcept

Turn on the display backlight.

◆ lcd_blink()

void lcd_blink ( void  )
noexcept

Display the blinking inverted cursor at the current cursor location.

◆ lcd_clear()

void lcd_clear ( void  )
noexcept

Clear the display.

◆ lcd_createChar()

void lcd_createChar ( byte  charnum,
const byte  char_map[] 
)
noexcept

Create a custom character.

Load a custom character into the display by specifying the location in memory to be stored (8 locations maximum, starting from 0) and an array of 8 bytes. The bytes contain a bit map of the 5x7 dot matrix to display. Each byte specifies one row of character dots starting with the top-most row. The lsb of each byte is the right-most dot on its corresponding line of the character.

Parameters
charnumThe memory address (character code) 0-7
char_mapThe byte array

◆ lcd_cursor()

void lcd_cursor ( void  )
noexcept

Display the underline cursor at the current cursor location.

◆ lcd_display()

void lcd_display ( void  )
noexcept

Turns the display on without modifying data on it.

The display is unblanked, and all data sent to the display is displayed.

◆ lcd_home()

void lcd_home ( void  )
noexcept

"Home" the display.

Moves cursor to 0,0 and removes any shifts.

◆ lcd_init()

void lcd_init ( byte  address,
byte  columns,
byte  rows,
i2c_inst_t *  I2C 
)

Initialize the lcd display.

Parameters
addressThe I2C address
columnsThe LCD's number of columns
rowsThe LCD's number of rows (lines)
I2CThe I2C instance
Note
If called more than once, the existing LCD class object will be
discarded (and destroyed), and a new one created and initialized with the given
parameters. Use with care!
Warning
The Pi Pico pins and the I2C bus are not initialized! (But see See LCD_I2C_Setup().)

◆ lcd_leftToRight()

void lcd_leftToRight ( void  )
noexcept

Sets the text direction to left to right. Each character output advances the cursor one position to the right. This is the default condition.

◆ lcd_noAutoscroll()

void lcd_noAutoscroll ( void  )
noexcept

Turns off automatic scrolling of the display.

◆ lcd_noBacklight()

void lcd_noBacklight ( void  )
noexcept

Turn off the display backlight

◆ lcd_noBlink()

void lcd_noBlink ( void  )
noexcept

Disable the blinking inverted cursor at the current cursor location.

◆ lcd_noCursor()

void lcd_noCursor ( void  )
noexcept

Hides the underline cursor at the current cursor location.

◆ lcd_noDisplay()

void lcd_noDisplay ( void  )
noexcept

Turns the display off without modifying data on it.

The display is blanked as though it had been cleared, but the data and cursor position are not changed.

◆ lcd_rightToLeft()

void lcd_rightToLeft ( void  )
noexcept

Sets the text direction to right to left. Each character output advances the cursor one position to the left.

◆ lcd_scrollDisplayLeft()

void lcd_scrollDisplayLeft ( void  )
noexcept

Scrolls the display and cursor one position to the left. home() will restore it to its original position.

◆ lcd_scrollDisplayRight()

void lcd_scrollDisplayRight ( void  )
noexcept

Scrolls the display and cursor one position to the right. home() will restore it to its original position.

◆ lcd_setCursor()

void lcd_setCursor ( byte  line,
byte  position 
)
noexcept

Move the input cursor to a location on the screen.

All output to the screen is placed at the current cursor position. In the default mode, the cursor then advances one position to the right. The cursor does not scroll to the next line.

Parameters
lineSpecifies the row (or line) on the display
positionSpecifies the position on the row (or column) on the display

◆ lcd_writeBuffer()

void lcd_writeBuffer ( const uint8_t *  buffer,
size_t  size 
)

Write array of bytes.

Parameters
bufferThe array of bytes to output
sizeThe number of bytes to write

◆ lcd_writeChar()

void lcd_writeChar ( byte  val)
noexcept

Output a character to the screen.

Parameters
valis the character to display

◆ lcd_writeString()

void lcd_writeString ( const char  str[])
noexcept

Output a string to the screen. Naming is more in the style of the Pico SDK, and the Enable_Buffering parameter can be utilized.

Parameters
stris pointer to the string to display