npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lcdi2c

v1.0.6

Published

I2C LCD character display driver for Raspberry Pi using PCF8574 port expander.

Downloads

30

Readme

lcdi2c

Overview

For use on a Raspberry Pi, lcdi2c is a node.js library for accessing LCD character displays using I2C via a PCF8574 port expander, typically found on inexpensive LCD I2C "backpacks." This work is based upon the following repository:

https://github.com/wilberforce/lcd-pcf8574

lcdi2c supports 16x2 and 20x4 LCD character displays based on the Hitachi HD44780 LCD controller ( https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller ). lcdi2c uses the i2c-bus library ( https://github.com/fivdi/i2c-bus ) instead of the i2c library since the former supports more recent versions of node (e.g. 4.2.1).

lcdi2c also provides new functions to facilitate output on a multiline character display based on the Hitachi HD44780 LCD controller. These include:

println( string, line ): Sends output to a specified line. Automatically truncates output to number of columns specified on startup.

Installation

npm install lcdi2c

Usage

First, set up I2C on your Raspberry Pi. More information about this can be found here:

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

Now, check for the address of the LCD on the I2C bus:

For a rev. 1 board, use the following:

sudo i2cdetect -y 0

For a rev. 2+ board, use the following:

sudo i2cdetect -y 1

This will print out the devices on the I2C bus, such as:

root@raspberrypi:/home/pi/lcdi2c# sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Here, we see two devices, 0x27 (our LCD display) and 0x68 (a realtime clock board). So, the device address is 0x27.

To use lcdi2c, add the following code to your node.js application to set up the lcd object:

var LCD = require('lcdi2c');
var lcd = new LCD( 1, 0x27, 20, 4 );

Note that this will set up an I2C LCD panel on I2C bus 1, address 0x27, with 20 columns and 4 rows.

To print out strings to the LCD panel, see the following code:

lcd.clear();
lcd.print( 'This is line 1...   ' );
lcd.print( 'This is line 2...   ' );
lcd.print( 'This is line 3...   ' );
lcd.print( 'plThis is line 4... ' );

To print out a string to the LCD panel using specified line numbers, see the following example code:

lcd.clear();
lcd.println( 'plThis is line 1...', 1 );
lcd.println( 'plThis is line 2...', 2 );
lcd.println( 'plThis is line 3...', 3 );
lcd.println( 'plThis is line 4...', 4 );

To turn on the backlight:

lcd.on();

To turn off the backlight:

lcd.off();

To create custom characters:

lcd.createChar( 0,[ 0x1B,0x15,0x0E,0x1B,0x15,0x1B,0x15,0x0E] ).createChar( 1,[ 0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00] );

More information about creating such custom characters can be found here:

http://www.quinapalus.com/hd44780udg.html

Error Checking

i2clcd checks for errors and implements a simple try/catch method to catch errors sent by the I2C driver. Such errors will occur if the bus has not been set up properly, if the device ID is wrong, or if the device is not operational. To prevent crashes, it is recommended that error checking be implemented in the calling code.

If an error is encountered, this will be stored in the variable lcd.error. The calling code should test lcd.error is null/false before calling the i2clcd routine again. Failure to check for such errors will result in a crash of the node.js application.

Example code:

var LCD = require('lcdi2c');
var lcd = new LCD( 1, 0x27, 20, 4 );

lcd.println( 'This is line 1...', 1 );
if ( lcd.error ) { 
    lcdErrorHandler( lcd.error );
} else {
    lcd.println( 'This is line 2...', 2 );
    if ( lcd.error ) {
       lcdErrorHandler( lcd.error );
    } else {
        lcd.println( 'This is line 3...', 3 );
        if ( lcd.error ) {
            lcdErrorHandler( lcd.error );
        } else {
            lcd.println( 'This is line 4...', 4 );
            if ( lcd.error ) {
                lcdErrorHandler( lcd.error );
            };
        };
    };   
};   

function lcdErrorHandler( err ) {
    console.log( 'Unable to print to LCD display on bus 1 at address 0x27' );
    //Disable further processing if application calls this recursively.
};

This code is rather ugly, but it will prevent any calls to the underlying I2C driver from causing a program crash if the I2C bus or LCD display is not configured properly, or if the LCD is not plugged in. This recursive error checking will prevent the application from crashing even if the LCD device is unplugged during application processing.

A sample application called i2c_clock is provided in this library (and can be found in ../node_modules/lcdi2c) that provides an example of such error checking.