#lcd #adafruit #i2c

no-std adafruit-lcd-backpack

Unofficial driver for the Adafruit I2C LCD backpack

1 unstable release

0.1.1 Feb 19, 2024

#1468 in Embedded development

MIT license

570KB
319 lines

adafruit-lcd-backpack

Rust driver for the Adafruit I2C LCD backpack with MCP23008 GPIO expander

NOTE: This library is not made by Adafruit, and is not supported by them. The use of the Adafruit name is for compatibility identification purposes only.

Overview

This crate provides a driver for the Adafruit I2C LCD backpack with MCP23008 GPIO expander. It is designed to be used with the embedded-hal traits for embeded systems. It supports standard HD44780 based LCD displays.

Usage

To create a new LCD backpack, use the new method. This will return a new LCD backpack object. Pass it the type of LCD display you are using, the I2C bus, and the delay object. Both the I2C Bus and Delay objects must implement the relevant embedded-hal traits.

// The embedded-hal traits are used to define the I2C bus and delay objects
use embedded_hal::{
    blocking::delay::{DelayMs, DelayUs},
    blocking::i2c::{Write, WriteRead},
};
use lcd_backpack::{LcdBackpack, LcdDisplayType};

// create the I2C bus per your platform
let i2c = ...;

// create the delay object per your platform
let delay = ...;

// create the LCD backpack
let mut lcd = LcdBackpack::new(LcdDisplayType::Lcd16x2, i2c, delay);

// initialize the LCD
if let Err(_e) = lcd.init() {
   panic!("Error initializing LCD");
}

This library supports the core::fmt::Write trait, allowing it to be used with the write! macro. For example:

use core::fmt::Write;

// write a string to the LCD
if let Err(_e) = write!(lcd, "Hello, world!") {
  panic!("Error writing to LCD");
}

The various methods for controlling the LCD are also available. Each returns a Result that wraps the LCD backpack object. This allows you to chain the methods together. For example:

// clear the display and home the cursor before writing a string
if let Err(_e) = write!(lcd.clear()?.home()?, "Hello, world!") {
 panic!("Error writing to LCD");
}

License

Licensed under the MIT license.

Dependencies

~1.5MB
~36K SLoC