How to use mcp-spi-adc - 10 common examples

To help you get started, we’ve selected a few mcp-spi-adc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openhomeautomation / smart-homes-pi-zero / 05 / meter_log.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github openhomeautomation / smart-homes-pi-zero / 05 / meter_interface.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github PacktPublishing / Building-Smart-Homes-with-Raspberry-Pi-Zero / Chapter 05 / 05 / meter_log.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github PacktPublishing / Building-Smart-Homes-with-Raspberry-Pi-Zero / Chapter 05 / 05 / meter.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github PacktPublishing / Building-Smart-Homes-with-Raspberry-Pi-Zero / Chapter 05 / 05 / meter_interface.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github openhomeautomation / smart-homes-pi-zero / 05 / meter.js View on Github external
// ID should be 6 characters long
piREST.set_id('34f5eQ');
piREST.set_name('energy_meter');
piREST.set_mode('bcm');

// Variables
current = 0;
power = 0;

// Start server
var server = app.listen(80, function() {
    console.log('Listening on port %d', server.address().port);
});

// Sensor measurement loop
var sensor = mcpadc.open(channel, {speedHz: 20000}, function (err) {
  if (err) throw err;

  // Measurement interval
  setInterval(function () {

    // Read
    sensor.read(function (err, reading) {
      if (err) throw err;

      // Calculate current
      var measuredVoltage = reading.value * 3.3;
      var measuredCurrent = (measuredVoltage/resistance) * 2000 / 1.41;

      // Calculate power
      var power = voltage * measuredCurrent;
github petre2dor / piGarden / devices / controller / fw1s / read_fw1s.js View on Github external
return new Promise((resolve, reject) => {
        let tempSensor = Mcpadc.open(0, {speedHz: 20000}, err => {
            if (err) reject({ type: 'ERROR', message: 'Could not open mcpadc.', httpCode: 400, data: err })

            tempSensor.read((err, reading) => {
                if (err) reject({ type: 'ERROR', message: 'Could not read mcpadc.', httpCode: 400, data: err })
                // map read value to from range 1(no humidity) - 0.3(max humidity) to range 0 - 100
                let humidity = Util.map_range(reading.value, 1, 0.3, 0, 100);
                resolve({
                    message: 'Here is the humidity.',
                    type: 'SUCCESS',
                    httpCode: 200,
                    data: [{"type": "HUMIDITY", "value": humidity}]
                })
            })
        })
    })
}
github node-red / node-red-nodes / hardware / mcp3008 / pimcp3008.js View on Github external
RED.nodes.createNode(this,n);
        this.pin = n.pin || 0;
        this.interval = n.interval || 1000;
        this.dnum = parseInt(n.dnum || 0);
        this.bus = parseInt(n.bus || 0);
        this.dev = n.dev || "3008";
        var node = this;
        var cb = function (err) { if (err) { node.error("Error: "+err); } };
        var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus };
        var chans = parseInt(this.dev.substr(3));

        try {
            fs.statSync("/dev/spidev"+node.bus+"."+node.dnum);
            if (mcp3xxx.length === 0) {
                for (var i=0; i= 0) && (pay < chans)) { pin = pay; }
                    else { node.warn("Payload needs to select channel 0 to "+(chans-1)); }
                }
                else { pin = parseInt(node.pin); }
github node-red / node-red-nodes / hardware / mcp3008 / pimcp3008.js View on Github external
this.pin = n.pin || 0;
        this.interval = n.interval || 1000;
        this.dnum = parseInt(n.dnum || 0);
        this.bus = parseInt(n.bus || 0);
        this.dev = n.dev || "3008";
        var node = this;
        var cb = function (err) { if (err) { node.error("Error: "+err); } };
        var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus };
        var chans = parseInt(this.dev.substr(3));

        try {
            fs.statSync("/dev/spidev"+node.bus+"."+node.dnum);
            if (mcp3xxx.length === 0) {
                for (var i=0; i= 0) && (pay < chans)) { pin = pay; }
                    else { node.warn("Payload needs to select channel 0 to "+(chans-1)); }
                }
                else { pin = parseInt(node.pin); }
                if (pin !== null) {
github node-red / node-red-nodes / hardware / mcp3008 / pimcp3008.js View on Github external
this.interval = n.interval || 1000;
        this.dnum = parseInt(n.dnum || 0);
        this.bus = parseInt(n.bus || 0);
        this.dev = n.dev || "3008";
        var node = this;
        var cb = function (err) { if (err) { node.error("Error: "+err); } };
        var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus };
        var chans = parseInt(this.dev.substr(3));

        try {
            fs.statSync("/dev/spidev"+node.bus+"."+node.dnum);
            if (mcp3xxx.length === 0) {
                for (var i=0; i= 0) && (pay < chans)) { pin = pay; }
                    else { node.warn("Payload needs to select channel 0 to "+(chans-1)); }
                }
                else { pin = parseInt(node.pin); }
                if (pin !== null) {
                    mcp3xxx[pin].read(function (err, reading) {

mcp-spi-adc

MCP3002/4/8, MCP3202/4/8 and MCP3304 SPI analog to digital conversion

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis