0.1.0 • Published 8 years ago

mcp-adc v0.1.0

Weekly downloads
3
License
Apache2.0
Repository
github
Last release
8 years ago

#mcp-adc Node.js module: MCP3208/MCP3008 SPI analog-to-digital converters support for RaspberryPi.

This library provides MCP3208(12bit) and MCP3008(10bit) analog-to-digital converters support. These chips are a good option for RaspberryPi DIY projects (see a sample with a wiring diagram here).

If using with RaspberryPi, please do not forget to enable SPI support using "raspi-config" first.

Code sample

var McpAdc = require('mcp-adc');

var adc = new McpAdc.Mcp3208();

var channel = 0;

adc.readRawValue(channel, function(value) {
        console.log("Raw value:\t" + value);
});

adc.readVoltage(channel, function(voltage) {
        console.log("Voltage:\t" + voltage);
});

adc.readNormalizedValue(channel, function(normValue) {
        console.log("Percents:\t" + (normValue * 100));
});

Output:

Raw value:	 700
Voltage:	0.5649084249084249
Percents:	17.094017094017094

It is also possible to use MCP3008:

var adc = new McpAdc.Mcp3008();

And provide custom reference voltage and/or SPI instance:

var adc = new McpAdc.Mcp3208({
    voltage: 1.3, //1.3v
    spi: mySpiInstance
});