Skip to content

NodeJS driver for mcp23008. Lets you detect button clicks and draw on the display.

License

Notifications You must be signed in to change notification settings

sveasmart/adafruit-mcp23008-ssd1306-node-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node driver for Adafruit MCP23008 and SSD1306

This package is designed to let us talk to this thing using node on a Rasberry Pi running Raspbian.

That is, we can detect button presses and write stuff to the display.

How to install

npm install adafruit-mcp23008-ssd1306-node-driver

How to use it

Try this to run a quick demo. It echos button presses to the display.

const adafruit = require("adafruit-mcp23008-ssd1306-node-driver")
adafruit.demo()

Here's how to do it yourself:

const adafruit = require("adafruit-mcp23008-ssd1306-node-driver")
const ButtonDriver = adafruit.ButtonDriver
const DisplayDriver = adafruit.DisplayDriver

const busNumber = 1

const displayAddress = 0x3c
const displayDriver = new DisplayDriver(busNumber, displayAddress)

const buttonsAddress = 0x20
const buttonDriver = new ButtonDriver(busNumber, buttonsAddress)

buttonDriver.watchAllButtons(function(buttonPin) {
  displayDriver.writeText("Clicked button #" + buttonPin)
})

displayDriver.writeText("OK, click some buttons")
console.log("Check the display...")

You can also watch just one button:

buttonDriver.watchButton(1, function(buttonPin) {
  console.log("Clicked button #" + buttonPin)
})

You can also display QR codes:

displayDriver.setQrCode("http://www.google.com")

Note that the display driver runs a background loop to keep the display refreshed. So your process won't exit until you call:

displayDriver.stop()

Using tabs

This driver has a "tab" mechanism, using the metaphor of tabs in a web browser. Send the tab name as the last parameter of any method. If you don't specify a tab, it will use "default". Switch the current using displayDriver.showTab(...).

Example:

displayDriver.writeText("First tab", 0, 0, false, "tab1")
displayDriver.writeText("Second tab", 0, 0, false, "tab2")
displayDriver.showTab("tab2")

If you write stuff on a tab that isn't the current tab, then nothing changes on the display until you show that tab. Just like with real tabs.

Testing

If you are in a development environment with no access to the actual screen, you can use the fakes.

const adafruit = require("adafruit-mcp23008-ssd1306-node-driver")

console.log("Has driver: ", adafruit.hasDriver())
const fakeDisplayDriver = new adafruit.FakeDisplayDriver()
const fakeButtonDriver = new adafruit.FakeButtonDriver()
  • FakeDisplayDriver: has all the same methods as DisplayDriver, but displays on the terminal instead of the SSD1306 display.
  • FakeButtonDriver: has all the same methods as ButtonDriver, but you simulate button presses using your keyboard (press 0, 1, or 2).

How it works internally

The button stuff is a node port of this code:

For display stuff is a wrapper around:

About

NodeJS driver for mcp23008. Lets you detect button clicks and draw on the display.

Resources

License

Stars

Watchers

Forks

Packages

No packages published