Code Monkey home page Code Monkey logo

Comments (7)

marcellobarile avatar marcellobarile commented on August 24, 2024

Hello @k33g,
I'll try to provide you something useful for your needs. Let's keep in touch, okay?

from grovepi.

k33g avatar k33g commented on August 24, 2024

oh nice πŸ˜ƒ πŸ‘ thank you very much πŸ˜„

from grovepi.

chewbecky avatar chewbecky commented on August 24, 2024

Hey, i'm also curious :) Is there any example code on how to use the 96x96 OLED Display with node?

from grovepi.

jlorek avatar jlorek commented on August 24, 2024

Im also looking for an example or at least an direction on how to use the display in NodeJS.
Any help is appreciated!
Thanks :)

from grovepi.

marcellobarile avatar marcellobarile commented on August 24, 2024

Sorry for being late guys, I don't have that display but I'll do my best to give you some reasonable answer :)

from grovepi.

danibram avatar danibram commented on August 24, 2024

Hey guys,
I wrote this class for a workshop with my groove pi

const GrovePi = require('node-grovepi').GrovePi;
const fs = require('fs');
const sleep = require('sleep');
const extend = require('extend');

const I2cSensor = GrovePi.sensors.base.I2C;
const i2cBus = require('i2c-bus');

const DISPLAY_RGB_ADDR = 0x62;
const DISPLAY_TEXT_ADDR = 0x3e;

const i2c0Path  = '/dev/i2c-0'
const i2c1Path  = '/dev/i2c-1'
const i2c2Path  = '/dev/i2c-2'

class LCD_I2C {
    constructor(){
        this.data = {}

        this.initialized = false;
        this.bus = null;
        // Bus Address from i2cdetect command
        this.address = 0x68;
        // Default delay for streaming
        this.watchDelay = 100;

        let busNumber

        if (fs.existsSync(i2c0Path)) {
          busNumber = 0
        } else if (fs.existsSync(i2c1Path)) {
          busNumber = 1
        } else if (fs.existsSync(i2c2Path)) {
          busNumber = 2
        } else {
          var err = console.log('ERR: Could not determine your i2c device')
        }

        this.i2c1 = i2cBus.openSync(1);
        console.log(this.i2c1)

        this.setText('Ready!');
        this.setRGB(55, 55, 255);
    }

    //data
    setData(data) {
        this.data = Object.assign({}, this.data, data)
        this.update(this.data)
    }

    update(data) {
        var text = ""
        Object.keys(data).map((k) => {
            text = text + ` ${k}: ${data[k]}`
        })
        this.setText(text);
    }

    //Hardware
    setRGB(r, g, b) {
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,0,0)
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,1,0)
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,0x08,0xaa)
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,4,r)
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,3,g)
      this.i2c1.writeByteSync(DISPLAY_RGB_ADDR,2,b)
    }

    textCommand(cmd) {
      this.i2c1.writeByteSync(DISPLAY_TEXT_ADDR, 0x80, cmd);
    }

    setText(text) {
      this.textCommand(0x01) // clear display
      sleep.usleep(50000);
      this.textCommand(0x08 | 0x04) // display on, no cursor
      this.textCommand(0x28) // 2 lines
      sleep.usleep(50000);

      var count = 0;
      var row = 0;
      for(var i = 0, len = text.length; i < len; i++) {
        if(text[i] === '\n' || count === 16) {
          count = 0;
          row ++;
            if(row === 2)
              break;
          this.textCommand(0xc0)
          if(text[i] === '\n')
            continue;
        }
        count++;
        this.i2c1.writeByteSync(DISPLAY_TEXT_ADDR, 0x40, text[i].charCodeAt(0));
      }
    }
}

export default LCD_I2C

I hope this help you, its written in es6 but you can easy extract the basic idea

from grovepi.

marcellobarile avatar marcellobarile commented on August 24, 2024

hello @danibram,
that's awesome, thank you for your contribution!

from grovepi.

Related Issues (20)

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.