"Have a MPL115A2 Sensor? And..."

Well, every single node module I found for node.js or NR that supports the MPL115A2 sensor chip, is either very old and broken over time, fails to compile, and/or seems to refuse to load into npm, etc.

Moreover, the MPL115A2 is one of the most straight forward temperature and pressure sensor chip via i2c to use. Below is an i2c-bus module based flow that requests the temperature and pressure values from the MPL115A2 sensor chip.

[{"id":"bb08d7e6.bd7cf","type":"i2c in","z":"654b54e5.8fec74","name":"","busno":"1","address":"96","command":"4","count":"8","x":230,"y":80,"wires":[["876ca385.9fcf3"]]},{"id":"82407e4e.d8386","type":"inject","z":"654b54e5.8fec74","name":"Invoke","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":80,"wires":[["bb08d7e6.bd7cf"]]},{"id":"9a68a6c.5587158","type":"debug","z":"654b54e5.8fec74","name":"Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1160,"y":80,"wires":[]},{"id":"b559c614.dd1bc","type":"i2c out","z":"654b54e5.8fec74","name":"","busno":"1","address":"96","command":"18","payload":"payload","payloadType":"msg","count":"1","x":530,"y":80,"wires":[["26150518.9a9fd2"]]},{"id":"876ca385.9fcf3","type":"function","z":"654b54e5.8fec74","name":"Calculate","func":"const EMPTY = '';\n\nvar theData = msg.payload;\n\nmsg.A0 = (theData[0] * 256 + theData[1]) / 8.0;\nmsg.B1 = (theData[2] * 256 + theData[3]);\n\nif (msg.B1 > 32767) msg.B1 -= 65536;\nmsg.B1 = msg.B1 / 8192.0;\n\nmsg.B2 = (theData[4] * 256 + theData[5]);\nif (msg.B2 > 32767) msg.B2 -= 65536;\n\nmsg.B2 = msg.B2 / 16384.0;\nmsg.C12 = ((theData[6] * 256 + theData[7]) / 4) / 4194304.0;\n\nmsg.payload = EMPTY;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":80,"wires":[["b559c614.dd1bc"]]},{"id":"26150518.9a9fd2","type":"delay","z":"654b54e5.8fec74","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":690,"y":80,"wires":[["99fc88a.6bdb4f8"]]},{"id":"99fc88a.6bdb4f8","type":"i2c in","z":"654b54e5.8fec74","name":"","busno":"1","address":"96","command":"0","count":"4","x":850,"y":80,"wires":[["5c612eb2.898bb8"]]},{"id":"5c612eb2.898bb8","type":"function","z":"654b54e5.8fec74","name":"Convert","func":"var theData = msg.payload;\nvar thePressure = ((theData[0] * 256) +(theData[1] & 0xC0)) /64;\nvar theTemperature = ((theData[2] * 256) +(theData[3] & 0xC0)) /64;\n\nvar theConversion = msg.A0 + (msg.B1 + msg.C12 * theTemperature) * thePressure + msg.B2 * theTemperature;\n\nmsg.celsius = (theTemperature - 498) / (-5.35) +25;\nmsg.pressure = ((65.0 / 1023.0) * theConversion + 50) * 10;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1000,"y":80,"wires":[["9a68a6c.5587158"]]},{"id":"3007934b.030d54","type":"comment","z":"654b54e5.8fec74","name":"Reference MPL115A2 Data Sheet For Details","info":"","x":190,"y":40,"wires":[]}]

The above is also a fair example of how to leverage the i2c-bus module. Which can be a real challenge at times, given that some i2c connected devices do some interesting things in communicating.

The setup is typical i2c device connection to Pi, or any i2c supported device, connect 3.3v, GND, SCL, SDA per the MPL115A2 data sheet, add i2c-bus module to NR, and import the above flow. Enjoy!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.