LAN iof things for the homestead

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 iof things for the homestead

Postby Doug Coulter » Sat Jan 24, 2015 6:49 pm

As I get older, it's kind of a race against time to retain my proper Scottishness (eg, I'm a cheapskate) and still live in the fashion I prefer in the middle of nowhere (well, Floyd is pretty close, and dynamic, just not all that populated). I can no longer substitute raw effort for money as much as when I was younger, so I'm automating what I can. This is also good practice for the automation of the fusor for remote running of it, since we had a breakthrough that basically makes it unsafe to be around while running and tuning - it's that good now. May as well get good at this.

As many know, I'm off the grid almost entirely (just a phone bill) so I care lots about power use, especially for anything that's going to be a "vampire load", or "always on".
I don't like the idea of an "internet of things" much at all - send all my data to someone else's server (reliable, private, I think not)? Nah. And what is/will-be offered isn't what I want anyway.

So, I rolled my own.

Some thoughts about requirements and system design.
1. I won't want to change/upgrade this much. I want consistent data long term in a database for weather, water levels in the collection system, solar insolation, you name it. I have to pick something now to work with, even though "better" stuff might become available later - almost a sure thing, but then I'd have to port it all. Not going to happen, I have a life to live doing other things.
2. Anything that can break either needs market staying power or hot spares ready to go. While there are some things that are now better in say, mips/watt than the Raspberry Pi B+ I selected as the hub computer, it's a pretty sure thing they'll be around awhile, and at the prices, well, I can afford to stock a spare or two. Ditto the Arduino Uno's I'm using for the actual data collection and control. Yes, Microchip's pic stuff blows them away, but hasn't seen the adoption since they kind of cheated on making good tools for the masses, and whatever doesn't sell - won't be around later.

In short, I don't actually like either of the computer types I'm using here as "best of class" at the moment. These were chosen for being cheap and widely available, with good toolsets that aren't going away. It's not that much of a compromise, actually - and since the Pi is linux, I can always SSH or RDP into it from something to control it, which is why I'm not that worried about say, a failure in the slick HDMI display I put on it (Adafruit). There will be HDMI for quite some time, I suspect.
Even the display I'm using has a power switch to eliminate the 1-2 watts it uses...yeah, I'm that cheap. Homestead batteries are expensive. I had already built a small UPS for 13.5v running off the homestead inverters, temperature compensated for the big battery it has (60 ah) and this will run from that, giving me days of the rest of the system being down (never has happened, but you never know) before this is out of juice. Could be important for the data collection, and that's when I might actually want the data the most.

So, what I wound up with is a Pi, and an arduino slaved to it. Turns out I can slave other arudinos and so on and not run out of Pi IO even without adding a USB hub if I use the Pi's serial port in a wired-or kind of situation and a decent protocol for that I designed years ago for a customer - I essentially could then have 254 other things out there - surely enough, as 1-2 is more like what I need (and those can run from the same UPS with the same buck switcher I'm using in this box, I acquired those in bulk).

I managed a kind of alpha test of all this a short while back when we had temperatures more than 8F lower than the record since I moved here in '79, and wanted to watch the temperatures and so on for my plumbing in the building that has that, in this case using wireless ethernet (I'll likely go wired once I build the planned add-on to that building, move there, and bury some more cable - got 100' of CAT-6 burial cable just for that reason - and it saves power...).

This will no doubt turn into a long thread as I build the software (the fun part) and add various sensors and actuators to control things like my water collection system. That turns out to be a non-trivial control problem itself. Then there's learning the thermal time constant of that building vs degree differential and wind speed, the normal time constants of its woodstove and so on.

While these pics could almost as well go in "machining and fab" they really don't show how to do this - just how I did it. It's kind of assumed you know how to measure, drill holes, solder and so on, and avoid shorts. (Pro tip - after machining the box, blast it and all your little SMD type boards off with compressed air to remove ALL chips. Those don't get along well. I didn't have issues this time, at least in part because I did that. It all worked on the first try :mrgreen:

Here's some pix of the Pi hardware going together. I could bolt this box to a wall, or flush mount it if the wall is thick enough. The latter is probably what will happen, and I've left provision for that via the "wings" that stick out past the display panel that replaces the box top. I will add some (a heck of a lot?) of arduino stuff to this thread later. The basic system design is - the Pi does the high level stuff - talk on the ethernet, web server, database, plotting - the arduinos do the data acquisition, control, and anything where real time matters (Pis are glacially slow compared to a modern PC, but they still can do all the same stuff....if you wait long enough).

Parts.JPG
The basic pieces. Pi is lower left, switcher is upper center, and HDMI panel driver on right.

Note the sneaky trick of mounting the HDMI board end via an angle bracket to the unused VGA port. Ground and a better mount than those tiny holes anyway, and at the moment, my shop isn't toolled up for 2-56 or 2mm screw work anyway. So I used a lot of nylon nuts (no shorts) and 4-40, which barely fits these guys.

To avoid invoking Murphy's law, I of course fired it up under load before buttoning it up.
Testing.JPG
Pre-test. Yes, it's ridiculous to have 2 meters of HDMI cable wound up in there. I'll find a short one sometime soon.


Since that seemed to work, I buttoned it up and did a more real test, full DC power loading, web server and so on. That's me showing on the screen in the back, served up by Apache running on the Pi...could be worse.
Done.JPG
I just love it when things work on the first try...


Some of what I've done I've already written up here somewhere. There will be more, and as time goes on, I'll try to make it all link together so we have usable standalone sub-projects as well as the 30,000 ft view of the system and its design.
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Tue Jan 27, 2015 11:22 pm

And, of course, some things don't work on the first try. Gawd, what spaghetti code that cam-stream stuff is. Along with phpmyadmin, which I added along with MySQL as a way to log data and retrieve it.
The issue with the cam stream code...well, there are a few. Some of the camera control functions don't work - and I care. Heck, I challenge you to even find out all the places where the path to new camera images are stored is defined - let's just say, many and by different names and in two different languages (at least). I need to up my grep-fu chasing down multiple renamings of things via the equivalent of #define here and there, and the places where the author(s) themselves just gave up and hardcoded (yes) the path in other files to move that spot. I was trying to do that so as to move those, and the database itself, onto a plugin USB stick I could mount over just one directory. I didn't want it to have all of /var, as I've had issues in the past with mounting things over that (if you're booting off a SSD and put a hard drive over /var, it's not ready yet, or even mounted when the system logs want to start being writtin, and things crash).

I also found out that with cheap USB-2 drives (Sandisk in all cases here), they don't always auto-mount at startup, even if I have them in /etc/fstab - they're just not there unless you re-plug them - even a power cycle doesn't do it. I had this with the dirt-cheap 4gb sandisk drives Amazon sells in bulk - about half the time (at best) they show up under /dev and also mount, the rest, nope, and there's nothing you can do about that but re-plug them with the system already booted (not a good idea if mounted where logs and swapfiles live!). I then tried a 64 gb "Extreme" USB 3.0 drive and it works every time. I noticed in the reviews that someone complained they couldn't boot windows off it, as it marks itself as a "fixed" drive. Well for me, that's better, so there - it works every time and is more the size I wanted anyway. And it mounts up fine over all of /var (after copying the content of var to it with all the permissions etc conserved) from fstab...and doesn't seem to slow anything down, even though the swapfile is also there - works for me. I had worried a little about possible power draw issues (heck, I always worry those) with USB 3 on this - it doesn't need and can't use it - but the thing stays stone cold, so it can't be eating much.

So, rather than having to tackle the ugly camera code right now - or move MySQL databases and somehow tell phpmyadmin where they went - "it just worked". I have full remote access to this thing, have it on a fixed IP address (as is the share on my wifi access point) to make things a bit simpler, and can easily share stuff (yup, SAMBA, none of this would seem odd to a linux guy) - it all works fine, if slowly. It's a dancing bear. It dances, let's not get into style/speed here. It's enough.

Yes, I should fill in all the details of things I actually did with complete command lines, but I didn't write them down (but I might slip a character error doing it from my memory)...I did backup the pi SD card before doing the final USB mount over /var, though.

Oh, computers have memory. So the backup command with the pi's micro-SSD card in a reader (on a regular linux PC) is:

sudo dd if=sdc of=/fast/PiB_prevar.img bs=4M

That is, assuming it's sdc on your machine and you have a directory called /fast, both of which are true here, and that's where you want your image to go (/fast is on an SSD on an intel NUC i5). Adjust as required. I'm using a 16 gb card, which at this point, zips down to around 2gb and is not at all full, but adding that heavy software added around a gb to the zip file. You obviously can't add a full image file of the pi boot card to the pi boot card and expect it to fit anyway. A PC takes long enough to do this...use one.

The command to copy the content of /var off the pi SD card onto a USB stick formatted ext2 with one big partition and with label PiB is: (on the pi itself)

sudo cp -r -p /var/* /media/PiD

This preserves all the permissions etc.
Then, once this is all done, /etc/fstab on the pi is edited to look like this.
Pi's fstab:

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
# attempt to mount //amped_ap_usb/mnt/ over home/pi/amped
//192.168.1.240/mnt/ /home/pi/amped cifs guest,uid=1000 0 0
# try this last...
/dev/sda1 /var ext2 defaults,noatime 0 0

That IP address is my wifi shared USB storage (a 120gb SSD itself). You'll not need that, or need something else (it IS really cool to have it as a directory in your home, though, no fooling around at all, it's "just there"), here we're talking about that last line. I did this with ext2 and noatime for two reasons - to not burden the pi with journling file system stuff, and to save wear and tear on the USB stick. It should be fine, some cron script I'll write later will auto back it up from time to time anyway.

And, it works, no mods to the spaghetti other code required at all. Phpmyadmin works from any machine here, I can ssh into the pi as it's user and do stuff, I might even add remote desktop if it looks like it'll take the load...once I fix the camera stuff so it doesn't eat 70% of the pi cpu even in timelapse mode (can't seem to turn preview off) and even after you log off its website...if you didn't turn the camera to off before doing so. Like I said, drappy code, but it's something I can fix later, as the camera isn't the main show (this is for another building, not the fusor) and that won't even be the index page of the website once I get going anyway.
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Fri Feb 06, 2015 2:47 pm

Here's a quick movie of where I'm at currently, and a link to some of the arduino stuff I'm doing in conjunction (lots more to come!).
Arduino protocol: viewtopic.php?f=32&t=910&p=5512#p5512
The idea is to do all the stuff that has to be hard-real-time in arduinos, since they make that simple and don't have a pre-emptive multi-tasking opsys so you can do it easily despite whatever else is going on, and do most of the "heavy lifting" re math, databases, web serving on a "real" opsys, in this case, Raspian. Always use a platform for its strengths, don't force it - let it do what it does best, let something else do the other stuff. Works, and has been working as a systems-design approach for decades now, at least for me.

Movie:http://youtu.be/j_jnmjVa4Mk
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Tue Feb 10, 2015 2:44 pm

As luck would have it, I caught a day of reasonable weather to install the automation stuff, or well, most of it, into the water system. This involved swapping out the ball valve and garden hose at the supply/collector end of things, replacing that with a nice brass fitting and quick-disconnect for 1/2" NPT, and running some blue PEX tubing down to the cistern end of things. Here's the collector end:
Collector.JPG
Note, screen over top, overflow hole, pickup not quite at bottom.

This originally took a lot of time and thinking to perfect, it's not as simple as it looks, quite. There is plastic window screen over the top, with the intakes from the gutters near-horizontal. This filters out any large chunks, and the flow tends to wash them off the screen - that's important, as you don't want, say, water through rotting wet leaves. There is an overflow hole in the side of the trash can (which is looking good after a few years in the sun) to eliminate anything that floats. I don't use any water that hasn't brought this to overflow, which a suprisingly small rain will accomplish (~512 sq foot of collection area). This washes off the floaters, and also tends to dilute anything that was already in the tank in case it wasn't so hot - even that thin layer that we don't take at the bottom can grow algae etc in the sun. Since the trash can is free floating, occasionally I pull it out of there and clean the insides. The bottom is often just a little algae and mostly little rocks off the shingles. Half a cup of bleach and a little sponging and it's like new. This is a good system for where I live. There are about 3 weeks yearly when I can't use this water, and it's because of pollen seasons spring and fall. That stuff is "turbid" and will grow bad things as pollen is bacteria's favorite food, we have sun...and so on. Of course, this is why I want and have a large cistern, kept in a crawl space and in the dark. Without light and cool - not much would grow in there even if the right other stuff was present, and in fact, after running all my water through there for a year, there's about 1/8" of crud on the bottom. Won't be hard to remove with a siphon since it was a spot sprayer tank and has a big screw on lid for access (other than the other holes I've put in).

So, here is that end of the system.
CisternValves.JPG
Cistern, overflow/sensor and valves.

Since this is gravity-feed with only a few feet of head, the valve selection was all-important. For example, nearly all electrical solenoid valves require some fairly serious pressure to actually open, and most of them have a tiny aperature compared to the fittings even then. The ones from Adafruit are like that, and they are the better of the bunch out there usually. As luck would have it, I had obtained some other, high quality valves I think were meant to be in a refrigeration system, surplus. While rated at 24vac, they also work well at 5v DC or so, which is how I''m using them and will once the Pi controller is in charge as well - DC is one fet to switch (per valve), AC is a little trickier. And I have the DC. There is an emergency overflow at the top (white pipe on brass fitting) "just in case a computer makes a boo-boo" even though we all know that never happens </sarcasm>. The brass fitting, installed via drilling an almost big enough hole, then heating the fitting above the melt point of HDPE and screwing it in, is also going to be the topmost level sensor contact, that system part described elsewhere. I've already drilled and tapped it for a 4-40 screw and lug for that. The permatex is for "just in case" and I used the good blue stuff.

Below that, there are two valves. One is to let water in, the other is to let it out onto the ground outside. That one will be handy when we've got a half collection can of junky water we don't want in the system - we just let it go out. Or perhaps we want to drain the line (which will be buried at some point) because some of it might not be buried and might freeze, a pain. The other one, that lets water in, will be activated by one of the computers in the LAN of things project, not sure which one at this point...I'm trying to hold down the number of arduinos I need at this building, and might use some Pi I/O for that part, since it's very not-time-critical and requires more "judgement". There will have to be water level and turbidity detectors at the collection end as well, for the right decision to be made. And oops, though I bought one, I forgot to add the water flow sensor (Adafruit) I'm going to want to have in the intake before the valves. Next nice weather, I suppose. For now, It's sealed back up, since it's supposed to get nasty-cold (for us) again real soon. Those valves draw around 6w with the battery and switch on DC (rated at 12-14 on 24v AC) but really, that's not a huge solenoid and you'd not want to leave them on forever, even if power wasn't a consideration - they get nicely warm as is.
SealedUp.JPG
Sealed up with insulated door for the cold.


So, now I can eat breakfast in peace...at 1:145 pm....and know that no more standing in the rain is in store for me for a long time. I no longer have to sweat overflow...for one thing. I can just check for overflow (from a window) go out and turn on the v valve, and come out again later to shut it back off. Instead of standing in the rain, waiting and waiting to get the thing "just full". Next step is to install the level sensors on the cistern (and make another set for the collection tank along with inventing some sort of clarity tester). But the UPS guy just brought me a bunch of new toys from Ada - and one of them is a very nice arduino screw terminal shield I intend to populate with the wired-or serial stuff and whatever else. NIce to have screws for wires from sensors too....will make any later maintenance a lot easier, and by then, I'll want to do it less, and be less able to. After all, this whole thing is to allow me to grow old, infirm (and I'm already lazy, at least by my own standards. Heck, if I start goofing off after only 10 hours of work, I feel guilty.).

FWIW, the resulting flow rate is about twice what it was before, using 3/4" garden hose and full size ball valve. That PEX tubing is very slippery inside compared to most other plumbing things. You can usually use a smaller size. In this half inch size, you can freeze and thaw it - with no damage whatever. Kind of useful where I live.

And now here I am, in the warm, testing the Pi Cam with 2 meter cable..the little bluer screen is the pi, the bigger one is a NUC...the rest is just a mess. I scaled down the pi pic around 2x...it's really high resolution, not needed here. Having just assembled an arduino screw-shield, I'm going to put the serial wired-or parts on that, and get ready to test with all the other sensors too. The original Uno code didn't take the required timing into account for a "speak only when spoken to" interface, so I get to change that code as well. Then add more stuff until I run out of pins...
WorkingPiCam.jpg
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Wed Feb 11, 2015 2:14 pm

I managed to catch some more decent weather (35f) so I finished up by adding the flow meter I'd forgotten before. Here is some clearer detail on the intake system. The top valve goes to the cistern top inlet, the bottom one goes to a pipe that just lets water go on the ground outdoors (downhill). The flow meter is now installed at the intake, before the tee. These valves were made for 3/8" OD sweated (soldered) joints, and the PEX fitting are a little small for that, so I drilled the 1/2" nominal fittings ID out with a letter W drill (a tiny bit larger than 3/8" so there's room for solder). The PEX fittings for the flow meter have a rather large brass inner too - and it doesn't quite fit the rather small opening of the flow meter so the rubber can seal, so I reamed out the flow meter fittings with a large pipe reamer to make that all match up. Hopefully, it won't leak (have to wait for rain to find out). With this in the system, the computer will know whether water is flowing - and whether to even bother keeping some valve open or not. Saves power, wear and tear, and gives me some kind of error info. I'll just steal the same arduino code I used for geiger counters to count pulses from this.
Valves.JPG
Detail of the valving system

Now, until this computer control stuff is more of a reality, I still use and need water. So I kludged up a 6v gel cell and a switch to operate the valves from outdoors. Already, I won the advantage of not having to take that door off to monitor it.
You can also see the propane tank for the little gas lantern mantle heater I run when it's supposed to get ridiculous-cold, to keep the system from freezing. That grill tank will run that little lamp for many days...but you have to get in there to turn it on and off...for now.
ManualControl.JPG
Temporary manual controls...remember when the aliens got the computer in Star Trek and nothing worked? I do. Gotta have backup!
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Sat Feb 14, 2015 1:14 pm

Here's some more pix of things in progress. The Pi has some new contents, as I decided some things might just as well be right in the box with it.
PiNPeriphs.JPG
the Pi box

Clockwise from upper left, we have the BMP180 barometer/temp sensor, the ~~12v to 5v switcher, the HDMI/DVI display driver board, and about-to-be-mounted thermocouple breakout board (for woodstove flue temps in that building), the Pi, right now a B+ but I'm planning to upgrade to a Pi2, and in the center, the serial level converter/driver for the slave arduinos.

It's going to go here, in my old "office trailer" where I plan to move - and make a lot less of a man-cave than this place. That's the trailer in the movie above, about in the middle, backside. I want to put together a more-normal living situation in it, maybe even (gasp) get a girlfriend again. No human female would ever hack my current man-cave (at least, probably not). This is one of the old op positions from when I ran C-Lab from there. While it's no longer a 386, yes, that ancient NT4 machine actually still works and I recently recovered some cool old software we'd written from it. Of course, that will be seriously upgraded in the near future, with multiple monitors, the Pi box in the wall, and the obsolete books put in deep storage or discarded, to be replaced with current stuff of more general interest. Some benches etc in there will be torn down, and a more normal living space created via that and an add-on (with real insulation and porch) added this spring.
OpPosition.JPG
The intended op position, before I clean things up.


The point is - I need a place further from the fusor to run it from, and this "LAN of things" project will include the stuff to run the fusor from there - about 30 yards away, so the air and inverse square law eliminate some of the radiation I get. The other point is to automate a bunch of this "homesteading stuff" so living here is more like what most people experience - except without the ongoing "rent" costs and with less labor. I'll keep my freedom, thanks.
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Tue Feb 24, 2015 7:55 pm

Huff, Puff...coming along...when I get a minute between hauling wood and thawing water, it's been pretty brutal out.
I've designed a simple protocol that lets one hang any number of Arduinos (or other) microprocessor(s) off the serial port of a raspberry pi - the pi can drive all the slaves easily with a 2 amp peak (!) fet driver, and all the arduinos are wired-or driving back though a 2 transistor circuit. They only respond when they see their "unit address" at the beginning of a line, and there is various error-rejection. The assumption in this simple, low speed (115.2 kb but only every 10 seconds or so) protocol is that the host will simply retry on an error, timeout or otherwise. Seems to work pretty well in bench testing even with long cables and some EMI present, though I did take care to put signals between AC grounded wires in the flat cables I'm using - just in case, so it's more like coax for signals.
Here's a screenshot from the pi with this running.
PiArdTest.png
Running along.

The colon comes from the pi so I mark start of line.
Next column is water level, which isn't hooked up yet. After that are two counters, also not hooked to anything at present, but they will go to flow detectors from Adafruit that make pulses for water going in, and out. Then follow temperature and humidity for each of three DHT22 sensors - one will be basement, one living space, and one outdoor. Right now, indoor is near the woodstore, "basement" is on my bench, and outdoor is well, outdoors, hanging out the window - these seem to work fine at the end of 20+ feet of cable.
I will be posting code, but to avoid confusion, will hold off a little till it's closer to done - right now it's only dev-alpha...no point posting endless near-useless revs till It's nearly ready. I'm using a simple perl program on the pi to just dump this stuff, whereas later on, it'll be going into a MySQL database on the pi, and the pi will serve a web page with all this stuff on it, in purty plots and so forth, as well as be the "real brains" deciding when to open valves, beep me because it need some human input, or someone is at the door (yup, doing security on this too - including full HD video).
I'll put in a little youtube of this in action when it uploads. It will be at: http://youtu.be/4wKUZ8ClZbs

The water level detector is something I'm excited to try. Believe me, I've tried them all - and they all fail in the nasty conditions (temp and humidity) around a water tank, and tend to fail on the young side. This idea I stole from a National Semiconductor apps book, circa 1978 (they used to make a chip for this). The idea is that you AC couple some signal into the water, which has a dielectric constant of around 81 (vs air, which is 1.000something). For simplicity, and loudness, I used a 555 timer at ~50 khz and 12v peak. You then have probes poking down so at various tank levels, the water will touch various probes - one that goes near the bottom gets water first, and so on up as the water level goes up. You then AC couple some simple AC detectors (full wave voltage doublers in this case) loaded with some high impedance (100k ohm here), and when they come off ground - you've got water to the level of the probe tip. Since I had gotten it into stock anyway for physics stuff, the probes will be pure titanium wire, and shouldn't be a corrosion issue - especially since there is no DC current at all - this is AC coupled in and out.

Some pretty simple code then shows you which probe is the highest level, and you can report that. I'm using 4 channels of the arduino a/d to give me 4 level indications, from 56 gallons to full, which is 225 for this tank. Not perfect, not super resolution, but a heck of a lot better than going into a crawl space with a flashlight - that has the door screwed shut with multiple 3" screws in winter to keep the cold wind out....Progress! I may add a water temperature sensor and an old immersion heater from my electroplating setup to push a little warm into the water when it's both cold and I have the power to spare - that's the kind of thing this will allow without me having to think of it and do it every time - and thus make it a lot harder to freeze my plumbing so I can spend more time on physics than crawling around with fittings due to a freeze/break occurrence.

On further thought, since there might be someone who would benefit from this as an example, before it gets too specific to my uses and so on, and just in case I somehow lose my code, here's what I'm working with right now:
ArdT1.bz2
Uno Sketch
(3.65 KiB) Downloaded 108 times

ardtest.bz2
Perl host code for pi
(1.05 KiB) Downloaded 109 times
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Mon Mar 09, 2015 4:49 pm

Well, $DIETEY(s) of home automation have smiled, and rewarded some effort I've put into this. Today, I added the circuit board/mount and wiring to the cistern (I put in the Ti wires yesterday, and the sealant is a little soft, but it was hard to wait), and lo and behold, not only did I NOT hit my head, it works! I am seeing ~9v on each output from a sensor wire under the water, and about 90mv on the one that isn't.
Should be relatively easy to tell from the arduino's a/d what is going on (and yeah, I'll probably put a 10k or so series resistor in there...just in case).
Here's the inside. I've let the tank get kind of dirty - but it's easily cleaned later. Good luck that the shavings from drilling the holes float...
InsideTank.JPG
Remember, it doesn't have to be pretty to work, just not shorted and the wires the right lengths...

Here's the overflow sensor (and actual overflow piping, not that I trust it to keep up with a fast intake).
OverFlowSense.JPG
Maybe the most important single level - too much.

Here's the tank top with the probes "installed". Looks like a joke, but I bet it works fine.
TankTop.JPG
Drive wire at left - goes to the bottom and along the length of the tank at bottom level. The other three are the intermediate level probes, shortest first.

And all wired up and tested...yes, it works fine. Plenty of "margin" running the 555 sq wave from my ~~13.3v basement UPS system (that will also drive the arduino after a switcher and the pi that will control it, at some point, right now they're over here for programming. And more programming.) I wanted to get this in now, as we're about to go back to crap weather...and I can now do more programming on the pi and arduino now that I know what numbers to expect (well, better than a pure guess).
WriedTested.JPG
Ta-Duh. It works!


I've been thinking really hard about whether to used the Pi B+ or this new PiB-2 that I'm posting with as the final thing to put in the box. One thing is the other one is already in there, and it works fine, though it gets on the stressed side streaming HD video previews (hey, who wouldn't want a free IR security, snoop camera?) and doing the rest, while this pi2 is barely cracking 13% cpu streaming vid while running NGINX, MySQL, phpMyAdmin, and you name it else (and oh yeah, iceweasel, the browswer, firefox by another name for pi2's).
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Thu Mar 26, 2015 1:39 am

Well, moving along so I tried to get this really right, as once this is all bolted in, some thing will be harder to change. I of course got a camera for this pi, and want to be able to use it as a security camera and for other fun things. I used Silvan Melchior's pretty decent (though kind of spaghetti) code, but I didn't like using apache - in fact, I did use it at first, and it's about like a really lnasty virus if you try to unsintall it - various modules etc refuse to leave, or insist that somthing similar be installed if you remove one as it will break some dependency (from something else I'd already removed). First time I've ever seen the linux .deb/apt package manager actually really screw up. So I did it all over. I took the opportunity to put both /var and /home/pi/bin onto the big usb stick this time, and used NGINX as the web server, basically using the raspi cam web installer but doing it all manually and leaving out the apache-related stuff. It works even on the slower older pib+!
What also works is the data aq - soon to be in a mysql database, but I've not finished rebuilding this image all the way, to get all the cool mySQL tools back in and running under NGINX yet - I will.
Some handy links here:
http://www.raspberrypi.org/forums/viewt ... 43&t=63276 - for the basic cam stuff. I downloaded his install script, opened it in an editor (I like gedit and installed that), and then cut-pasted to a terminal only the parts I wanted, leaving out the apache stuff (NGINX eats a lot less resources and is more modern and easier to configure unless you're already way up to speed on apache)
How to get NGINX in here and working right: - you will wind up pausing this video, he goes fast to squeeze in quite a lot, but it's no frills, straight to the point, just get 'er done good stuff:

Some results - here's my ugly mug in my mess working on this from the pi camera. It's really pretty good (despite poor material to take pictures of).
testimg2.jpg
Been working all day...on this, beer o' clock now.

I actually had to run this through the gimp and compress it from the original 3 mb to around 600k to get the board to take it at all....it's too darn good. I didn't make any other changes or enhancements, the original is better.

I'll have some more on the cool data aq control soon. It's late tonight...and I want to do a little more customizing (eg fix up the screenshot stuff on pi so it can be in the app tray etc so I can use those pixels to show it off better).
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Re: LAN iof things for the homestead

Postby Doug Coulter » Thu Mar 26, 2015 11:37 am

Here's the data aq screen - this is just prototype code for the version that will stuff things into the database (which will be synced to another unit in another building - both need to know each other's status to make some decisions).
The sharp eyed will notice this isn't on exact time intervals - working on that one, for now, it just sleeps between taking data and printing it (it won't do that in the final version). I will put the "final" arduino code on another thread, it's been really stable, and while I could dandy it up a little (low pass filter or median smooth some noise out etc), I might not bother. We'll just see how the cpu cycles come out - the arduino has plenty to spare, so it's a matter of where to do work to keep things responsive, and get the most mips/watt/piece of hardware.
StuffData.png
Raw sceenshot from pi


What we have here on separate lines is some data from within the pi box, then some data from the slave arduino (which is now more or less out of pins to connect stuff to).
The arduino format is:
Water in cistern (not wired up, wrong building right now)
Water intake rate (also not wired)
Water outflow rate (also not wired)
Indoor temp (deg F)
Indoor relative humidity (%)
Outdoor temp
Outdoor humidity
"basement" temp and humidity - sensor is right now by my woodstove, but it'll go by the water system in the basement
Thermocouple cold junction temperature (thermocouple is for a woodstove flue)
Thermocouple temperature, currently near my soldering iron to get a nice high reading.
State of water inlet valve
State of water dump valve.

In real life, I'll probably have this combine data at whatever sample rate (it can be fairly fast and not eat cycles badly) into a summary for stuffing into the mySQL database about (hopefully exactly) once a minute, which is still on the fast side for "weather" data, but about the right speed for making decisions about water, heat, power use for heating water, and so on.

I'd have liked to have one more pin on this guy, but I'm fairly sure it would take a little modification to use the SPI data-out pin for something, since I'm using the other pins for the thermocouple breakout - it probably spews random stuff.
What for? Wouldn't it be nice to have a switchable heater under the water supply in winter? I have the heaters and relays. I'll have to fool with that more to see if I can find a way (and keep it reasonably simple, eg, no special modified libraries, want to keep them all "stock"). I seem to have some free gpio pins on the pi, though - we'll see what I can rig. Avoiding yet another box of electronics and its power drain are fairly high on the priority list here. Had I known of the possibility of using just one slave, I'd not have done all that work on the protocol that lets me have many - but again, this project IS a dry run for fusor automation type of stuff - and it will need a few slaves, so...the more the code (and hardware) is the same everywhere, the better from my POV.

I'm trying to learn the rather odd system debian uses to allow things to be on menus and on taskbars so I can make scrot an icon on the taskbar and get screenshots without the little dance I did for this one. I opened a terminal and told it to take a shot 10 seconds later, then hid that terminal. A kludge...Since I plan to be using this for many years...I'm trying to make it "nice".
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: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA

Next

Return to Combined projects

Who is online

Users browsing this forum: No registered users and 1 guest