2.0.5 • Published 1 year ago

node-red-contrib-iiot-rpi-ads1115 v2.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

node-red-contrib-iiot-rpi-ads1115

platform platform NPM version NPM Donate

A Node-Red node for 16bit ads1115 analog to digital converter

image info

Example ads1115 hat from joy-it

image info

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 AddressADDR Pin
48HGND or open
49HVCC
4AHSDA
4BHSCL

Array Index

InputArray-Index
A00
A11
A22
A33

CHANGELOG

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.payload0. Input A1 is voltage with Input-Range 0..2048mV in array msg.payload1. 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.

image info

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  
];
2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.1

1 year ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago