Archive | March 2017

Stepper Gauge

VID_20170316_082442-2

Today seemed like a good day for cleaning out junk drawers, and I’m proud to say I successfully completed half that job!  While looking through the heaps of crap I absolutely need, I came across a questionable stepper motor driver and stepper motor. Odds are the reason I had it is because it doesn’t work, but of course I’m not going to throw it out without testing, and with a three year old repeatedly asking “what’s that?” it seemed like I had no choice but to hook it up and start screwing around.

2017-03-16 09.02.372017-03-16 09.02.19

The stepper driver is a pretty standard type, it takes two input signals, one tells it which way and the other says how many. Steps that is. So where do I get these signals? I have a raspberry pi that floats around my bench that I can make use of when I need some GPIO. Ignore the rainbow of other wires going to the right in the photo, they’re from another project that I can’t disconnect because I’m totally going to finish it someday. The only ones that matter here are the three wires going southbound. Those three wires are STEP, DIR, and GND.

2017-03-16 09.04.28

The only thing left was motor power. If you’re looking for something to add to your test bench at home, go to ebay and pick up one of these XL6009 step up DC-DC converters and stick a couple 2.1mm barrel connectors on each end. (pick up a couple 10 packs of 2.1mm barrel connectors too while you’re there.) So handy. It turns any wall wart you have kicking around into an adjustable voltage source. I used mine to boost from my 12v adapter to the 24vdc that this motor requires.

2017-03-16 09.03.53

Here’s the whole package assembled. Nothing to it really.

2017-03-16 09.09.44

The other only thing left was to hack up some software. Toggling the outputs manually proved that the drive and the motor worked. I can move the motor. But then what? Steppers are so easy, all you need to do in order to make them move is turn that STEP line  on and off a bunch of times and the motor will move 0.1 degree that same bunch of times, so the code is kind of boring. The fun had to come from what numbers to send. The pi was connected to the same wifi that my thermostat/gaslogger/powelogger was on, so I had plenty of numbers to choose from. Using my socket for realtime power monitoring  seemed like the most logical choice, so the code below was the result. It polls the power consumption every two seconds and moves the stepper 1 step per watt. I threw a little cardboard pointer on it to make it easier to see the movement.

2017-03-16 18.19.10

Then I added a cardboard backing to make it even more gauge like….. This is the gif from before my assistant helped out with some decorations. Aww yeah, that’s some awesome, shoddy ass gauge at work.

VID_20170315_185341-2

I was really entertained by this bout of screwing around, it made for a fun afternoon. More entertained than my kid it seems….something about having to turn on the microwave, or wait for the furnace to start before seeing anything happen wasn’t compatible with her attention span I guess. Maybe I’ll hook a joystick up to it or something for a bit more instant gratification, or I’ll just cut up more cardboard for drawing on…yeah, probably the cardboard thing.

It is worth noting that you can make up something like this really damn cheap these days. On ebay, an equivalent stepper driver can be had for around 2$, stepper motors anywhere from 5$ to 20$ depending on how much you need to move. Stick a 5$ esp8266 based controller on there and you can have a wifi connected stepper, or steppers, somewhere in your house doing…. I dunno… something!?

The python code is pretty simple, but it’s available here if you’re interested

Power Logger

With a design along the same lines as the Gas Sensor Logger, I made up a power consumption monitor for the house.
I installed 4 clamp on current transformers in my panel, one on each of the 230v legs coming in, and two that can be clamped on any circuits of interest. With the transformers and an arduino wired up pretty much exactly as described at this link I was able to load up a sketch that would provide a accumulated total of power consumed.

 

The arduino is connected to one of the USB ports on the raspberry pi that’s running my Thermostat Project, which means I was able to write an additional daemon that could poll the arduino for power measurements and log them to the same mysql database that all of my environmental data gets logged to. With that data being logged I’m able to make some pretty graphs to display power consumption.

The code for both the arduino and the raspberry pi side of things is on github at https://github.com/rhasbury/GasSensorLogger. I might break it into its own repo at some point but for the moment the two are so similar they can hang out in the same place.

I found that having the graph for reviewing the days consumption was cool, but for finding out what the different items in the house draw I really wanted to have a gauge with a needle, so one addition to the power logger that isn’t in the gas logger is a tcp socket that is made available for requesting realtime (down to ~2 sec) power measurements. If you send a “get_powers” string to port 50008 on the pi it’ll send you back a json string like so:

{“onetwentywatts”: 676.87, “clamp1watts”: 97.17, “clamp2watts”: 12.43, “twofortywatts”: 226.56, “totalwatts”: 903.43}

So with the help of a php script and some borrowed d3 code I got something rough put together. These are hosted on that same thermostat pi, so these graphs and gauges are available to any device connected to the lan. It’s nice to have this graph on my phone while I’m wandering around trying to figure out what’s burning so much power!!$!$$

The code for the graphs and gauges are in the github repo as well, under the rpi/http folder.