2.0.2 • Published 17 days ago

@iiot2k/mcp4728 v2.0.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
17 days ago

@iiot2k/mcp4728

platform

mcp4728 digital to analog converter library

Installation

npm install @iiot2k/mcp4728

or add in your package.json:

"dependencies": {
    "@iiot2k/mcp4728": "latest"
},

View on npm

mcp4728 12bit digital to analog converter

  • 12bit Conversion Resolution.
  • Four Analog Outputs.
  • Internal or External Voltage Reference.
  • Stores outputs value to internal eeprom.

Usage

  • This library works on Raspberry Pi with 32bit or 64bit OS.
  • Enable I2C with raspi-config.
  • In this case i2c-1 is enabled (port=1).
  • If you use i2c-0 port add dtparam=i2c_vc=on to /boot/config.txt, then Pin27=SDA, Pin28=SCK.
  • For other ports add this to /boot/config.txt.

API

API functions are explained in documents API.md

Report any issues here

Example

// example writes to dac output
"use strict";

const mcp4728 = require("@iiot2k/mcp4728");

var ret = mcp4728.write_sync(
    1, // i2c-1
    mcp4728.CH_A, // output A
    mcp4728.VREF_INT_4096, // internal vref
    1000 // dac value
    );

if (ret === undefined)
    console.log("error on write dac");
else
    console.log(ret);
// example writes multiple values to dac outputs
"use strict";

const mcp4728 = require("@iiot2k/mcp4728");

mcp4728.write_multi(
    1, // i2c-1
    mcp4728.VREF_INT_4096, // internal vref
    [1000, 1500, 2000, 3000],  // values output A..D
    (data) => {
        if (data === undefined)
            console.log("error on write dac");
        else
            console.log(data);
    });

Examples are on examples folder.