Comments (3)
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.
Thank you so much!!
from mcp-spi-adc.
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)
- Typescript interface?
- Error: ENOENT, No such file or directory HOT 7
- Troubleshooting basic setup HOT 5
- No signal from Pulse Sensor HOT 22
- bindings.js: 202 Uncaught TypeError: exists is not a function HOT 2
- support for MCP3201 HOT 1
- MCP3208 differential mode HOT 1
- Error Message HOT 3
- Incompatibility with electron because of non-context-aware-ness
- Error: EPERM, device closed, operation not permitted HOT 7
- Promises api HOT 1
- Drop support for Node.js v0.10, v0.12, v5 and v7 HOT 1
- Support for TI ADS1256 HOT 3
- Moisture sensor returns data between 0.78 (dry) and 0.54 (wet) HOT 1
- What's the different between device number and bus number? HOT 1
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 mcp-spi-adc.