Coder Social home page Coder Social logo

triptych / epaper.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samsonmking/epaper.js

0.0 2.0 0.0 12.34 MB

Node.js library for easily creating an ePaper display on a Raspberry PI using HTML and Javascript.

C 86.28% C++ 3.13% Python 1.38% JavaScript 9.21%

epaper.js's Introduction

ePaper.js

Node.js library for easily creating an ePaper display on a Raspberry PI using HTML and Javascript.

  • Render HTML DOM onto ePaper display
  • Simple and extensible Javascript and WebSocket API
  • Currently supports Waveshare 4.2inch ePaper Module
  • High performance, native c++ hardware access

Example weather station Example ereader gif

Working with the API

Create static/index.html. The contents of this webpage will be rendered onto the ePaper display.

<!DOCTYPE html>
<html lang="en">
    ...
<body>
    <h1>Hello from ePaper.js</h1>
    <script>
        // connect to the WebSocket API
        const ws = new WebSocket("ws://raspberrypi:8080");
        ws.addEventListener("open", () => {
            // draw contents of DOM onto ePaper display
            ws.send('render');
        });
    </script>
</body>
</html>

From Node.js initialize ePaper.js. This does the following:

  • Creates a webserver that serves index.html from the static directory
  • Loads index.html in a headless instance of Chromium, using Puppeteer
  • Creates a WebSocket API that the frontend can use to trigger a display refresh, or perform custom actions
  • Renders the contents of the browser DOM onto the ePaper display
const {init} = require('epaperjs');

init();

Additional Configuration

Additional Configuration Options

const {devices, init} = require('epaperjs');
init(devices.waveshare4in2, {
    webPort: 3000,                              // WebServer Port
    websocketPort: 8080,                        // WebSocket API Port
    staticDirectory: 'static',                  // Directory to serve frontend from
    url: `http://localhost:3000/index.html`     // Initial URL to load
};)

Extend the server side WebSocket API

const {devices, init} = require('epaperjs');

const render = (page, ws) => {
    // Forward frontend console output to Node.js console
    page.onConsoleLog(console.log);

    // When recieving 'render' from frontend, update display
    ws.on('message', async (message) => {
        if (message === 'render') {
            await page.display();
        }
    });

    // forward keypresses to the frontend over WebSocket
    process.stdin.addListener('keypress', (key, data) => {
        if (data.name === 'left') {
            ws.send('left');
        }
        if (data.name === 'right') {
            ws.send('right');
        }
    });
};

init(devices.waveshare4in2, {}, render);

Examples
See the examples directory

  • weather-station: This creates and example weather station display
  • ereader: An ereader that reads epub files and uses the left and right keypresses to change pages

Installation

Raspberry PI
Enable SPI

sudo raspi-config
# Choose Interfacing Options -> SPI -> Yes  to enable SPI interface
sudo reboot

Install Dependencies

# Install latest Node.js LTS
curl -sL install-node.now.sh/lts | sudo bash

sudo apt-get update

# Install wiringpi
sudo apt-get install -y wiringpi

# For Pi 4, you need to update wiringpi (skip otherwise):
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
#You will get 2.52 information if you've installed it correctly
gpio -v

# Remaining dependencies
sudo apt-get install -y build-essential chromium-browser

Node.js
Install ePaper.js

npm install -s epaperjs

Hardware

Waveshare 4.2inch Display
Waveshare HAT Raspberry Pi Adapter
3D Printed Enclosure for PI B+

epaper.js's People

Contributors

samsonmking avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.