Thursday, November 10, 2016

Remote Watering System (RWS) - I

I have a real-world need for a project.  The backstory:

  • I purchased ~30 acres of property (raw land) in northern Minnesota earlier this year.
  • It has zero apple trees on the property.  I would like to change that.
  • When I talked to the the apple tree guy, he made it pretty clear that unless I can apply 5 gallons of water to each tree per week for the first year of growth I'd be wasting my money.
  • I'm newly married and my wife won't appreciate me burning up half a day (or 25% of a weekend) watering trees for a whole year.  And even if she were cool with it, I'm far too lazy to put that much effort in.
Project constraints:
  • There is no well on my property.  There is, however, a stream that crosses onto my property for a little bit.
  • The distance from stream to the location where I want to plant the trees is not exactly known, but is estimated at 200-300'.
  • I have a Honda EU2000I (2000 watt peak) generator.
  • Apple trees require at least two in order to cross-pollinate.  I'd like to have a bit of a buffer in case one of them doesn't pull through.
  • There are a lot of deer on the property.  Presumably they'd love to eat a young apple tree.
  • I'm looking to get by on the cheap.
My current design idea is, roughly:
  • Pump water from the stream to some type of containment apparatus.
  • Use a microcontroller to operate a valve of some sort to release water from said containment apparatus where it will be fed (ideally by gravity) to the trees.
  • Power all of the electronics from a deep cycle battery, possibly enabling self-charging with a solar panel.
  • Equip the microcontroller with a host of sensors.  Perhaps most obvious is the need for a water flow rate sensor.  Other sensor possibilities include rain, soil moisture, temperature, humidity, wind speed&direction, barometric pressure, possibly others.
  • Since the area is somewhat remote, but has decent cellular coverage, a cellular network connection seems to be the best fit.
I started floating this idea around work.  I started off imagining this with a 250 gallon "tote" and asked around if anybody had a spare one lying around or knew where I could get one.  I should not have been surprised to get some very puzzled, but curious, looks from the other software architects on my team.  Nobody had anything to offer in terms of 250 gallon totes.

About a week went by.  Then, a gentleman who sits next to me brought up one day that he had something that he needed to get rid of.  It was a water tank, of unknown capacity, that he needed to get out of his yard.  After looking at the pictures, it seemed to be much larger than a 55 gallon drum, but certainly it was no 250 gallon tote either.  I decided to take a look at it.

Turns out I struck the jackpot!  It's 125 gallons, doesn't leak (that I know of yet), and all it cost me was a trip to his house to pick it up on a Sunday morning.  BAM!

Here are some photos.  Since it was unseasonably warm when I got it home, I took to power washing it.









Monday, March 28, 2016

Trouble With The 3D Printer

It didn't take long for things to go off the rails.  I was working on printing a toothpaste squeezer when my y-axis pulley came loose from the y-axis stepper motor.  Some quick analysis revealed that the slices of the parts were out of alignment in one direction only.


The set screws on the pulley that came with the kit required a 2mm allen wrench to cinch down.  They were pretty scrawny to say the least.  I quickly ordered a different set from Amazon and replaced the parts that came with the printer.

After the new parts, it's been working wonderfully.  Look at all the money I'm already saving!*





* This is sarcasm.  I'm under no illusion that buying this thing is ever going to pay for itself.  It's a hobby.


Friday, March 25, 2016

3D Printer

THE FUTURE IS NOW!

I've purchased a 3D printer.  It was a bit of an impulse purchase from Amazon, and by that I mean that I time-boxed the research period before purchasing.  If you do any web searches for 3D printers, there is a TON of information out there and a lot of it is difficult to internalize without any 3D printing experience.  So, I decided that ~$400 was a price point that I could handle for a toy that might be awesome or may turn out to be a flop.

With the $400 option, there is some assembly required.  When I say "some," I mean "a ton."  Here's what it looks like out of the box:

I asked one of my grad school buddies if he wanted to lend a hand with the assembly.  His response was something to the effect of "You better not start without me!"  Two engineers should be able to throw this thing together on the quick, right?  A Saturday morning should do the trick, right?  Wrong.

Here are some photos of the assembly process:




One minor setback occurred when I failed to correctly identify a stepper motor.  The kit includes two different sized motors, just a few millimeters different in length.  The z-axis motors are slightly shorter and, as we learned, the taller stepper motors don't fit.


As the wiring came together, it slowly devolved into an absolute rat's nest.  Although it's a bit unsightly, I prefer this slightly less polished model of printer because I can easily trace lines, troubleshoot, and replace individual components.





Throughout the course of the build, I was surprised with the relatively high level of quality for a kit straight from China.  The installation instructions were in poorly translated English and weren't always accurate, but it possible to figure it out with a little deduction.

My quality opinion went down when I realized that I was short five fastening parts.  They're sort of like M5 nuts, but with a special shape that allows them to turn 90 degrees and then stop within the aluminum frame channel.  I contacted the seller through amazon and they said they will ship me the missing parts.  Since I didn't want to wait for the slow boat, I improvised for the mean time:



There's nothing a little duct tape can't fix!  Well, nothing except this protruding set screw that prevents the extruder heatsink from seating properly...




Fine, there's nothing a little duct tape, a drill press, and a step bit can't fix!



Next, I got those blasted cables under control... zip ties!




And, finally, a test print:


Saturday, February 27, 2016

First IoT Gizmo: Enhanced

I know what you're probably thinking after reading this post title: "How could it possibly get any better?"

I agree.  It's a thing of beauty already, but some parts showed up recently including a 128x64 .96" OLED.  I thought it would be a better value add to visually display the current temperature (and some other data) on the OLED display.

