easyi2c

EasyI2C for BananaPi / RasberryPi (& more) to Control I2C Bus + I2C LCD

Usage no npm install needed!

<script type="module">
  import easyi2c from 'https://cdn.skypack.dev/easyi2c';
</script>

README

EasyI2C

EasyI2C is made for Singelboard Computers like BananaPi or RasberryPi. Supporting I2C-LCD; I2C-PN532 (RFID, NFC) [WIP]

Its a Wrapper! Using: i2c-bus

Installation

npm i easyi2c

https://www.npmjs.com/package/easyi2c

Usage

var EasyI2C = require("easyi2c");

var i2c = new EasyI2C(2);

i2c.on("connectedDevice", e => {
    console.log(`${ e.fid} has connected to the I2C-Bus`); 
});
i2c.on("disconnectedDevice", e => {
    console.log(`${ e.fid} has has disconnected from the I2C-Bus`);
});
i2c.on("message", e => {
    console.log(`${ e.fid} has send: ${ e.text} (${ e.bytes} Bytes)`);
});
i2c.on("ready", () => {
    console.log("EasyI2C is ready!");
});

i2c.start();

LCD-Example

i2c.on("connectedDevice", e => {
    console.log(`${ e.fid} has connected to the I2C-Bus`);
    if(e.fid =="0x27") {
        lcd = i2c.LCD(e.id, 16,2);
        lcd.print("Hello World");
    } 
});

Syntax

lcd.print(String);
lcd.clear();
lcd.cursorFull();
lcd.cursorUnder();
lcd.setCursor(x:number,y:number);
lcd.home(); // => setCursor(0,0)
lcd.blink(boolen)
lcd.cursor(boolen);
lcd.setBacklight(boolen);
lcd.off();
lcd.on();

i2c.on(name, func);
i2c.LCD(address,cols,rows); //=> EasyLCD
i2c.start();
i2c.updateSpeed; // default 1000
i2c.devicelist;
i2c.devicelistjson(); get i2c.devicelist as json
i2c.write(address,String);
i2c.read(address,length); (length > response text)
i2c.sleep(ms);
i2c.request(address,text,length); // write + read (length > response text)
i2c.updateDeviceList(this) // dont use if you dont use i2c.start();

Notes

Using i2c-bus for communication