LAN of things - power system

This is somewhat of an admission of failure. You can't easily pigeon-hole everything, and most real projects use commercial software, homebrew, and hardware all at once. So, for you makers out there (including me) - this is where to put whole projects that don't fit well in the other forums.

LAN of things - power system

Postby Doug Coulter » Fri Jul 17, 2015 1:56 pm

The first unit on the Lan of things monitors the building I'm now living in, and controls the water system as well. It's been working really well - I had over provisioned a few things back when it was all manual, and I now have more water than I can use, know when to heat or cool before it gets to an extreme, and have a really nice database now spanning a good chunk of time.

For the next one - and this setup will wind up with at least 3 major nodes (the workshop being the other) - I did the "batterybox" or batbox pi and arduino. It's not finished yet - it has a web server with a default page, and I've not yet set up the database stuff, but it's already useful as is - one of the things it now does is control the Lister diesel backup generator water pump and cooling fan, and it monitors net amps to the batteries, some other temperatures, and I'll be adding a few more things to that as I get the hardware going for them. But it was time to put it in the box, on the local network and put it to use - tending the Lister was a fair pain with either always on or manual water pump and fan control it was really hard to keep the temperatures in bounds, and/or near the "sweet spot" where it makes less pollution and gets better "mileage". The engine can be quite efficient, and let me get a little further from "rolling from the punches" of nature - I have the AC running, a shower heated up, the car charged, and am making tea in the microwave right now, and I don't think I've used a quart of fuel (the car only needed a top off). Meanwhile, I can watch it all happen, though I haven't hooked up all the sensors yet - there will be more.

