Going With the Flow
Sometimes victory is hard-won. Other times it just requires patience and laziness.
Way back in 2016 I bought Adafruit's breakout board for the INA219 high-side current sensor so that I could play around with measuring current. Sure, I can do that with my multimeter, but with the actual sensor I can do it with an Arduino, and maybe build this in to a project.
You may have noticed that the way I've been talking about it indicates that I never finished any such project. Very astute. I'll continue.
As is common in such things, I took on multiple challenges at the same time so when I ran in to a roadblock I banged my head against it rather than use a simpler solution. Specifically, I wanted to do two things other than just make it work: I wanted to use a Nokia 5110 LCD (because they're cool) and I wanted to learn about Espruino, a microcontroller like Arduino which uses Javascript as its language. (Yeah, that's a whole other conversation. Let's just say I wanted to and not get into reasons why, whether those reasons are valid, and so on. If you have issues with Javascript on a microcontroller there's a comment section here.)
Getting the LCD to display was no problem, but at the time I started looking at this there was no ready-made library for interfacing the INA219 with the Espruino. I didn't think there would be a problem there, as I had two libraries to refer to: one was a Javascript library in NPM that is suited for Raspberry Pi but which did not work for Espruino, and the other is a C library for Arduino. Even if those didn't exist, INA219 is an I²C device, and so how hard could it be to write an interface for an I²C device?
I can't tell you exactly what I did wrong, but this wasn't my top priority so when it didn't work out, the project went on the shelf. I revisited it a couple of times over the years and I didn't get anywhere. Maybe I should dig up that code, because when I sat down this time, I saw there was an issue with the wiring. I had connected the INA219 SCL and SDA pins to pins B9 and B12 on the Espruino (Original) when I thought I had connected them to B8 and B9. B12 is not a I²C-capable pin, and besides, I was using B8 for the Nokia LCD.
I can't swear that that was the issue in the past since I may have pulled the board or some jumpers off of the solderless breadboard and put them back. But that was an issue when I picked the project back up and dusted it off yesterday evening.
However, I only discovered the miswiring because I got a very clear error message about B12 not being I²C-capable, and I only got that error message because in the time that this project was gathering dust on my unfinished projects pile, someone else wrote an Espruino module for the INA219.
This became quite an easy project, basically because someone else did the hard work. That's a little embarrassing but sometimes that's how a project shakes out. I was able to get it working in less than an hour using less than 50 lines of example code (found at Pico LCD Hello World and espruino.com's INA219 page.)
I apologize to anyone finding this article when looking for information about how to use the INA219. I don't have any information that isn't already easily available. It's just a proof that I can do something with this sensor. That's all I need right now. There are a number of projects that I can use this for, including making a better test platform for power supplies. Those will require actual effort.
It always feels good to succeed where I'd run into problems in the past. It's nice to take a job off of my to-be-done-someday list. I admit that it feels a bit like cheating to simply wait several years until someone else did the real work, but it's not like I'm saying that's a good plan. It's just nice that it actually worked out. Now I can get on with the business of actually designing something that uses this sensor.