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 = adafruit
Here's how to do it yourself:
const adafruit = const ButtonDriver = adafruitButtonDriverconst DisplayDriver = adafruitDisplayDriver const busNumber = 1 const displayAddress = 0x3cconst displayDriver = busNumber displayAddress const buttonsAddress = 0x20const buttonDriver = busNumber buttonsAddress buttonDriver displayDriverconsole
You can also watch just one button:
buttonDriver
You can also display QR codes:
displayDriver
Note that the display driver runs a background loop to keep the display refreshed. So your process won't exit until you call:
displayDriver
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:
displayDriverdisplayDriverdisplayDriver
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 = consoleconst fakeDisplayDriver = const 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:
- https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/legacy/Adafruit_MCP230xx/Adafruit_MCP230xx.py
- https://github.com/HWHardsoft/Display_Shield_RPI/blob/master/standard_test.py
For display stuff is a wrapper around: