SPI support for Thermocouple

255 views
Skip to first unread message

Brad Hopper

unread,
Jul 18, 2016, 7:17:58 PM7/18/16
to Node-RED
Hey guys a lot of sensors use SPI for communication, for example the thermocouple board I just picked up from Amazon.

I'm not sure why half of sensors use i2c, which is well supported by NR and half use SPI which appears to be unsupported, but there it is.

Meanwhile the TC board I got is based on the Max31855, for which there exists a NodeJS library called:

Thermocouplelib-max31855

Which can be installed using NPM. I'm not sure this library, which was written for the Tessel board (Sam processor) will work in my case (on Raspberry Pi 2 and Zero but it seems worth a try.

I'll post the exact attempts and errors I'm getting but basically I can't figure if I'm using the right syntax for setting a node module in the global settings, then if I'm calling it right and then how to troubleshoot what's going wrong.

Anyone else use any other approaches for controlling SPI sensors on raspi?

bho...@tibco.com

unread,
Jul 18, 2016, 9:20:56 PM7/18/16
to Node-RED
OK, so here's a link to the library on NPM:


I installed per the instructions there, then added it to global context like so:

functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false}),
           thermocouplelib:require('thermocouple-max31855')
    },

The example says to call it like this:

var thermocouplelib = require('thermocouple-max31855');
var sensor = thermocouplelib.use(port, { /* options */ });

so, since the module is already in global context, I called it like this in a function node:

var sensor = context.global.thermocouplelib.use(21);  
msg = sensor.read();
return msg;

[Could be that my "port" isn't right above or that the underlying code isn't right for grabbing an raspi gpio in the first place...]

I find it hard to believe it could be that easy, and I guess is isn't :-) since I get this error:

TypeError: Cannot read property '0' of undefined

Not really sure how to further troubleshoot the issue. Any ideas?

Dave C-J

unread,
Jul 19, 2016, 3:26:38 AM7/19/16
to node...@googlegroups.com

If be very surprised if the tessel code just works on a pi....
I think you'd be better off starting with some SPI code for pi, and building on that. Eg http://git.drogon.net/?p=wiringPi;a=blob;f=examples/max31855.c;h=2060a5592cfb9e9d102c9648f5297c55bb11d07b;hb=f6c40cb2a69a43de97903c9fdd6f24a4f32f8eae
And then either call that via an exec node, or start to wrap that into a node file.

Reply all
Reply to author
Forward
0 new messages