node-red-contrib-iiot-rpi-ads1115 2.0.5
A Node-Red node for ads1115 analog to digital converter
A Node-Red node for 16bit ads1115 analog to digital converter
Example ads1115 hat from joy-it
Example ads1115 module
Installation
Install with Node-Red Palette Manager or npm command:
cd ~/.node-red
npm install node-red-contrib-iiot-rpi-ads1115
Nodes
- iiot-ads1115: Sends adc inputs as number array.
- iiot-ads1115-m: Sends adc inputs as number on each multiple outputs.
Usage
- Read is triggered on cycle.
- To prevents locks only one node is allowed per i2c address.
- Input voltage more than VCC can damage adc input.
- The output values are mV or adc raw data.
- This node works on Raspberry Pi with 32bit or 64bit OS.
- Enable I2C with raspi-config.
I2C Address | ADDR Pin |
---|---|
48H | GND or open |
49H | VCC |
4AH | SDA |
4BH | SCL |
Array Index
Input | Array-Index |
---|---|
A0 | 0 |
A1 | 1 |
A2 | 2 |
A3 | 3 |
Example
This example reads current and voltage from the analog to digital converter.
Input A0 is current with Input-Range 0..2048mV in array msg.payload[0].
Input A1 is voltage with Input-Range 0..2048mV in array msg.payload[1].
Input A2 and A3 are disabled.
Raw values are scaled to engineering values.
Power is calculated.
The toFix function cuts decimals after point.
Each engineering value is send to output.
In Node-Red Dashboard, these are displayed in a gauge.
JavaScript Code in Function Node:
// Rounds number to fix decimal after point.
// https://www.jacklmoore.com/notes/rounding-in-javascript/
function toFix(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
// scale raw data to engineering value
function scale(raw_value, input_min, input_max, output_min, output_max)
{
var factor = (output_max - output_min) / (input_max - input_min);
var offset = output_min - (input_min * factor);
return (raw_value * factor) + offset;
}
var current = scale(msg.payload[0], 0, 2048, 0, 5); // scale currtent 0..5A
var voltage = scale(msg.payload[1], 0, 2048, 0, 50); // scale voltage 0..50V
var power = current * voltage; // calculate power
return [
{ payload: toFix(current, 1) }, // output 1
{ payload: toFix(voltage, 1) }, // output 2
{ payload: toFix(power, 2) } // output 3
];