GithubHelp home page GithubHelp logo

node-ads1x15's People

Contributors

adouglass avatar alphacharlie avatar tjkurki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-ads1x15's Issues

Example 3 that can be added done with looping code.

// To run this Do the following
//
// install modules
// npm install node-ads1x15 --save
//
//
// nodejs i2c.js
//
// Code test on a Pi3 and a AUTOMATION PHAT unit
// https://shop.pimoroni.com/products/automation-phat

var ads1x15 = require('node-ads1x15');
var chip = 0; //0 for ads1015, 1 for ads1115

//Simple usage (default ADS address on pi 2b or 3):
var adc = new ads1x15(chip);

// Optionally i2c address as (chip, address) or (chip, address, i2c_dev)
// So to use /dev/i2c-0 use the line below instead...:

//var adc = new ads1x15(chip, 0x48, '/dev/i2c-1');

var channel = 0; //channel 0, 1, 2, or 3...
var samplesPerSecond = '250'; // see index.js for allowed values for your chip
var progGainAmp = '4096'; // see index.js for allowed values for your chip

var ChData =[]; //somewhere to store values
var dev = 127; // used to change Ch data to Voltage

var Active = "0, 1, 2, 3"; //channels and the order to scan in
// var Active = "0, 1"; // Only ch 0 and 1
// var Active = "1, 3"; // Only ch 1 and 3
var ActiveCh = Active.split(", ") ;
var Count = 0; // Counter in the loop back

function ChannelRead() {
var ch = ActiveCh[Count]; // Getting the ActiveCh number
adc.readADCSingleEnded(ch, progGainAmp, samplesPerSecond, function(err, data) {
if(err){
//logging / troubleshooting code goes here...
throw err;
}
// if you made it here, then the data object contains your reading!
ChData[ch] = data // Putting data into

// Checking the Loop
if (Count == (ActiveCh.length - 1)) {// Checking if is the last change 
     Count = 0; // Reset the counter and do NOT call ChannelRead 
 // Output the Voltages
     console.log ('CH1: ' + (ChData[0]/dev).toFixed(2) +
               '\tCH2: ' + (ChData[1]/dev).toFixed(2) +
               '\tCH3: ' + (ChData[2]/dev).toFixed(2) +
               '\tCH4: ' + (ChData[3]/dev).toFixed(2) );

}else { // going to read the next channel 
     Count++;
     ChannelRead();  // Calling ChannelRead again with Count +1
}
return 1; // need to return to the starting call to TempRead

});
}

if(!adc.busy)
{

// ChannelRead(); // - one Time Read read all 4 ch

// Active = "0, 1, 2, 3";
// OUTPUT
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60

// Active = "0, 1";
// OUTPUT
// CH1: 0.03 CH2: 0.03 CH3: NaN CH4: NaN

// Active = "1, 3";
// OUTPUT
// CH1: NaN CH2: 0.03 CH3: NaN CH4: 4.57

iv = setInterval(ChannelRead, 500); // Repeat every 500msec
// 100 (every 100msecs or 10 times a sec) is the max with this program
// will do with 4 ch being run each time and the Sample rate (On a pi3).

// OUTPUT
// CH1: 5.15 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 5.15 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60

}

callback is needed in getLastConversionResults()

I think you forgot to call callback function in getLastConversionResults function. After 669th line you can add callback(null, data). I add the line however It was returned NaN value. I realized that this.pga is not set in startContinuousConversion function. I solve that problem by passing argument to getLastConversionResults function.

It gives me error as given below in the node-red console.

is ads1115
We've got an Error, Lance Constable Carrot!: Error: Cannot write to device
We've got an Error, Lance Constable Carrot!: Error: Error reading length of bytes

And I am getting some wrong reading from respective channel.

install fails because node-gyp rebuild fails

This package is just the thing I need for a project I am working on.

When I try to install node-ads1x15 on my raspberry pi 3, the rebuild of node-gyp fails:

pi@smoke-pi:~/work/tools/node-ads1x15 $ npm install node-ads1x15 --save
\

[email protected] install /home/pi/node_modules/node-ads1x15/node_modules/i2c
node-gyp rebuild

