USB Serial Countdown

Posted by

This Node project is a command line app for counting down the number of days to several events on a 16×2 LCD display connected to a computer via USB. The display used in this project is the “USB + Serial Backpack Kit with 16×2 RGB backlight positive LCD – Black on RGB” from Adafruit. The project is available on GitHub at

Run npm link in the project root directory to symlink the binary file to the system path, making it accessible from anywhere by running usb-countdown

Run npm run start to start the app in the background

The app supports the following command line options:

  • List – List events
  • Add – Add an event (“Event title” 12/18/2018)
  • Remove – Remove an event (Specify index of event from List command)
  • Start – Start displaying event countdown
  • Stop – Stop displaying event countdown
  • Clear – Clear the list of events
  • Speed – Number of seconds to show each event (1-5)\
  • Color – Display background color (White, Red, Orange, Yellow, Green, Blue, Purple)
  • Port – Serial port for display
  • Baud – Serial port baud rate

Project Overview

The project consists of a Node module (index.js) which does all the real work, such as calculating the number of days in the countdown, storing the countdown events in a JSON file, and sending the data to the LCD display at a regular interval.

There is also the command line app (app.js), which uses the countdown Node module and parses the command line command.

To make the countdown available from the command line, a file (bin/usb-countdown) is added to the bin field in the project’s package.json file.

The Countdown Node Module

The countdown module exports several functions to manipulate events (add, remove, list, …) and adjust serial port and display settings that are used by the command line application or any other program that requires the module. It uses the node-serialport NPM module for serial port communication and the jsonfile NPM module to save settings as a JSON text file.

The Command Line Application

The command line application basically parses any command line options and passes it on to the countdown module. Although the bulk of the code is in app.js, the command line application is a stub in bin directory called usb-countdown that requires app.js

Scripts to start and stop usb-countdown are in package.json. The script to start the countdown in the background uses nohup to ensure that the process isn’t terminated when the shell gets logged out.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.