Since my name was bandied about (grin) I've attached my Spin code for the INA219 (which I have tested and deployed in client projects) -- might be a useful reference. I2C on a standard BS2 is possible with SHIFTOUT and SHIFTIN and a little extra work. Most of us have done it. Not saying that porting the INA219 code to the BS2 will be easy, but it should be possible.
Jon,
Quick question on your code just for calrity...was this by design/intentional? The constant and comment seem to be backward? It's probably just me over-thinking it.
BRNG_32 = 1 << 13 ' 16V bus range
BRNG_16 = 0 ' 32V
Hey everyone, your code submissions were checked/tested by myself and added to the Downloads & Documentation section of the INA219 product page by Courtney Jacobs. https://www.parallax.com/product/29130
Thanks for your contributions to the source code bit-bucket!
Despite being behind in developing a code sample for this project ( really, it was the post office!), I am appreciative of Ken sending along a current sensor module for development.
So, by way of contributing, I spent a bit of time expanding the ability of the current sensor to measure much larger AC currents.
I was able to use the code developed in this thread, changing only the pins used by the Stamp and changing the displayed "mA" to "Amps".
I've attached the schematic and a few pics. Start with the schematic. Thanks iPhone, they will be upside down!
Fair warning: this circuit and measuring technique assumes you have good understanding of the risks of working around high voltage and current.
Basically, I used a standard industrial current transformer to safely sense the current in the high voltage AC circuit. Normally, a current transformer ( CT ) is meant to feed its secondary into a low impedance AC circuit like an ammeter or other transducer. However, over the years I've successfully taken the secondary circuit and rectified and filtered the signal to give a reasonable DC voltage signal suitable for feeding a microprocessor. In keeping with the need to NEVER let the secondary of a CT to become an open circuit while current is flowing in the primary, you will see two zener diodes across the CT secondary. They limit the possible output voltage to around 19 volts which is safe for the ina219.
With the ina219, the CT's rectified signal drives a current through the calibrating resistor ( about 3.6 K ohms, in my case ) which takes into account the turns ratio of the CT primary to Secondary and the fact that we want the display in Amps, not mA. You could also make the calibrating resistor smaller and let the Stamp provide a suitable scaling factor.
Tom, a nice adaptation and good work from everyone. Current measurement can be tricky but if you can control an output based on a current level you can design some very sophisticated devices, overload detection or viscosity measurement are just two that come to mind. Thanks for sharing.
Thank you very much to all who have contributed (and even those who tried, but had to wait for USPS). You saved us a lot of development work and made it a lot easier for Chris - while he can write this code I've got his schedule fully booked with a number of projects! Thanks Chris for harvesting and sorting through the code, getting the final versions to our web site.
Now that this is done, what kinds of code examples do we need for other products?
What happened to the Microcontroller KickStarts on Learn?
The simplicity and no nonsense of the KickStarts make it a great resource for teachers and students.
Some of the more complex devices such as the INA219 would be easier to use in classroom environment in a KickStart-like format.
For example, INA219 low voltage measurements using batteries and stripped-down code.
The Microcontroller KickStarts are also a great way of testing hardware to make sure it's working properly.
What happened to the Microcontroller KickStarts on Learn?
The simplicity and no nonsense of the KickStarts make it a great resource for teachers and students.
Some of the more complex devices such as the INA219 would be easier to use in classroom environment in a KickStart-like format.
For example, INA219 low voltage measurements using batteries and stripped-down code.
The Microcontroller KickStarts are also a great way of testing hardware to make sure it's working properly.
We're happy to accept new ideas or submissions for the KickStarts, too. If there's anything you'd like to see that we're not providing just let us know.
Comments
Jon,
Quick question on your code just for calrity...was this by design/intentional? The constant and comment seem to be backward? It's probably just me over-thinking it.
Thanks for your contributions to the source code bit-bucket!
Well, between USPS and Canada Post, I just received my current sensor and seemed to have missed most of the fun!
Will hook it up and see if I can find an interesting angle to exploit. Will report as required!
Cheers,
Tom SIsk
Despite being behind in developing a code sample for this project ( really, it was the post office!), I am appreciative of Ken sending along a current sensor module for development.
So, by way of contributing, I spent a bit of time expanding the ability of the current sensor to measure much larger AC currents.
I was able to use the code developed in this thread, changing only the pins used by the Stamp and changing the displayed "mA" to "Amps".
I've attached the schematic and a few pics. Start with the schematic. Thanks iPhone, they will be upside down!
Fair warning: this circuit and measuring technique assumes you have good understanding of the risks of working around high voltage and current.
Basically, I used a standard industrial current transformer to safely sense the current in the high voltage AC circuit. Normally, a current transformer ( CT ) is meant to feed its secondary into a low impedance AC circuit like an ammeter or other transducer. However, over the years I've successfully taken the secondary circuit and rectified and filtered the signal to give a reasonable DC voltage signal suitable for feeding a microprocessor. In keeping with the need to NEVER let the secondary of a CT to become an open circuit while current is flowing in the primary, you will see two zener diodes across the CT secondary. They limit the possible output voltage to around 19 volts which is safe for the ina219.
With the ina219, the CT's rectified signal drives a current through the calibrating resistor ( about 3.6 K ohms, in my case ) which takes into account the turns ratio of the CT primary to Secondary and the fact that we want the display in Amps, not mA. You could also make the calibrating resistor smaller and let the Stamp provide a suitable scaling factor.
Jeff.
Now that this is done, what kinds of code examples do we need for other products?
Ken Gracey
What happened to the Microcontroller KickStarts on Learn?
The simplicity and no nonsense of the KickStarts make it a great resource for teachers and students.
Some of the more complex devices such as the INA219 would be easier to use in classroom environment in a KickStart-like format.
For example, INA219 low voltage measurements using batteries and stripped-down code.
The Microcontroller KickStarts are also a great way of testing hardware to make sure it's working properly.
They are still on learn.parallax.com:
http://learn.parallax.com/KickStart?utm_content=bufferf6083&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer
We're happy to accept new ideas or submissions for the KickStarts, too. If there's anything you'd like to see that we're not providing just let us know.
Ken Gracey