make: Entering directory '/home/pi/node_modules/node-ads1x15/node_modules/i2c/build'
CXX(target) Release/obj.target/i2c/src/i2c.o
../src/i2c.cc: In function ‘void ReadBlock(const v8::FunctionCallbackInfov8::Value&)’:
../src/i2c.cc:162:47: error: no matching function for call to ‘New(int32_t&)’
Local buffer = node::Buffer::New(len);
^
../src/i2c.cc:162:47: note: candidates are:
In file included from ../src/i2c.cc:2:0:
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:28:40: note: v8::MaybeLocalv8::Object node::Buffer::New(v8::Isolate_, size_t)
NODE_EXTERN v8::MaybeLocalv8::Object New(v8::Isolate_ isolate, size_t length);
^
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:28:40: note: candidate expects 2 arguments, 1 provided
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:31:40: note: v8::MaybeLocalv8::Object node::Buffer::New(v8::Isolate_, v8::Localv8::String, node::encoding)
NODE_EXTERN v8::MaybeLocalv8::Object New(v8::Isolate_ isolate,
^
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:31:40: note: candidate expects 3 arguments, 1 provided
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:36:40: note: v8::MaybeLocalv8::Object node::Buffer::New(v8::Isolate_, char_, size_t, node::Buffer::FreeCallback, void_)
NODE_EXTERN v8::MaybeLocalv8::Object New(v8::Isolate_ isolate,
^
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:36:40: note: candidate expects 5 arguments, 1 provided
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:43:40: note: v8::MaybeLocalv8::Object node::Buffer::New(v8::Isolate_, char_, size_t)
NODE_EXTERN v8::MaybeLocalv8::Object New(v8::Isolate* isolate,
^
/home/pi/.node-gyp/4.4.3/include/node/node_buffer.h:43:40: note: candidate expects 3 arguments, 1 provided
i2c.target.mk:86: recipe for target 'Release/obj.target/i2c/src/i2c.o' failed
make: *** [Release/obj.target/i2c/src/i2c.o] Error 1
make: Leaving directory '/home/pi/node_modules/node-ads1x15/node_modules/i2c/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.4.9-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/node_modules/node-ads1x15/node_modules/i2c
gyp ERR! node -v v4.4.3
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm ERR! Linux 4.4.9-v7+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "node-ads1x15" "--save"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the i2c package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs i2c
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls i2c
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/pi/work/tools/node-ads1x15/npm-debug.log
pi@smoke-pi:~/work/tools/node-ads1

always echo's out `is ads1115`

When I run your sample program, on every call to adc.readADCSingleEnded() it will echo out is ads1115 to STDOUT. Why is this, and how do I disable it?

Looks like it may be coming from node-i2c however not 100% sure.

Please add a license to this repo

Thank you for creating this library! Could you please add an explicit LICENSE file to the repo so that it's clear under what terms the content is provided, and under what terms user contributions are licensed?

Per GitHub docs on licensing:

Generally speaking, the absence of a license means that the default copyright laws apply. This means that you retain all rights to your source code and that nobody else may reproduce, distribute, or create derivative works from your work. This might not be what you intend.

Thanks!

The example code is missing } at the end

The example code you have on the main page is missing } at the end. And you get the following error
/home/user/node/i2c/example.js:29
);
^

SyntaxError: Unexpected token )
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

i.e. change it to this at the bottom
if(!adc.busy)
{
adc.readADCSingleEnded(channel, progGainAmp, samplesPerSecond, function(err, data) {
if(err)
{
//logging / troubleshooting code goes here...
throw err;
}
// if you made it here, then the data object contains your reading!
reading = data;
// any other data processing code goes here...
);
}
}

Received Callback twice

We are using the function "readADCDifferential()" (supposing it happens with others too) with our ads1115 chip in our product. To customers we are providing an npm environment as software interface so customer can use your code easily. It is working excellent.
For us it is obligatory to perform EMC tests to the analog inputs we connected to the ADS chip before we release a final product. During the EMC tests it happens that the I2C bus is disturbed as well and the communication across I2C may get interrupted.

This is why the readADCDifferential() function from time to time returns the error "We've got an Error, Lance Constable Carrot!: Error: Cannot write to device"

self.wire.writeBytes(ADS1015_REG_POINTER_CONFIG, bytes, function(err) {
      if(err)
      {
        self.busy = false;
        callback("We've got an Error, Lance Constable Carrot!: " + err.toString());
      }
    });

