Giter Club home page Giter Club logo

Comments (3)

fivdi avatar fivdi commented on June 15, 2024

The max. sampling rate will depend on many factors, for example:

  • The Node version
  • The Linux version
  • The SPI device driver
  • The board (Raspberry Pi 0, 1, 2, 3 or 4, BeagleBone, BeagleBone Black, ...)
  • The system load
  • ...

The below program samples the voltage on channel 4 of an MCP3008 and prints the number of samples per second.

const mcpadc = require('mcp-spi-adc');
const assert = require('assert');

let voltageReading;
let samplesPerSec = 0;

const voltageSensor = mcpadc.open(4, err => {
  assert(!err, 'can\'t open voltage sensor');

  const next = _ => {
    voltageSensor.read((err, reading) => {
      assert(!err, 'can\'t read voltage sensor');
      voltageReading = reading;
      samplesPerSec += 1;
      next();
    });
  };

  next();
});

setInterval(_ => {
  console.log(
    'samples per sec: ' + samplesPerSec +
    ', v: ' + (voltageReading.value * 3.3)
  );

  samplesPerSec = 0;
}, 1000);

If this program is run using Node 14 on a Raspberry Pi 2 running Linux raspberrypi 4.19.57-v7+ with no additional system load it prints the following:

samples per sec: 3667, v: 1.6580645161290322
samples per sec: 3935, v: 1.6548387096774193
samples per sec: 4207, v: 1.6580645161290322
samples per sec: 4178, v: 1.661290322580645
samples per sec: 4168, v: 1.661290322580645
samples per sec: 4307, v: 1.661290322580645
samples per sec: 4481, v: 1.661290322580645
samples per sec: 4459, v: 1.661290322580645
samples per sec: 4390, v: 1.6580645161290322
samples per sec: 4319, v: 1.6580645161290322
samples per sec: 4021, v: 1.6580645161290322
samples per sec: 4226, v: 1.6580645161290322
samples per sec: 4198, v: 1.6580645161290322
samples per sec: 4255, v: 1.6580645161290322
samples per sec: 4404, v: 1.6580645161290322
samples per sec: 4429, v: 1.6580645161290322
samples per sec: 4443, v: 1.6580645161290322
samples per sec: 4402, v: 1.6580645161290322
samples per sec: 4478, v: 1.6580645161290322
samples per sec: 4480, v: 1.6580645161290322
samples per sec: 4481, v: 1.6580645161290322
samples per sec: 4432, v: 1.6548387096774193
samples per sec: 4472, v: 1.6580645161290322
samples per sec: 4473, v: 1.6580645161290322
samples per sec: 4424, v: 1.6580645161290322
samples per sec: 4470, v: 1.6548387096774193
samples per sec: 4477, v: 1.6548387096774193
samples per sec: 4399, v: 1.6548387096774193
samples per sec: 4465, v: 1.6548387096774193
samples per sec: 4467, v: 1.6548387096774193
samples per sec: 4471, v: 1.6580645161290322
samples per sec: 4427, v: 1.6548387096774193
samples per sec: 4473, v: 1.6548387096774193
samples per sec: 4463, v: 1.6580645161290322
samples per sec: 4430, v: 1.6580645161290322
samples per sec: 4486, v: 1.6548387096774193
samples per sec: 4549, v: 1.6580645161290322
samples per sec: 4495, v: 1.6580645161290322
samples per sec: 4548, v: 1.6580645161290322
samples per sec: 4542, v: 1.6548387096774193
samples per sec: 4514, v: 1.6580645161290322
samples per sec: 4545, v: 1.6580645161290322
samples per sec: 4545, v: 1.6580645161290322
samples per sec: 4432, v: 1.6580645161290322
samples per sec: 4468, v: 1.6580645161290322
samples per sec: 4474, v: 1.6580645161290322
samples per sec: 4475, v: 1.6580645161290322
...

Give the program a try on your system to see what's possible.

Note that Linux is not a real time operating system so there are no guarantees about timing.

from mcp-spi-adc.

ZaneL avatar ZaneL commented on June 15, 2024

Thank you so much!!

from mcp-spi-adc.

meta-meta avatar meta-meta commented on June 15, 2024

Any ideas how to get a faster sampling rate? I'm on a Pi Zero W, reading 6 pins and getting maybe 600 samples per second. I don't necessarily need all 10 bits if that makes a difference. I'm trying to get a digital reading from IR sensors which I can do with GPIO but being able to decide 0|1 with a threshold in software is valuable.

from mcp-spi-adc.

Related Issues (16)

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.