Getting this thing to work with the ESP8266 proved to be a bit of a challenge.

First off, the device's documentation is mostly nonexistent.  Before you can get anywhere with an I2C slave device, you need to know its address.  After using the addresses on the back of the PCB with no success (and some beating my head on the wall), I did some outside the box thinking and found this little gem.  It scans the I2C bus and looks for slaves on every possible address.

After determining that the correct address was 0x3c, I started hunting for a library that let me use this thing without implementing low level code.  Several Arduino libraries for 128x64 OLEDs were available, but they only sort-of worked.  The Adafruit library ran for a little while but it would always crash and cause the ESP8266 to reboot.  Eventually I found this library, which is specifically written for the ESP8266.  The only minor issue was that the code didn't compile, but it was minor so I fixed it, submitted a patch on github, and moved on.

The code I've got so far is worthy of calling a "proof of concept".  It works, but it usually crashes.  I'm 99.9% confident that it's the excessive use of delay(...) calls, causing starvation to things like the WiFi stack.  Before I deploy this thing in practice, I'll probably try running it using a cyclic executive.  This is a perfect use case for timers, but I've not found readily available documentation on the ESP8266 timers.  This is part of the down side of using the Arduino framework on this thing - you have no idea what's actually running under the hood.  More research may be in order here...

Here are some photos of the "proof of concept":





Also, I wanted to get this thing off of my ESP8266 programming board + breadboard, so I whipped up a protoboard version.  Side note: I'm feeling much more confident in my soldering and board layout having made just a small number of these things.  If you haven't moved past breadboards, I would strongly recommend soldering up some permanent boards.  Visuals:




If anyone is interested, here's a schematic of the board.  Note that RST and CH_PD pins on the ESP8266 need to be pulled high in order for it to run.


Saturday, February 20, 2016

First IoT Gizmo

I made my first internet-connected sensor.  I suppose this makes me an Internet of Things expert, right?

While I'm no expert, I did learn a lot along the way.  One of the biggest learnings was how stupid-easy it was to set up a place to dump my data.  I used data.sparkfun.com to publish data "stream".  This freely available platform is based on phant, which appears to be developed by Sparkfun.  Sign up was fast, easy, and didn't even require me to give away all my personal information!

Here's what their UI looks like:

A handy button labeled "Export to Analog.io" produces an ultra-schnazzy chart:


There is a phant library accessible in the Arduino IDE library manager.  I looked into this briefly but determined it to be of little use in the case of ESP8266.  The library looks to be focused on constructing the message payload that you could just send out over TCP port 80, which makes sense if you're running on an Arduino and may have different TCP/IP stack implementations depending on what adaptation gizmo (e.g., ethernet shield, WiFi shield, etc...) you're using to connect it to a network.

Since the ESP8266 features a full TCP/IP stack out of the box and the libraries include a HTTP client, it was easier just to use that.  I was in a rush to see it working, so created data with a GET request.  As a professional software engineer who works in RESTful services, this made me die a little bit on the inside.  I have to keep reminding myself that this is a hobby, and that it's OK to lower my coding standards back down to the undergrad-level of "get it to work."

The gizmo itself consists of an ESP8266 and a 18B20 one-wire temperature sensor.  The 18B20 is much more expensive than the pile of LM35 sensors I had laying around.  Since the ESP8266 has no onboard ADC (well, no ADC that you can use on a GPIO pin), one is forced to use a digital sensor.

This was my first attempt at one-wire interface.  One-wire is a bit of a misnomer because you also need a ground (which in my case was a wire), thereby increasing your wire count to two.  Since the circuitry for parasitic power wasn't work it for me, my wire count was again incremented putting us at three.  Long story short, it worked out just fine.

Here's the gizmo:



Thursday, February 18, 2016

ESP8266 Programming

The ESP8266 is an amazing little unit.  I've had some ESP8266-01 boards on hand for some time now, but haven't had an opportunity to start fiddling with them until recently.  My interest in this board was originally for use as a WiFi enabler for another microcontroller (an AVR), but this article caused me to rethink things.  With a little effort, the ESP8266 can be reflashed to both act as a WiFi device as well as run your logic.

I started out using the hackaday article to build a programmer.  It was a vile, ugly thing.  I didn't go to school for electrical engineering, and it probably shows through in this thing:


It probably goes without saying that this rat's nest of wires didn't work well, so I built a different rat's nest:


The truth of the matter is that the first one didn't work well because I was powering the ESP8266 through my USB-TTL-Serial device.  This device had a convenient 3.3V pin, but it put out nowhere near the current required by the module when it starts talking WiFi.  So, I added a 3.3V power regulator, capable of 800mA, along with a 330uF capacitor to the circuit.  This yielded repeatable results -- much more satisfying than intermittent results.

My third programmer revision was inspired from an article I found when searching for ESP8266 stuff.  This board works reliably and I had the forethought to include headers to supply easy access to GND, GPIO0, and GPIO2.




It wasn't long before I realized that my brilliant forethought to add headers for GND, GPIO0, and GPIO2 forgot to include a pin for VCC.  Thus, it was no longer brilliant and needed an amendment.  Since I was making changes, I added some other improvements to include fancy button label stickers and a stress relief for the wires going to the barrel jack.  Eventually I'll get a female barrel jack that I can solder to the protoboard directly, but this will work for now.  Revised:




For programming the device, I opted to go for the Arduino software with the ESP8266 plugin.  The lack of intellisense and some other professional IDE software features are a bit of a turn off, but it is a free and easy to use option for the time being.  Well, easy to use from a toolchain and device flashing perspective -- not so much coding.