Characteristic Locus
Inheritance System.Object > SerialLCD
Namespace Meadow.Foundation.Displays
Assembly SerialLCD.dll

Syntax

public class SerialLCD : ITextDisplay

Remarks

Serial LCD backpacks provide a convenient way to display data on a 16x2 or 20x4 LCD display.

Purchasing

This driver supports the Sparkfun Serial Backpack. This can also be purchased as a kit with both the serial backpack and the LCD.

Examples

The application below outputs Hello, world on the LCD:

using System.Threading;
using Meadow;
using Meadow.Foundation.Displays;

namespace SerialLCD_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            var display = new SerialLCD();
            //
            //  Clear the display ready for the test.
            //
            display.Clear();
            display.SetCursorStyle(SerialLCD.CursorStyle.BlinkingBoxOff);
            display.SetCursorStyle(SerialLCD.CursorStyle.UnderlineOff);
            //
            //  Display some text on the bottom row of a 16x2 LCD.
            //
            display.SetCursorPosition(2, 1);
            display.DisplayText("Hello, world");
        }
    }
}
Example Circuit

The Serial LCD requires only three connections; power, ground and serial data. The Tx pin on Meadow should be connected to the Rx pin on the serial backpack:

Constructors

View Source

SerialLCD(IIODevice, SerialPortName, TextDisplayConfig, Int32, Parity, Int32, StopBits)

Create a new SerialLCD object.

Declaration
public SerialLCD(IIODevice device, SerialPortName port, TextDisplayConfig config = null, int baudRate = 9600, Parity parity = null, int dataBits = 8, StopBits stopBits = null)

Parameters

Type Name Description
IIODevice device
SerialPortName port
TextDisplayConfig config

TextDisplayConfig object defining the LCD dimension (null will default to 16x2).

System.Int32 baudRate

Baud rate to use (default = 9600).

Parity parity

Parity to use (default is None).

System.Int32 dataBits

Number of data bits (default is 8 data bits).

StopBits stopBits

Number of stop bits (default is one stop bit).

Fields

View Source

_lock

object for using lock() to do thread synch

Declaration
protected object _lock

Field Value

Type Description
System.Object

Properties

View Source

DisplayConfig

Display configuration (width and height).

Declaration
public TextDisplayConfig DisplayConfig { get; }

Property Value

Type Description
TextDisplayConfig

Methods

View Source

Clear()

Clear the display.

Declaration
public void Clear()
View Source

ClearLine(Byte)

Clears the specified line by writing a string of empty characters to it.

Declaration
public void ClearLine(byte lineNumber)

Parameters

Type Name Description
System.Byte lineNumber

Line to clear (0-3)

View Source

DisplayText(String)

Display the text at the current cursor position.

Declaration
[Obsolete("Use .Write methods instead.")]
public void DisplayText(string text)

Parameters

Type Name Description
System.String text

Text to display.

View Source

MoveCursor(SerialLCD.Direction)

Move the cursor either right or left on the display.

Declaration
public void MoveCursor(SerialLCD.Direction direction)

Parameters

Type Name Description
SerialLCD.Direction direction

Direction to move the cursor, left or right.

View Source

SaveCustomCharacter(Byte[], Byte)

Saves a custom character to one of 8 slots in the CGRAM. Custom characters are defined as charater maps and can be created using online graphical tools such as the one found at: http://maxpromer.github.io/LCD-Character-Creator/

Note: due to .Net's underlying string implementation, slot 0 is unusable unless you decode the string yourself and use the Write(byte[] chars) method. Otherwise, when the string is created, .Net treats the 0 character as a string terminator.

Declaration
public void SaveCustomCharacter(byte[] characterMap, byte address)

Parameters

Type Name Description
System.Byte[] characterMap

Character map defining the 5x8 character.

System.Byte address

0-7

View Source

ScrollDisplay(SerialLCD.Direction)

Scroll the contents of the display one character in the specified direction.

Declaration
public void ScrollDisplay(SerialLCD.Direction direction)

Parameters

Type Name Description
SerialLCD.Direction direction

Direction to scroll the display, left or right.

View Source

SetBaudRate(SerialLCD.LCDBaudRate)

Change the baud rate of the display using the command interface.

Declaration
public void SetBaudRate(SerialLCD.LCDBaudRate baudRate)

Parameters

Type Name Description
SerialLCD.LCDBaudRate baudRate
View Source

SetBrightness(Single)

Sets the backlight brightness of the LCD. Valid values are 0 through 1. Sleeps for 125milliseconds after setting to let the display settle.

0 = Off 0.5 = 50% 1 = 100%

Declaration
public void SetBrightness(float brightness = 0.75F)

Parameters

Type Name Description
System.Single brightness
View Source

SetCursorPosition(Byte, Byte)

Set the cursor position on the display to the specified column and line.

Declaration
public void SetCursorPosition(byte column, byte line)

Parameters

Type Name Description
System.Byte column

Column on the display to move the cursor to (0-15 or 0-19).

System.Byte line

Line on the display to move the cursor to (0-3).

View Source

SetCursorStyle(SerialLCD.CursorStyle)

Set the cursor style to underline or block. The cursor can also be blinking or solid.

Declaration
public void SetCursorStyle(SerialLCD.CursorStyle style)

Parameters

Type Name Description
SerialLCD.CursorStyle style

New cursor style (Block/Underline, Blinking/Solid).

View Source

SetDisplayVisualState(SerialLCD.DisplayPowerState)

Turn the display on or off.

Declaration
public void SetDisplayVisualState(SerialLCD.DisplayPowerState state)

Parameters

Type Name Description
SerialLCD.DisplayPowerState state

New power state for the display.

View Source

SetSplashScreen(String, String)

Set up the splash screen.

Declaration
public void SetSplashScreen(string line1, string line2)

Parameters

Type Name Description
System.String line1
System.String line2
View Source

ToggleSplashScreen()

Toggle the splash screen.

Declaration
public void ToggleSplashScreen()
View Source

Write(Byte[])

Displays the characters at the current cursor position. Unlike the string text overload, this assumes the text has already been encoded to characters. Can be useful in sending pre-encoded characters, or accessing custom a custom character saved in the 0 slot.

Declaration
public void Write(byte[] chars)

Parameters

Type Name Description
System.Byte[] chars
View Source

Write(String)

Display the text at the current cursor position.

Declaration
public void Write(string text)

Parameters

Type Name Description
System.String text

Text to display.

View Source

WriteLine(String, Byte)

Writes the specified text to the specified line.

Declaration
public void WriteLine(string text, byte lineNumber)

Parameters

Type Name Description
System.String text

Text to display.

System.Byte lineNumber

Line to write the text on (0-3).