Friday, September 18, 2015

21: Battery Backup, Revised Again
updated 9/26

After my failures with the Adafruit Powerboost 1000 (post 16), I complained at an Adafruit forum. Their response as  that I should have used a Powerboost 1000C instead. Note the subtly added letter "C". So, gritting my teeth, I paid $19.99 (plus their pricey shipping) and tried again.


I let this setup run for over 24 hours powering either a Raspberry Pi (drawing about .4 amps) or a Particle Photon (drawing 1/8th as much) and both worked fine. I could disconnect external USB without the computers noticing but pulling the battery plug caused both processors to restart. Not nice but not a deal killer.

Note the input power LED in the image. If you aimed a photo sensor at it, your program could detect external power failure. You would  then have time to send out a text message and shut down "gracefully" whatever that means.

Update: The setup ran a Raspberry Pi for over 2 weeks.

Wednesday, September 16, 2015

20: I Installed a LIVE System!
(after 2+ years of messing around)

Two weeks ago I installed Particle Photon in my granddaughter's farm hoop house (they used to be called "green houses"). It is programmed to support 2 temperature sensors and 2 soil moisture sensors. It provides control of 2 switched devices: an electrified deer fence and a water valve for drip irrigation. Here's the smartphone web page image:

as of 10pm, September 15

Data comes from my Photon program via Particle's "cloud" interface. The electric fence is normally turned on and off by time-of-day (the cloud provides UNIX-like time functions). But that timing can be overridden by the web page above (password secured).

I originally planned to implement this using a Raspberry Pi but the $19 Photon's simple web interface trumped the Pi's many advantages (especially the mature software development environment).

However, the Pi is not all together out of the picture: a Pi-based cron task checks on the Photon every few minutes and sends text messages if anything has gone wrong.

The Photon, sensors, switches and wiring cost under $70. My control program in C++ is about 80 lines long.

Does anyone know of a reliable motor setup for safely rolling the sides of the hoop house up and down (to control inside temperature)?

Thursday, August 13, 2015

19: Solenoid Water Valves

My new mistakes:


1. The image above shows 2 seemingly identical .5 inch plastic valves. But the one on the right has tapered threads (about $10 from Adafruit). The left (cheaper) one did not. To get the brass fittings screwed on I had to carefully file down the end threads so I could get the adapters screwed on without butchering the plastic. Very time-consuming -- and irritating.

2. Also, why did I go cheap? For about $25 I could have a brass valve to go with the pair of $15 fittings. And the whole thing would likely have been more reliable.

Tuesday, August 4, 2015

18: Photon vs. Core

