In 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.
Of 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.
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.
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
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.
Thanks for your feedback Peter. I’ll keep pushing ahead. best. Paul
Hi Paul
I have been chasing a solution for the same thing. Did you have any success?
Pete, with latest dashboard you can use a msg to dynamically set ranges etc, see https://github.com/node-red/node-red-dashboard/blob/master/config-fields.md
Oh that is just…. STUNNING – thank you so much!!!
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.
Very informative, as always Pete. Where did you get that Wemos with the OLED display, I would love to get my hands on one?
Check Aliexpress and Banggood for “wemos oled”. Make sure it is the sane one. Ref to D1 and D2 on the back for i2c.
Ordered! Thanks Pete.
i’ve found them this summer, while looking for cheaper alternatives to official Deauther device: https://www.tindie.com/products/lspoplove/wifi-deauther-oled-v25-case-and-antenna/
which, as it’s opensource, you can replicate with those wemos+oled and the firmware: https://github.com/spacehuhn/esp8266_deauther
Which board should I choose in the Arduino IDE?