upm  1.0.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes
Lcm1602 Class Reference

API for the LCM1602 I2C controller for HD44780-based displays. More...

Detailed Description

This supports all sizes of HD44780 displays, from 16x2 to 4x20. The controller has no idea of the actual display hardware, so it lets you write farther than you can see. These displays with such controllers are available from various manufacturers with different I2C addresses. Adafruit* TC1602A-01T seems to be a well-documented example. The driver also supports parallel GPIO connections directly to the HD44780 in case you are not using an I2C expander/backpack.

lcm1602.jpeg

Example for LCM1602 displays that use the I2C bus

upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
lcd->setCursor(0,0);
lcd->write("Hello World");

Code sample for GPIO based LCM1602 displays

// LCD connection:
// LCD RS pin to digital pin 8
// LCD Enable pin to digital pin 13
// LCD D4 pin to digital pin 2
// LCD D5 pin to digital pin 3
// LCD D6 pin to digital pin 4
// LCD D7 pin to digital pin 5
// LCD R/W pin to ground
// 10K trimmer potentiometer:
// ends to +5V and ground
// wiper to LCD VO pin (pin 3)
upm::Lcm1602 *lcd = new upm::Lcm1602(8, 13, 2, 3, 4, 5, 20, 2);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->setCursor(1,2);
lcd->write("Hello World");
printf("Sleeping for 5 seconds\n");
sleep(5);
delete lcd;

Public Member Functions

 Lcm1602 (int bus=0, int address=0x27, bool isExpander=true, uint8_t numColumns=16, uint8_t numRows=2)
 
 Lcm1602 (uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t numColumns=16, uint8_t numRows=2)
 
 ~Lcm1602 ()
 
mraa::Result write (std::string msg)
 
mraa::Result setCursor (int row, int column)
 
mraa::Result clear ()
 
mraa::Result home ()
 
mraa::Result createChar (uint8_t charSlot, uint8_t charData[])
 
mraa::Result displayOn ()
 
mraa::Result displayOff ()
 
mraa::Result cursorOn ()
 
mraa::Result cursorOff ()
 
mraa::Result cursorBlinkOn ()
 
mraa::Result cursorBlinkOff ()
 
mraa::Result backlightOn ()
 
mraa::Result backlightOff ()
 
mraa::Result scrollDisplayLeft ()
 
mraa::Result scrollDisplayRight ()
 
mraa::Result entryLeftToRight ()
 
mraa::Result entryRightToLeft ()
 
mraa::Result autoscrollOn ()
 
mraa::Result autoscrollOff ()
 
 Lcm1602 (int bus=0, int address=0x27, bool isExpander=true, uint8_t numColumns=16, uint8_t numRows=2)
 
 Lcm1602 (uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t numColumns=16, uint8_t numRows=2)
 
 ~Lcm1602 ()
 
upm_result_t write (std::string msg)
 
upm_result_t setCursor (int row, int column)
 
upm_result_t clear ()
 
upm_result_t home ()
 
upm_result_t createChar (uint8_t charSlot, lcm1602_custom_char_t charData)
 
upm_result_t displayOn ()
 
upm_result_t displayOff ()
 
upm_result_t cursorOn ()
 
upm_result_t cursorOff ()
 
upm_result_t cursorBlinkOn ()
 
upm_result_t cursorBlinkOff ()
 
upm_result_t backlightOn ()
 
upm_result_t backlightOff ()
 
upm_result_t scrollDisplayLeft ()
 
upm_result_t scrollDisplayRight ()
 
upm_result_t entryLeftToRight ()
 
upm_result_t entryRightToLeft ()
 
upm_result_t autoscrollOn ()
 
upm_result_t autoscrollOff ()
 
- Public Member Functions inherited from LCD
mraa::Result write (int x, int y, std::string msg)
 
std::string name ()
 

Protected Member Functions

mraa::Result send (uint8_t value, int mode)
 
mraa::Result write4bits (uint8_t value)
 
mraa::Result expandWrite (uint8_t value)
 
mraa::Result pulseEnable (uint8_t value)
 
virtual mraa::Result command (uint8_t cmd)
 
virtual mraa::Result data (uint8_t data)
 
upm_result_t command (uint8_t cmd)
 
upm_result_t data (uint8_t data)
 

Protected Attributes

uint8_t m_displayControl
 
uint8_t m_entryDisplayMode
 
uint8_t m_numColumns
 
uint8_t m_numRows
 
uint8_t m_backlight
 
int m_lcd_control_address
 
mraa::I2c * m_i2c_lcd_control
 
lcm1602_context m_lcm1602
 
- Protected Attributes inherited from LCD
std::string m_name
 

Constructor & Destructor Documentation

Lcm1602 ( int  bus = 0,
int  address = 0x27,
bool  isExpander = true,
uint8_t  numColumns = 16,
uint8_t  numRows = 2 
)

Lcm1602 constructor; calls libmraa initialisation functions

Parameters
busI2C bus to use. Default 0 (autodetect).
addressSlave address the LCD is registered on. Default 0x27
isExpanderTrue if we are dealing with an I2C expander, false otherwise. Default is true.
numColumnsNumber of columns the display has. Default 16.
numRowsNumber of rows the display has. Default 2.

Here is the call graph for this function:

Lcm1602 ( uint8_t  rs,
uint8_t  enable,
uint8_t  d0,
uint8_t  d1,
uint8_t  d2,
uint8_t  d3,
uint8_t  numColumns = 16,
uint8_t  numRows = 2 
)

Lcm1602 alternate constructor, used for GPIO based HD44780 controllers supporting RS, Enable, and 4 data pins in 4-bit mode.

Parameters
rsRegister select pin
enableEnable pin
d0Data 0 pin
d1Data 1 pin
d2Data 2 pin
d3Data 3 pin
numColumnsNumber of columns the display has. Default 16.
numRowsNumber of rows the display has. Default 2.

Here is the call graph for this function:

~Lcm1602 ( )

Lcm1602 destructor

Lcm1602 ( int  bus = 0,
int  address = 0x27,
bool  isExpander = true,
uint8_t  numColumns = 16,
uint8_t  numRows = 2 
)

Lcm1602 constructor; calls libmraa initialisation functions

Parameters
busI2C bus to use. Default 0 (autodetect).
addressSlave address the LCD is registered on. Default 0x27
isExpanderTrue if we are dealing with an I2C expander, false otherwise. Default is true.
numColumnsNumber of columns the display has. Default 16.
numRowsNumber of rows the display has. Default 2.
Lcm1602 ( uint8_t  rs,
uint8_t  enable,
uint8_t  d0,
uint8_t  d1,
uint8_t  d2,
uint8_t  d3,
uint8_t  numColumns = 16,
uint8_t  numRows = 2 
)

Lcm1602 alternate constructor, used for GPIO based HD44780 controllers supporting RS, Enable, and 4 data pins in 4-bit mode.

Parameters
rsRegister select pin
enableEnable pin
d0Data 0 pin
d1Data 1 pin
d2Data 2 pin
d3Data 3 pin
numColumnsNumber of columns the display has. Default 16.
numRowsNumber of rows the display has. Default 2.
~Lcm1602 ( )

Lcm1602 destructor

Member Function Documentation

upm_result_t write ( std::string  msg)
virtual

Writes a string to the LCD

Parameters
msgstd::string to write to the display; note: only ASCII characters are supported
Returns
Result of the operation

Implements LCD.

upm_result_t setCursor ( int  row,
int  column 
)
virtual

Sets the cursor to specified coordinates

Parameters
rowRow to set the cursor to
columnColumn to set the cursor to
Returns
Result of the operation

Implements LCD.

upm_result_t clear ( )
virtual

Clears the display of all characters

Returns
Result of the operation

Implements LCD.

Here is the caller graph for this function:

upm_result_t home ( )
virtual

Returns to the original coordinates (0,0)

Returns
Result of the operation

Implements LCD.

Here is the caller graph for this function:

mraa::Result createChar ( uint8_t  charSlot,
uint8_t  charData[] 
)

Create a custom character

Parameters
charSlotthe character slot to write, only 8 are available
charDataThe character data (8 bytes) making up the character
Returns
Result of operation
upm_result_t displayOn ( )

Turn the display on

Returns
Result of operation
upm_result_t displayOff ( )

Turn the display off

Returns
Result of operation
upm_result_t cursorOn ( )

Turn the cursor on

Returns
Result of operation
upm_result_t cursorOff ( )

Turn the cursor off

Returns
Result of operation
upm_result_t cursorBlinkOn ( )

Turn cursor blink on

Returns
Result of operation
upm_result_t cursorBlinkOff ( )

Turn cursor blink off

Returns
Result of operation
upm_result_t backlightOn ( )

Turn backlight on

Returns
Result of operation

Here is the caller graph for this function:

upm_result_t backlightOff ( )

Turn backlight off

Returns
Result of operation
upm_result_t scrollDisplayLeft ( )

Scroll the display left, without changing the character RAM

Returns
Result of operation
upm_result_t scrollDisplayRight ( )

Scroll the display right, without changing the character RAM

Returns
Result of operation
upm_result_t entryLeftToRight ( )

set the entry mode so that characters are added left to right

Returns
Result of operation
upm_result_t entryRightToLeft ( )

set the entry mode so that characters are added right to left

Returns
Result of operation
upm_result_t autoscrollOn ( )

Right justify text entered from the cursor

Returns
Result of operation
upm_result_t autoscrollOff ( )

Left justify text entered from the cursor

Returns
Result of operation
upm_result_t write ( std::string  msg)
virtual

Writes a string to the LCD

Parameters
msgstd::string to write to the display; note: only ASCII characters are supported
Returns
Result of the operation

Implements LCD.

upm_result_t setCursor ( int  row,
int  column 
)
virtual

Sets the cursor to specified coordinates

Parameters
rowRow to set the cursor to
columnColumn to set the cursor to
Returns
Result of the operation

Implements LCD.

upm_result_t clear ( )
virtual

Clears the display of all characters

Returns
Result of the operation

Implements LCD.

upm_result_t home ( )
virtual

Returns to the original coordinates (0,0)

Returns
Result of the operation

Implements LCD.

upm_result_t createChar ( uint8_t  charSlot,
lcm1602_custom_char_t  charData 
)

Create a custom character

Parameters
charSlotthe character slot to write, only 8 are available
charDataThe character data (8 bytes) making up the character
Returns
Result of operation

Here is the call graph for this function:

upm_result_t displayOn ( )

Turn the display on

Returns
Result of operation
upm_result_t displayOff ( )

Turn the display off

Returns
Result of operation
upm_result_t cursorOn ( )

Turn the cursor on

Returns
Result of operation
upm_result_t cursorOff ( )

Turn the cursor off

Returns
Result of operation
upm_result_t cursorBlinkOn ( )

Turn cursor blink on

Returns
Result of operation
upm_result_t cursorBlinkOff ( )

Turn cursor blink off

Returns
Result of operation
upm_result_t backlightOn ( )

Turn backlight on

Returns
Result of operation
upm_result_t backlightOff ( )

Turn backlight off

Returns
Result of operation
upm_result_t scrollDisplayLeft ( )

Scroll the display left, without changing the character RAM

Returns
Result of operation
upm_result_t scrollDisplayRight ( )

Scroll the display right, without changing the character RAM

Returns
Result of operation
upm_result_t entryLeftToRight ( )

set the entry mode so that characters are added left to right

Returns
Result of operation
upm_result_t entryRightToLeft ( )

set the entry mode so that characters are added right to left

Returns
Result of operation
upm_result_t autoscrollOn ( )

Right justify text entered from the cursor

Returns
Result of operation
upm_result_t autoscrollOff ( )

Left justify text entered from the cursor

Returns
Result of operation
Inheritance diagram for Lcm1602:
Inheritance graph
[legend]
Collaboration diagram for Lcm1602:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: