INA219/ESP8266 and Node Red

tmpB2D1In a previous blog entry we were playing with the INA219 voltage and current monitor. Here I team the little board up with the ESP8266 and Node-Red.

In this entry, I have teamed up the INA219 with my ESP8266 code which already has a driver in for this chip and also has support for the SSD1306 – hence, thanks to MQTT, this little combined chip can easily show the current status on the on-board display and also show it on a Node-Red dashboard in gauges and also a combined graph.

Please note that I have updated the ESP8266 code (v2.3.15) and changed how this works as I ended up writing way too fast to the device… this code works.

Power MonitorOf course that’s how I’ve done it – armed with info you can do any variation you like. I’ve set the graph limits here to 6 volts, I guess it would make sense to set it to 30v.

I’m also using a 1 second inject node, perhaps something more flexible and externally programmable would be better – in which case you could have different graphing speeds. Nice for checking battery charging?

As my ESP8266 code (documented on the blog – see right menu, ROMS available, recently updated) already does all the display and INA219 handling, everything was done in Node-Red.

 

Power Monitor

Here is the code for “Process Chart”

var ina=JSON.parse(msg.payload);
var msg1={};
var msg2={};
var v=Math.round((ina.voltage/1000.0)*100)/100;
var a=Math.round((ina.current/1000.0)*100)/100;
var w=Math.round((v*a)*100)/100;

msg.payload=v; msg.topic=”voltage”;
msg1.payload=a; msg1.topic=”current”;
msg2.payload=w; msg2.topic=”watts”;
msg3.topic=”ssd1306/toesp”;
node.send([msg,msg1,msg2]);

The injector node has a topic of ina219/toesp (assuming you set the ID of the board to “ina219” of course) and a payload (string) of:

{ina219_getall:1}

The 1 on the end implies a 64 pixel high ssd1306 display attached, a 0 would imply a 32 pixel high display and no parameter would assume no display and simply send the information out. Initialisation of the INA219 and optionally the display happens at first use – no need for separate init.

I’ve now added range adjustment – you MUST have the latest node-red-dashboard for this…

msg.ui_control=msg.payload;
msg.payload=””;
return msg;

In the case of setting the maximum range to 6 – the payload for that button (drop down and select JSON) is {“ymax”:6} – have as many as you want!!

And that’s it  – simples…

I’ve not shown current here as I need to lower that LOAD resistor on the INA219 but you will normally see voltage, current and power in that graph! Once I figure out how to correctly reprogram the chip I’ll add that into the ESP8266 INA219 code.

I have some 0.025R resistors on the way but from China so it’ll be weeks. Meanwhile of course this is perfectly usable.

The first version of the software proved unreliable and so anyone who first looked at this may have noticed I’ve updated the ESP software. The current version I have sitting on a window on my PC.

It has now been running at 1 sample per second for the last 96 hours without a glitch. At some point I’ll add disk (sqlite most likely) logging – though in Node-Red that is simple enough to do.

Facebooktwitterpinterestlinkedin

12 thoughts on “INA219/ESP8266 and Node Red

  1. Hi Pete, I’m looking to connect an INA219 directly to a raspberry pi zero via I2C. Have you tried this?

    If you have any advice on how to communicate with it through Node-Red, I would appreciate your input as there doesn’t seem to be any software nodes out there that I can install (I’m new Node-Red and don’t have a lot of developer experience).

    best. Paul

    1. I do my peripheral chips such as INA219 via ESP8266 talking to PI with MQTT. I’m sure putting the init code for that chip into a PI would not be difficult but I’ve not tried it yet.

    1. I have updated the blog entry accordingly with range buttons – that is just magic. I’ve also put a warning that node-red-dashboard needs to be up to date.

    1. Check Aliexpress and Banggood for “wemos oled”. Make sure it is the sane one. Ref to D1 and D2 on the back for i2c.

Comments are closed.