Node-red-contrib-i2c fails to install

That's what I think (In fact I posted that on the issue on github about 20 mins ago) :slight_smile:

Its all seems to fully work with me using an i2c Pi add-on board (4tronix PiCon Zero)

I can configure inputs to read anlog values and I can make an output switch between 1 and 0 to control a LED
image

:slight_smile:
Logic looks OK (but this i2c node is not very user friendly)

Can I suggest starting a new thread on your specific problem (as this one is about getting the node working at all) and we can go into detail there?

That makes sense.

new topic : Pulling readings from i2c chip into Node-Red

Are you referring to Java or JavaScript? In any case, if you want to write in C, it isn't hard to link your code to Node-RED.

I use to put cpu performance code into the Korn Shell. I just would like to revisit a discussion I had with Bill about pulling in optimized hardware code functions outside the run time compiler.

Anyone got any ideas how to avoid the run time compiler to use some of the better written optimized i2c C functions. I keep seeing issues related to munging up the i2c bus due to timing mismatches.

As a long-time writer of device drivers, I agree it would be madness to rely on any kind of JIT for low-level device access. However the "-contrib-i2c" node appears to have all its driver interface functionality in C++, so possibly the timing issues are coming from the interop layers.

I'd suggest contacting the node's author to see if there are any timing or usage constraints which you might be running into. If that doesn't work out, then you could possibly write a custom node, moving any timing-critical logic into C/C++, and accessing the I2C driver directly.

Has anyone actually done any raw i2c testing on the Pi? It may well be that performance isn't terribly hot anyway.

Remember, the Pi was designed for teaching not for industrial use. The GPIO design on the Pi is actually rather weak I believe.

Certainly, I've never even bothered trying since a general purpose OS like Linux doesn't really sit all that well with the near real-time requirements of GPIO. I've always found it a lot easier to use an Arduino or ESP8266/ESP32 for hardware interfaces. Even though it meant that I've had to learn some C/C++ along the way.

I regularly see people struggling with the Pi GPIO and resorting to Python to try and get things working but this stuff is so cheap now that a couple of dollars spent on an ESP8266 seems like a no-brainer.

1 Like

Linux and Windows are definitely not real-time operating systems, but carefully designed kernel-level device drivers should be able to handle the requirements of even quite demanding devices. The question of where you draw the divide between driver and user functionality is crucial though, and if you leave any kind of time-critical stuff to the user level it will almost certainly fail at some point. (I speak from experience :wink:)

Indeed - I've gone down this route extensively, and nearly all my devices are/will be ESP8266-based, using MQTT to communicate.

That said however, an RPi, if it's not overly loaded with a mass of other tasks, should easily be up to running I2C and Node-RED together. It would be interesting to see some performance tests on various models with similar software setups...

Molesworth, contrib-i2c is using i2c-bus for the low level. Where are you seeing C++ in contrib-i2c?

I now see where i2c-bus has its cc files and plan on exercising them once I can get contrib-i2c to show up in node red console.

My local NPM list it properly installed, but I can see the nodes in node-red. Any ideas as to how to fix this?

node-red-contrib-i2c still needs to resolve the GIT version with the NPM version so I can pull it in to the palette within the console and not with NPM on the command line.

One other thing NPM seems to stop processing the flows after 18-36 hours. Is there any issue with the virtual machine size? This looks a lot like java running out of space. On RPI I think there is a 256 value set I haven't looked into. Not that I'm not an expert on this, but I would like to know if this is known before wasting time looking at this, once I figure out how to get some sort of working dtrace package.

40 years of reading opcode...Woohoo....

The page for node-red-contrib-i2c has a section at the bottom which notes :

And includes a link to the Github repo - GitHub - fivdi/i2c-bus: I2C serial bus access with Node.js - which is the driver interface I was meaning. The node itself will be using an interop layer between C++ and Javascript, which is likely where the performance hit comes from.

1 Like

So, you are saying that 'node-red-contrib-i2c' does not work currently, but if I learn the i2c protocol, and how my chip responds to it I would be able to make a function node with java that would get the readings?

"YES" If we can get node-red-contrib-i2c updated from 0.5.2 to 0.5.5 on the NPM server. Its out of date

So we just need niels to push that version to npm ?

"YES" If we can get node-red-contrib-i2c updated from 0.5.2 to 0.5.5 on the NPM server. Its out of date

> Its all seems to fully work with me using an i2c Pi add-on board (4tronix PiCon Zero)

It is different on the Pi 4 4GB running latest Debian.

You can see from my listings I am where you are but the nodes don't show up inside the node-red console. For some reason it needs to be installed in the pallet manager to show up. If the NPM is updated then the install within the console should be a happy camper.

├─┬ node-red-contrib-i2c@0.5.5 (git+https://github.com/nielsnl68/node-red-contrib-i2c.git#ae3edb3830204c5fb1900777854acae7ee9eeded)
│ └─┬ i2c-bus@4.0.11
│ ├── bindings@1.5.0 deduped
│ └── nan@2.14.0 deduped

What model of Pi are you trying to get it to work on?

Is it running Stretch?

This is the newest Pi 4 with 4GB It requires the newest OS Debian Buster release. "IT IS DIFFERENT" !!!

https://www.raspberrypi.org/products/raspberry-pi-4-model-b/?variant=raspberry-pi-4-model-b-4gb

I installed my test version on the same machine as you - Pi4 4GB Buster

It all works for me using

cd /home/pi/.node-red
npm install https://github.com/nielsnl68/node-red-contrib-i2c.git

but my npm list looks different to yours

Can you try again with a brand new install?

Or like me Python for MCP9808

[{"id":"72c11be2.fdeb14","type":"python-function","z":"352b627d.9c316e","name":"MCP9808 I2C Inquiry","func":"import time\nimport Adafruit_MCP9808.MCP9808 as MCP9808\nimport os\n\nfrom unittest import TestCase, skipIf\nfrom time import time as now\n\n# Define a function to convert celsius to fahrenheit.\ndef c_to_f(c):\n\treturn c * 9.0 / 5.0 + 32.0\n\n# Default constructor will use the default I2C address (0x18) and pick a default I2C bus.\n#\n# For the Raspberry Pi this means you should hook up to the only exposed I2C bus\n# from the main GPIO header and the library will figure out the bus number based\n# on the Pi's revision.\n#\n# For the Beaglebone Black the library will assume bus 1 by default, which is\n# exposed with SCL = P9_19 and SDA = P9_20.\nsensor = MCP9808.MCP9808()\n\n# Optionally you can override the address and/or bus number:\n#sensor = MCP9808.MCP9808(address=0x20, busnum=2)\n\n# Initialize communication with the sensor.\nsensor.begin()\ntemp = sensor.readTempC()\n\ntempc = ('{0:0.3F}'.format(temp))\n\nmsg['topic'] = \"tempc\"\nmsg['payload'] = tempc\n\nreturn msg","outputs":1,"x":300,"y":70,"wires":[["9208f1fb.9caf8","c0562b67.8b2088"]]}]

Hello, a new node-red user here.

I had an installation fail of node-red-contrib-i2c 0.5.2 on my raspi 4.

Raspian Buster and nodered up-to-date today.
End of the debug-log:

...
151 verbose Linux 4.19.97-v7l+
152 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "--no-audit" "--no-update-notifier" "--save" "--save-prefix=\"~\"" "--production" "node-red-contrib-i2c@0.5.2"
153 verbose node v12.15.0
154 verbose npm  v6.13.4
155 error code ELIFECYCLE
156 error errno 1
157 error i2c-bus@1.2.5 install: `node-gyp rebuild`
157 error Exit status 1
158 error Failed at the i2c-bus@1.2.5 install script.
158 error This is probably not a problem with npm. There is likely additional logging output above.
159 verbose exit [ 1, true ]

However I can confirm, that node-red-contrib-i2c 0.5.5 directly from git seems to work (at the moment just tested the i2c scan node. Installation:

~/.node-red $ npm install --unsafe-perm https://github.com/nielsnl68/node-red-contrib-i2c

> i2c-bus@4.0.11 install /home/me/.node-red/node_modules/i2c-bus
> node-gyp rebuild

make: Entering directory '/home/me/.node-red/node_modules/i2c-bus/build'
  CXX(target) Release/obj.target/i2c/src/i2c.o
  SOLINK_MODULE(target) Release/obj.target/i2c.node
  COPY Release/i2c.node
make: Leaving directory '/home/me/.node-red/node_modules/i2c-bus/build'
+ node-red-contrib-i2c@0.5.5
added 2 packages from 2 contributors and audited 2159 packages in 19.962s

3 packages are looking for funding
  run `npm fund` for details

found 9 vulnerabilities (2 low, 1 moderate, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details

After "systemctl restart nodered" I see the i2c nodes in the palette and the palette manager.

Triggering the i2c scan node with a timestamp inject and debugging the msg.payload shows the addresses of my two i2c devices at address 32 (0x20) and 39 (0x27) (these are two PCF8574 port expanders):

[ 32, 39 ] 14/2/2020, 13:37:29node: 3fb33af4.40472emsg.payload : number 32 14/2/2020, 13:37:29node: 3fb33af4.40472e msg.payload : number 39

Would be nice, if v0.5.5 could be installed from the palette-manager.

Thank you all in this helpful thread!

hey @ll,

I'm new in the Raspbian and nodered world.
I also tried to install the i2c-bus and tried all your solutions, but its still not working.

~/.node-red $ npm install --unsafe-perm node-red-contrib-i2c

and this is the end of the debug-log:

make: *** [i2c.target.mk:111: Release/obj.target/i2c/src/i2c.o] Error 1
make: Leaving directory '/home/pi/.node-red/node_modules/i2c-bus/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 4.19.97-v7+
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/.node-red/node_modules/i2c-bus
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v5.0.7
gyp ERR! not ok 
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! i2c-bus@1.2.5 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the i2c-bus@1.2.5 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2020-03-02T21_00_52_811Z-debug.log

I'm using the newest version of nodered v.1.0.4