A simple current sensor visualization app

INA219_RPi_VBNet

So what do you do when you want to buy a uCurrent Gold but it’s not in stock? Search for a (temporary) alternative. So that’s what I did and the screenshot above shows what this alternative produces 🙂

An Adafruit INA219 Breakout Board, a Raspberry Pi, a Python script for doing the i2c to the INA219 and MQTT on the RPi, an MQTT broker and a VB.Net app on my Windows machine to collect the data and visualize it with a Chart control. (BTW, the uCurrent Gold has been ordered just a few hours ago – it’s in stock again!)

Most of the time was lost on trying to get the INA219 to work with a Devantech USB-ISS but I didn’t manage to get it working for some strange reason. I even used a BugLogic to analyze the i2c traffic – all I saw were NAK‘s and the USB-ISS I2C_TEST command always returned 0 too; weird.

After I decided to drop the USB-ISS for this and moved to a Raspberry Pi everything went much better. Enabling i2c on the RPi, Python (pip), installing mosquitto, INA219 Python library and I was almost ready – but still not knowing whether this would actually produce something useful…?

The example Python script only needed to be changed a bit:

#!/usr/bin/python

from Subfact_ina219 import INA219
import time
import mosquitto

print 'Starting ...'

def on_connect(self, rc, res):
  print 'Connected'

#On recipt of a message create a pynotification and show it
def on_message(self, data, msg):
  print("%s, %s" % (msg.topic, msg.payload))

client = mosquitto.Mosquitto("ina219", clean_session=True)
#define the callbacks
client.on_message = on_message
client.on_connect = on_connect

client.connect("192.168.10.179", 1883)

ina = INA219(0x41)
client.subscribe("inacommand", 2)

while True:
  try:
    value = ina.getCurrent_mA()
    client.publish("inadata", "%.5f" % value  , 0)

  except KeyboardInterrupt:
    print ' Exiting...Keyboard interrupt'
    break
    
  except:
    print 'unexpected error'

And I added a function to set the INA219 to max 16V and 400 mA and made that the default.

One item left: a tool to collect and visualize the measurements done by the INA219. Whenever I need a quick & dirty app with a form and some buttons I prefer VB.Net – it’s the easiest & quickest way to do small tasks like this. 130 lines of VB code is all it takes… I can expand this app with a lot of ‘extras’  like triggers, setting the INA219 to one of its 3 calibration modes, whether it should publish shunt-, bus- or current measurements and so on. Communicating with the INA219 connected to the RPi is simple, cause it’s done with MQTT 😉 But for now I think this app will suffice.

2-3 hours later I had the app finished for some first results as can be seen in the screenshot @ the top of this post. Apparently the VB.Net receives almost 2800 samples in a period of 5 seconds; that’s about 560 samples/second. Not bad… the screenshot is taken while the INA219 was measuring the current flowing through a 4.7kΩ resistor @ 5V.

Now it’s time to hook up a ESP8266 to the INA219 and start sampling! Don’t know when that will be though …

 

Switch to WordPress as Blog Engine

I was never really satisfied with my former Blog engine dasBlog, so i decided to switch to WordPress. Main concern was ofcourse how to get all my posts from dasBlog to WordPress. With some links and some tools i managed to get the most important posts over to WordPress without having to type them all over 🙂

http://www.aaronlerch.com/blog/2007/08/23/breaking-up-moving-blog-engines/

http://code.msdn.microsoft.com/DasBlogML

Drill down charts for Gas usage

I purchased Chartdirector recently. Not being satisfied with the charting software i used so far, i decided to go for this product after trying several others. I think i made the right choice 🙂

While moving to Chartdirector, i read all kinds of stuff about clickable charts, a feature i couldn’t use before. This could be a really good opportunity to try and do something about not being able to keep track of detailed information on data that was getting “old”. So i decided to create a page with 4 clickable charts to get from a year-based chart down to an hour-based chart:

Clicking on one of the bars above will instantly update a chart that displays the data for all the months in the selected year.

Clicking on one of the bars of the chart above, will instantly update a chart that displays the data for all the days in the selected month.

Clicking on one of the bars above will instantly update a chart that displays the data for all the hours in the selected day.

And that is where it ends, gas usage information is stored on an hourly basis, so here you are at the level at which the information is stored, just with 3 clicks…

Delaying startup execution

I run my Domotica-VM on Windows 2003. I call it the Domotica-VM, but it does much more than that; SQL Server 2005 and IIS are also running in that same VM. I still had an issue to resolve there, which was adding a startup-delay to my Domotica application.
Whenever the VM booted, my Domotica app just started to fast, immediately trying to connect to the SQL Server, which was just to busy at that moment to accept connections, resulting in a messagebox saying it couldn’t find the SQL Server. So i had to build in some sort of delay for starting up my Domotica app. First let SQL Server go through it’s process of starting up, and then my Domotica application.
The standard Windows 2003 Task Scheduler doesn’t have a delay feature, so i searched for some handy little piece of software that could take care of automatically starting up my Domotica application with a delay of let’s say half a minute.

I found an appllication called Xecutor that could do just that. It’s small, and it removes itself from memory when it has completed its tasks; just what i needed. Very neat. I’ll send them a postcard 🙂