This whole project creates a large increase in my quality of life...off the grid one gets used to not taking showers every day, not having AC much of the time, and so on. Now I can have it when I want it (but still don't have bills other than taxes and a little fuel, not much). Seems like luxury to me without too much compromise. I still have to pay attention, but also still don't get surprised by a huge electric or water bill if I don't. Now that's luxury.

This setup is using a pi B+ model 1, as what the heck - it's loafing for what I want, and I had it from back when it was the hottest thing. Once you've used a mod-2...how you gonna keep 'em down on the farm when they've seen Pari? Now that I've done most of the software dev, I don't need the speed of a mod 2 for something that does things every 10 seconds or so...and I could reuse much of what I'd already done, so I wasn't waiting endlessly in edit/compile/test cycles anymore.
It IS cool that I can remote desktop from it, and actually code arduino and burn the one attached to it from my comfy cockpit here...and back it all up to a NAS on my network for "just in case".

I don't have time today to draw and scan all the schematics, and darnit, I wish my ISP wouldn't have a fit when I try to share a large file of code (you guys can email me, though) but I will get to it. There's still some refinement to be done - the ampere shunt signal, while accurate on the bench, is really noisy in real life due to PWM switching solar controllers, chargers not running at 60 hz, several inverters, etc...I need a low pass filter beyond what I want to ask from an arduino, for example.
I had designed that in, but then forgot to actually put it in the build...sigh. I will try to document the whole thing in this thread, but not all today - and one of the important things to document is "well, how does it work in real life, what fails" and so on.
EG, tell you my mistakes so you don't make them yourself.

Despite the arduino slaved to the pi being on USB rather than the multi-slave serial thing I did for the first one, I used the same code other than the serial port address on the pi. It works...it's error-tolerant. The unit number part of the protocol is superfluous, but I don't care.

But for now, some fun pics. Here's the computer stuff in place. The upper inverter is a really old, non-sine wave one I use to run my 5hp air compressor - only. It has had a failure or two (mouse pee?) and I never bothered putting the cover back on. Real life!
Batbox.JPG
In the battery shed with some inverters


Now, I needed to switch some real power for controlling the radiator fan (6 amps) on the lister, and somehwat less for the water pump. So, I put the FETs and optoisolator in a bud box and mounted them right there - running skinny/cheap wire up to that as I'm still Scottish. I added some led indicators to the generator regulator box on the Lister that I can see out the window - I tend to backup my backups for things this important. Nothing beats an observant human.
ListerControl.JPG
Switch logic is in the bud box bolted to the lower left of the pallet jack in this pic.


Here's the schematic for half of the power switch. I used a dual opto-isolator, and a couple P-FETs from Adafruit (lazy, I normally get semis elsewhere but these are very good for this job and saved me having to look).
There is a 12v zener across the source/gate of the FET in case there is a spike on the lister 12v system (likely), a 1k resistor to protect things if the zener should happen to draw current, a 4.7k resistor to turn it off, and the opto with an input current limit resistor to turn things on. Interestingly in this case the optoisolator gives me voltage gain - a ~5v input becomes a ~12v output. The opto might not strictly have been required, but I have seen rather large voltages between "ground here" and "ground over there" when lightning hits - and they are cheap, and solved the problem of driving a high-side switch, which in turn saves me from having to rewire what was already on the Lister and keep the manual switch backups in place with no changes. As they say "An engineer is a guy who can do for a nickel what any damn fool can do for a dollar" - and in this case, it's likely to be more reliable as well. I forgot to show that there is also a catch diode preventing the FET drain from going below ground, but there is one there - a 6 amp/kV rated TV flyback diode I happened to have in stock in quantity (way overkill, but hey). The led indicator stuff is elsewhere, but if I need to draw a LED and resistor for you - this thread isn't for you.
There are two of these on a perfboard in the bud box (one opto isolator) that are simply hooked to different things (fan and pump) on output, and different arduino pins for input.
PowerSwitch.JPG
It looks like this.

PowerSwitch.gif
Here's the schiz (sans the catch diode, oops)


More in the next post.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA

Re: LAN of things - power system

Postby Doug Coulter » Fri Jul 17, 2015 2:22 pm

This isn't finished (by a long shot) but due to the magic of linux and remote desktop, I can change the arduino code from here. And I will be changing it to monitor lister output current and RPM - which has been an issue, we might go nuts and even make that actively controlled. The flyball governor stuck today (hard to believe with the forces involved there - strong springs and big levers, but it got to around 2000 rpm before I got out there and forced it back). So we might add emergency shutdown - but never depend on it - nothing beats a human in the loop somewhere.
Lister.zip
Arduino code for that part of things.
(4.55 KiB) Downloaded 309 times


Now that it's all in a rather uncomfortable place to work on...I do things from here, using XtightVNC server on the pi side, and vncviewer on this end. It's a nice setup. While the Lister was running, I had a little perl code sucking the data out of the arduino and showing it in the terminal.
Screenshot-2.png
Trimmed a little for size, I have a complex desktop and this is just a window on it.

The long lines decode as follows:
tab delimited, lf at end of line
Battery voltage, net amps, amp-seconds since last reading, battery temperature, inverter partition temperature, cylinder head temperature, AC amps (not implemented yet), pump state, fan state, and engine RPM (also not implemented yet).
The next line is just some averaging I'm doing in perl to see amperes without the ripple noise. I will be adding a low pass filter in hardware for this and probably also keep the one I have in the arduino sketch. Lots of noise on that shunt at several frequencies at a time - beat notes, you name it.

I used a picture of the batteries as the pi desktop background as a positive ID for which machine I was talking to (on top of having different names and so on - it's just a human factors thing).
batboxdesktop.jpg
Make it harder for the dumb human to mess up.


The pi has been setup quite a bit differently from the original noobs image it is based on. I'm running MySQL, NGINX, the later arduino IDE (all described elsewhere here or remind me and I will), added some better tools (gedit, gnuplot, cpanminus, synaptic, etc), stripped out the "kid stuff", created some ram disks for frequently written things (which also speeds things up) and put the entire /var partition on a USB3 stick, which is where the MySQL database will live. Why USB3? Well, a USB2 stick won't saturate a USB2 interface, not even the one on the Pi, but USB3 will...go figure. 64 gigs seems like enough for a thing that will probably write down about 1 line of text per minute (in nice columns and rows of course - let that machine, on anyway, do whatever work and unit conversion it can). If you saw the bunnie studios link about how crappy and unreliable flash is - you'd do this too if you wanted server class 9's reliability - or better will suit me fine. I am running the pi from one of those "simple switchers" available on ebay for $1.39 each in 10's, shipping free - what's not to like? It has the biggest UPS system on earth, relatively speaking - 24kwh for something that draws about 5 watts. I soldered that directly into the pi's power pads, so no microUSB connector flakyness to contend with - it's been an issue here in much more benign environments, so why not? I have it set for 5.1v, which the USB stuff seems to tolerate for that little bit extra fudge/safety factor when loading changes.
I wish I could share the Pi image here - but my ISP barfs on files that are 2gb zipped...it takes me a number of hours to set one up this way - all my favorite tools, all those little configuration file edits and tweaks and so forth. I have this setup as a "real working computer" - not a kid's toy.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA


Return to Combined projects

Who is online

Users browsing this forum: No registered users and 2 guests