This is also fine so far ... but now comes the problem: even if the error was reported in the callback (and the write over I2C was not executed) the readADCDifferential() function continues to setup another I2C command "self.wire.readBytes()" in a setTimeout() function and finally we got another callback(null, data);
So with a single call to "readADCDifferential()", we receive two callbacks which is not ok. Also we are wondering which "data" is provided in the second callback if the previous write command failed.
Should be corrected. In case of a write failed a following read should never be executed.

trouble with i2c

I'm trying to install ads-1x15 on an raspberry pi .
node version: v10.16.1
npm version: 6.9.0
uname -m : armv6l

i2c is failing. I went to the i2c GitHub and there is an issue that is resolved with npm install @abandonware/i2c.
I installed this version. How do I tell npm to use it with npm install ads-1x15?

I2C bus needs exposed.

I am trying to use node-ads1x15 on the CHIP (http://www.getchip.com) and CHIP has multiple I2C buses. The one we want to use is /dev/i2c-2. This issue requests the exposure of the parameter that defines the bus on which the device can be found.

error Failed to set address

I tried your library for raspberry pi and ads1115. But when run I get error failed to set address for line wire.setAddress(address); in i2c.coffee file. I have attach code file and error
code file:
codefile

error file:
errorfile

Example 2 that can be added

// To run this do the following
//
// install modules
// npm install node-ads1x15 --save
//
//
// nodejs i2c.js
//
// Code test on a Pi3 and a AUTOMATION PHAT unit
// https://shop.pimoroni.com/products/automation-phat

var ads1x15 = require('node-ads1x15');
var chip = 0; //0 for ads1015, 1 for ads1115

//Simple usage (default ADS address on pi 2b or 3):
var adc = new ads1x15(chip);

// Optionally i2c address as (chip, address) or (chip, address, i2c_dev)
// So to use /dev/i2c-0 use the line below instead...:

//var adc = new ads1x15(chip, 0x48, '/dev/i2c-1');

var channel = 0; //channel 0, 1, 2, or 3...
var samplesPerSecond = '250'; // see index.js for allowed values for your chip
var progGainAmp = '4096'; // see index.js for allowed values for your chip

var ChData =[]; //somewhere to store our reading
var dev = 127; // used to change Ch data to Voltage

// Reading the ch data
var ReadCh = function(ch, callback){
adc.readADCSingleEnded(ch, progGainAmp, samplesPerSecond, function(err, data) {
if(err){
//logging / troubleshooting code goes here...
throw err;
}
// if you made it here, then the data object contains your reading!
ChData[ch] = data // Putting data into

//console.log ('channel  ' + ch + ': ' + data);
// Calling the next ch or done
callback();

});
}

// A way to make the reads run one after the other with callbacks
var Readchall = function(){ReadCh(0, Readch1)};
var Readch1 = function(){ReadCh(1, Readch2)};
var Readch2 = function(){ReadCh(2, Readch3)};
var Readch3 = function(){ReadCh(3, ChDone)};
var ChDone = function(){
// This is run after the 4 ch have been read
console.log ('CH1: ' + (ChData[0]/dev).toFixed(2) +
'\tCH2: ' + (ChData[1]/dev).toFixed(2) +
'\tCH3: ' + (ChData[2]/dev).toFixed(2) +
'\tCH4: ' + (ChData[3]/dev).toFixed(2) );
};

if(!adc.busy)
{

// Readchall(); // - one Time Read read all 4 ch

// OUTPUT
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60

iv = setInterval(Readchall, 500); // Repeat every 500msec
// 100 (every 100msecs or 10 times a sec) is the max with this program
// will do with 4 ch being run each time and the Sample rate (On a pi3).

// OUTPUT
// CH1: 5.15 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 5.15 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60
// CH1: 0.03 CH2: 0.03 CH3: 0.03 CH4: 4.60

}

delay readADCSingleEnded too short

I found strange behaviour of readADCSingleEnded, which produces random result sometimes. After I tried to increase the delay, about 10ms, random results didn't appear anymore. Could you please evaluate the formula which calculates the amount of delay for readADCSingleEnded function? Just curious, maybe it didn't produces proper value.

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.