As advertised, the Particle Photon seems to play nicer with wifi. It connects quicker when plugged in and stays connected (my Core occasionally lost wifi and had to go through the startup mode again). My software development problems (clunkly build works, Particle Dev doesn't) haven't been fixed, at least for the Mac app.

BTW: I've gotten interested in Particle's cloud-provided Time functions. It's not like Raspberry Pi's crontab scheduling but you can program things to occur at particular times. There's Time.hour() for the current 24-hour clock hour, for instance. Easy access is available to day-of-week (e.g.) and all of the usual Unix/Linux functions -- accuracy refreshed from the cloud. Makes a Photon much more than a "smart controller."

A Particle advantage I hadn't thought of: I'm about to install a Photon system in a farm hoop house 100 miles away. If the running program needs modification I can do it from here!

Wednesday, July 22, 2015

17: Xmas in July -- I Received My 2 Particle Photons

Here's what you get for $19:
the Photon is 1.5" long
(they haven't totally erased the original "Spark" name yet)

See https://store.particle.io/?product=particle-photon for details. I've had the earlier $39 Core model for a few months. Supposedly the Photon can run the software I previously ported from Arduino. Also, in addition to being half the price the Photon is supposed to use the latest WIFI chip (more reliable?).

But there has been good news and the other.

Good news: The Core has been very reliable. Once I got it connected to my WIFI I've been able to communicate with it from anywhere. It's like an Arduino Mega but faster, more memory (but with fewer GPIO pins), the physical size is like an Arduino Nano and it has built in WIFI. Particle's "cloud" interface makes their "smart controllers" a lot smarter than an Arduino. I have my Core connected to the Web. I can read sensors and control relays from a simple web page.

Bad news: Documentation is sketchy -- well, you'd kind of expect that with something this new. Program development is painful. I started with their web browser interface: particle/build. Finding my coding mistakes was a challenge. On one 80 line C++ program I left off a semicolon on the next to last line. I got 72 lines of error messages; line 71 finally told me about my mistake. Once I got to 20-some source files having them up in the cloud became cumbersome. 

So I tried switching to "Particle Dev.app" programming where you keep your source file on your local disk. I could write a book about this but sufficient to say that since July 1 I have yet to be able to access a program compiled this way.

Also, I fear that Particle is skimping on their support force. At first, I got responses to my foolish problems/questions in a day. Lately (with changing to Dev.app) it can take a week or more.

* * *

I've been programming for 50-odd years. I should be used to this kind of thing.


Tuesday, June 30, 2015

16: Battery Backup
Post 11 corrected
** revised again 7/16/15 **

When I tested my battery backup circuit (post 11) I failed to let the systems run on both USB input and battery for long enough. Turns out with 5V/1A input from my USB hub the setup drains the battery. And when that happens the USB output drops to 4.10V. Not nice. However, USB input of 2.1 Amps seems to correct the problem.  Wrong again: Anyway, the setup pictured only works if the USB out draws less than 500mV. None of my Nano test setups take this little -- nor does my Particle Core. So regardless of 5V USB input the the system fails when the battery runs down (USB output drops to 4.1V).

Gory details at http://forums.adafruit.com/viewtopic.php?f=15&t=76014


Most USB hubs don't provide 2.1A outputs. So I ordered a 5-pack of 2.1A wall plugs. I'll let you know how they work long-term.

Saturday, June 13, 2015

15: Soil Moisture Sensor: Arduino and Particle Core
-- revised --

I programmed this first on an Arduino Nano. Pretty easy. My guesses at wiring did no damage. The "sunkee soil hygrometer" (probably meant "hydrometer") was mostly marked in Chinese. One tricky part: once you start the program the probe device is on all the time -- drawing current. I first considered turning it on & off with a transistor. But then I wondered, why not just use a digital pin. I don't know if this is as safe, but it's simple and it works. In addition to short patch wires, I tested this using a 50' CAT5 cable between the probe and the interface. It worked fine. See post 27 at http://dicks-raspberry-pi.blogspot.com/.

I had expected these things to be bigger. 
Probe points only about 2" long.
Adjustment screw only useful for digital (ON/OFF) output.

Here's my Particle Core code. The Core can be read anywhere wifi is available (if you know the codes). So the Core can be remote from my Raspberry Pi control program.

/* device: "sunkee soil hygrometer" [SP?]

2 wires from probe "YL" & "69" (?) to interface board 
  no-label<->(YL) & GND<->(69?)
4 wires out to Arduino: "VCC" "GND" "D0" "A0"

Arduino or Particle/Core -- just guessing:

VCC -- 5v (or 3.3) 
  Arduino 5v: analog range=1023:200 (10 bits), 
  Core: analog range=4095:2000 (12 bits)
GND -- GND
D0  -- unused: just on/off
A0  -- analog pin
*/
int soil = A3; // read the device
int power = D1; // turn power on just for the reading

void setup() {
    Spark.function("soil1", Soil); // Core-only function
    pinMode(soil, INPUT);
    pinMode(power, OUTPUT);
    digitalWrite(power, LOW);
}

void loop() {
    // not used
}

int Soil(String command) {
    digitalWrite(power, HIGH); // turn probe on
    delay(200); // let it settle?
    int raw = analogRead(soil); // high=dry, low=wet
    delay(200);
    digitalWrite(power, LOW); // turn probe off
    int read = map(raw,4095,2000, 0,20); 
    return read; // return reading between 0 & 20
}