0.2.0 • Published 9 years ago

pi-display v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

piDisplay

2 Digit, 7 Segment LED Display Controller Software for the Raspberry Pi. A module for Node.js.

This is a beta version of piDisplay. Everything works correctly as is, but I plan on updating it with a lot more features in the coming weeks and months. This module can display numbers and some letters on a 7 segment, 2 digit LED display that is connected to a Raspberry Pi.

Sample Images

Scrolling Text Across Display

Scrolling Text Across Display

Counting Up on the Display

Counting Up on the Display

Counting Down on the Display

Counting Down on the Display

Pin Layout/Configuration

The model of LED display I am using is a Kingbright DA03-11GWA, and the pinout is shown in the image below. For the full tech sheet, see here. LED Display Pin Layout

As you can see the display uses two pins for common cathodes, seven pins for the LEDs themselves, and pin 2 is not connected. If you do not have the same display, that's fine, just be sure it's common cathode and not common anode, and that it has two common cathode pins and seven pins for the LED segments of the digits. You'll also need to remap the pins manually if your different display does not match the pinout of the display above.

This is how the display's pins are mapped out on the R-Pi's GPIO pins. There wasn't much rhyme or reason to this, and you can feel free to change the defaults if you would like, which I will detail below. All pins are listed by their physical pin number.

LED PinR-Pi Pin
513
1015
918
719
121
822
323
624
426

Installation

npm install pi-display

Need help with installation? See here.

Usage

// Don't forget the extra parentheses to call the constructor function!
var piDisplay = require("pi-display")();

// Displays E7 on the LED display.
piDisplay.displayChars("E7");

// Displays 85.
piDisplay.displayChars(85);

// Scrolls the given string across the display. It looks more natural to scroll
// if you have spaces at either end of the string, but they are not mandatory.
// The second argument is the milliseconds to display each character.
piDisplay.scrollChars(" HI HELLO 1234567890 ", 400);

API

Methods

MethodArgument(s)Description
constructor()object ledPins, object cathodePinsUsed to construct the piDisplay object. Pass in two objects as described in the properties section. Both arguments are optional. See properties for more information.
displayChars()string|number charsDisplays one to two static characters on the display. Accepts a string or number (0 to 99). Can be updated very rapidly (without needing to use the clearDisplay() method) in a loop or through some other means.
scrollChars()string sentence, number speedDisplays the given sentence in a scrolling style across the LED display, moving one character at a time. The scrolling speed is specified in milliseconds. If no speed is specified, the default 400 is used.
count()string upOrDown, number speedCounts one-by-one either up or down on the display from 0 to 99. Use the string 'up' or 'down' to specify if the method should count up or down. The speed at which each new number is displayed is specified in milliseconds. If no speed is specified, the default 200 is used.
clearDisplay()noneCompletely clears the display (turns off all the LEDs) and stops any method that is currently executing.

Properties

These properties can only be reassigned at startup. See constructor method for more information.

PropertyDefault ValueDescription
ledPinsobject {"top": 23, "topLeft": 26, "topRight": 18, "middle": 21, "bottomLeft": 19, "bottomRight": 22, "bottom": 24}Which physical pin number is matched to which segment of the LED.
cathodePinsobject {"digitOne": 15, "digitTwo": 13}The physical pin that controls which digit is turned off when set to HIGH.

Credits

I'd like to give a huge thanks to drogon for his excellent Wiring Pi library, Soarez for making the original Node.js bindings for Wiring Pi, and eugeneware for enhancing Soarez's work on the newer Node.js bindings.