Comments (7)
Hello @k33g,
I'll try to provide you something useful for your needs. Let's keep in touch, okay?
from grovepi.
oh nice π π thank you very much π
from grovepi.
Hey, i'm also curious :) Is there any example code on how to use the 96x96 OLED Display with node?
from grovepi.
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.
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.
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.
hello @danibram,
that's awesome, thank you for your contribution!
from grovepi.
Related Issues (20)
- Installing GrovePi: ./install.sh: command not found HOT 4
- Installing on balena.io or docker HOT 1
- No such file or directory -- bash firmware_update.sh HOT 2
- Home Weather Station -- Runtime Error HOT 5
- The GrovePi sensor connection is unstable!! Under Python. Can you help me?
- Help meοΌMy GrovePiβs RST often light up after hours of work HOT 4
- Grove-LCD RGB Backlight V4.0 can't find i2c address on grovepi
- digitalRead not working HOT 1
- GrovePi+ D4 port question--differences among ports or faulty port/pi?
- Ruby test code doesn't run, i2c-devices library problem? HOT 1
- No more need the buffer tools module
- Can I use Tinker board to connect Grove Pi?
- oops: unable to determine board revision from /proc/cpuinfo
- grove_co2_lib.py not compatible with python3 HOT 1
- Hightemperature not reading
- di_i2c module missing ?
- RFR_Tools: Couldn't add Nodejs repo to source because it's not available for "bullseye" distribution
- Error: "pybind11" must be installed before running the build. HOT 4
- compatible with Banana Pi M2 Berry / M5 or Radxa Rock 3 A / Rock 4 C+ ? HOT 1
- does anyone know how to fix this?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grovepi.