Tuesday, July 5, 2016

101: My New Raspi Model B 3 -- and a Gotcha!
-- revised again --

Back at post 2 of this blog I told about running pi.py -- my little Python program that computes Pi to 10,000 places. My first April, 2013 model B took 4 seconds. The new one: 1.4. That timing is for the 2nd execution (with the Python app already loaded in memory). Same deal on my new-ish iMac (quad 3.1ghz, i5): 0.17 seconds.

Nice. However, I've been bitten by the increased power requirement of this (release 3) model. I fired it up with a 2.1 Amp power source, 32GB micro SD and with the following attached: HDMI cable to 7" monitor, USB wifi dongle and USB keyboard. In this configuration the red light comes on but the SD is never accessed (green LED stays dark). It boots OK with any of the plug-ins removed. After initial power-up the removed device can be added. I failed to read about the need for a 2.5 Amp source.

Later: I got the 2.5amp converter. Better. It not only boots up with everything connected, it stays up, too (accessing the new Raspi via ssh always failed after an hour or so with the 2.1 amp supply -- I didn't get why).

Later: just got a new power strip that besides "surge protection" has 4 USB power outlets rated at 2.4 amps each. Guess what? My new Pi appears to not quite require 2.5 amps.

Monday, June 13, 2016

100: Avoiding Solder
-- revised, again --

This is a recurring theme with me. I hate soldering, especially teenie-tiny, close together connections. So I keep looking for alternatives -- like screw-down connectors, circuit paint -- and just now "Wire Glue." See my posts 59, 93 and 96.

What's wrong with Wire Glue? a) it was hard to mix up (settled in the bottom), b) very weak "glue"; but here's the real problem:

Here's the test: I measure a known resistor. In my test below, a reading on a 220 Ohm resistor.
Big surprise, it reads .220k Ohms

And here's a reading for a heavy 3/4" line of Wire Glue (on inkjet printer paper):
Wow! 611 Ohms

This stuff should be called "liquid resistor." You will add resistance even if you glue 2 wires together with no apparent gap. PS: a foot long jumper wire reads .0.

Meanwhile, on the insulation front I have tried a couple glue/caulk products. 

Above, the glued wire-ends are both about 1mm apart and after 24 hours curing there is no current leaking between them. I made this test because I felt that red tube was the better insulator (they are the same). The main problem involves the tubes both drying out so that the screw top is plugged within a week or so. Also, the green tube goop sets harder.

More about glue:
My experience with "super glue": not an insulator. And about epoxy: probably not surprising is only a little stronger resistor than the above Wire Glue (and much stronger glue).

black tube 'contains metal'





Friday, June 10, 2016

99: Dog Toy

I have a mad urge to build an interactive amusement for the left-at-home dogs in my extended family. Yeah, I know other people have-done/are-doing this. So what.

I figure on implementing the following features using both a Raspberry Pi and an Arduino Nano.

Things I could provide:
1. Call to the dog -- recorded voice.
2. Show pictures or video clips of owner.
3. Play animal video clips: e.g., squirrels, lambs gamboling.
4. Dispense treats when dog touches proper button. (indicated by voice and LED)
5. React to the dog via motion detector.
6. Take video camera stills.
7. Via smartphone web page:
   - Turn the system on or off.
   - activate different "programs".
   - Keep track of treats supply.
   - Play back today's history of access.
   - Upload images (low-res, B/W) image from the camera.
   
Equipment (wifi & Internet assumed):
Raspberry Pi system -- $100
Arduino Nano (control motor) -- $10
Video monitor/speaker -- $50
Stepper motor -- $10
2 Photosensors -- $2
PIR motion sensor -- $2
2 Capacitive touch sensors -- $15
LEDs -- $1
Pi Camera -- $30
Box -- $30
Temperature sensor -- $1
Wires, other Misc. -- $20
-----------
$200



Saturday, May 21, 2016

98: C++ "Feature"

See http://dicks-photon-arduino.blogspot.com/, post 40. The useful map() function accepts float arguments without complaint but truncates them to ints. Return values can be wildly inaccurate. This may be a feature of all C++ compilers.

IMHO, map() should be coded like this:

float map(float value, float istart, float istop, float ostart, float ostop) {
    return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}

Tuesday, May 17, 2016

97: Problems with DHT22 Temperature/Humidity Sensors

For the past month or so I've tried DHT22s in my granddaughter's hoop house. With it I could provide her with useful humidity and dew point data. Note that a hoop house is a hostile environment for electronics! When the spring sun is out, the temperature/humidity mid-day can be 90F/25% and at 2AM 40F/99% (dew point 40F). I've tried three different DHT22s and they have all failed after a few nights of 99% humidity. For my latest attempt I housed the DHT dangling inside a 16oz water bottle (bottom cut off, sealed at the top). It lasted 2 nights. BTW: they recover after a couple days away from the hoop.

Now I've ordered an HIH-4030, humidity-only sensor (much more expensive). I'll pair it with a cheap TMP36 (cheap & reliable). Unlike the DHT22, the HIH provides a simple analog output. Note: my hoop house processors are actually Arduino-like Particle Photons (native analog gpio) but the humidity problem would be the same for a Pi.

Anyone run across this problem?

Saturday, April 23, 2016

96: Search for the Perfect Connector
-- revised 2/10/2017 --

Here's some recent purchases:


The white spring clips are cheap, easy to use, fairly secure, not waterproof. I've had some of the 2-wire type for a year. They are useful while you are messing around. Generally better than alligator clips.

The lower set are pretty much the opposite: secure, waterproof and not cheap. And once you snap one of these suckers together it's work getting them apart. But really waterproof. Also, they could use a screw-down hole like the white clips.

REVISED: The spring snap closures (right end of black connectors) are brittle in cold weather.

The search goes on...

Thursday, March 24, 2016

95: Computer Farming

If you've followed my blogs you'll know that I involved myself in the Raspberry Pi, Arduino and Particle Photon initially help grandchildren who insist on farming. Covered in earlier posts.

I've recently come across the dirtless farming work done at MIT. See--

http://openag.media.mit.edu/

and

http://www.ted.com/talks/caleb_harper_this_computer_will_grow_your_food_in_the_future?utm_source=tedcomshare&utm_medium=email&utm_campaign=tedspread

The MIT system is open source so I visited their github site and downloaded the source code. Interesting. There's a bit of overlap with my much more modest setup. I haven't finished snooping, but it appears that I have used the same sensors as they have -- temperature, humidity, soil temperature, soil moisture, irrigation switching. For testing, I have also programmed a CO2 gas sensor and photo sensor. They also have code for a pH sensor. I've been thinking about that one. There's a big range of prices.

Their system utilizes Arduino Megas and a Raspberry Pi. My system uses Particle.io Photons and a Raspberry Pi. Note: the Photon is as powerful as a Mega. Because of the Photon's "cloud" my Pi is 100 miles away.

Anyway. Their setup is worth studying.

Friday, January 22, 2016

94: Peltier Cooler/Heater Device
** 1/29/16: Seriously Revised **
-- 1/30/16: some results --

Having the urge to control a thermostat without actually replacing it or messing with it's wiring I bought this sample unit.
It is a 5V/1A item so I tried it with USB: +5 to the red wire, GND to the black. It pulls about .7A. The #1 side got warm, other (#2) got cool. I was curious about what would happen if I switched +5 to the black wire: would it burn out, catch fire, blow up in my face, etc. Well no. It obediently swapped the cool/warm sides. Cool (so to speak)!

So here is a 4-port switch.

REVISED PART:
My previous wiring idea was WRONG:
Start with the following:
1. External +5V & Ground (actually 1A USB)
2. 4-port relay device powered from the computer (+3.3V + G)
3. 4 GPIO ports to IN1, 2, 3, 4 on the switch
4. Wire each relay like this:
In arrow external + or -
Out arrow to Peltier + or -

5. Here's the overall wiring mess. Red lines are +5, blue are GND; lines coming from the edges are from the same +5/GND source. The white blob stands for the Peltier.

6. Initially (of course) all relays are open (since this is a "normally closed" device set the pins HIGH).
Initial state:
- IN1, IN2, IN3, IN4 open
- To make surface #1 warmer: Open IN3 & IN4, Close IN1 & IN2
- To make surface #1 cooler: Open IN1 & IN2 Close IN3 & IN4

Early results: Measuring the surface temperature with a TMP36 sensor I find that 10 seconds of +5 to the Peltier raises the TMP36 reading by 4F degrees (for loop, 10 seconds ON, 5 seconds OFF). More readings soon.

MORE RESULTS (1/30/16): Do you ever check on actual voltage from a USB hub? I was getting pretty big (20 seconds + to raise the temperature (TMP36 sensor) 10F, 20 seconds - to lower it 8F -- yes, up is faster than down. But then I happened to check the voltage: the presumed +5V was actually over 7V. When I changed power adapter so I got actual 5V the 20 second temperature changes were much more modest (2-3 degrees in 20 seconds). The surface that the Peltier rests on also affects results (might need to use a heatsink on the unused surface).

Warning: this gets hot! Be careful.

Comments?

Assuming this is workable, I'm more likely to actually control this setup using a Particle Photon (or Electron, when available) than a Raspberry Pi. Check out my Photon blog at http://dicks-photon-arduino.blogspot.com.

Sunday, December 13, 2015

93: More About Secure Wiring

Way back in post 59 I discussed "Bare Conductive Electric Paint." I hoped to be able to draw circuits on paper with the stuff. Well, not quite. But it was a sort of conductive glue (slow drying and not very strong).

Anyway, the stuff has stiffened up in the tube to where it won't come out the narrow spout anymore, but now I have a new use: sticking breadboard wires M-to-F or M-to-breadboard. Just dip the wire (M) end in the "paint" and insert as usual. And after 20 minutes the connection will be pretty secure and the contact will be good. Also, since the glue isn't too strong, you can get it out if you need to make a change.

Note that wisely, most glue is insulating, not conductive -- probably a good idea.

Tuesday, November 10, 2015

92: Stamp Out Loose Breadboard Wires
-- revised: Nov 25, 2015 --

I hate pulled-loose wires, also not fond of soldering. So, browsing Aliexpress I found 2 possibly useful devices: 8-wire screw terminal strips (I got 4) and a bunch of 2-wire spring clips.

Terminal Strip, Photon (imagine this with a T-cable from a Pi), Spring Clips

Anyway, I like both connectors. The screw strip is a tad over-kill. I probably won't run 220v through it. I particularly like the spring clips -- they are pretty strong. And flexible in number. And cheap: $1.30 for 10 pair.  REVISED: I tried getting more than 1 wire clamped in a single spring clip -- Sorry, not reliable (and not very useful, otherwise)!

Wednesday, November 4, 2015

91: Daylight Savings Time for "Smart Controllers"
(and why you should study cron)

Clock time is important to my "live" Particle Photon system. Imagine my surprise in finding the time off by an hour on Nov. 1. Sloppy me. Particle Docs is explicit that the provided Time.zone() function does not adjust for Daylight Savings.

Lucky for me, I have a Linux/Raspberry Pi to back me up. Here's a little shell script that can correct the time in my Photon program:

thisF=your-function-name
photon=1234... # your Photon's ID
accessT=5678... # your access_token
a=`date | sed -n 's/.* .\([DS]T\).*/\1/p'`
if [ "$a" != "ST" ] ; # previous WAS "DT"
then
  v=-5  # Standard Time (hours less than GMT)
 else
  v=-4  # Daylight Time
fi
# This can tell the Photon 
curl https://api.particle.io/v1/devices/$photon/$thisF \
 -d access_token=$accessT -d "args=$v"

Unix and Linux have a scheduling program called cron. And each user can have a personal set of scheduled programs accessed by the crontab app.. If the above shell code is in a file called "set-tz" then this crontab entry will execute it every Sunday in October, November and March:

# min hr dom mo dow command
...
0 3 * 3,10,11 0 sh set-tz

Read it as: 
"at zero minutes after the hour, 
3am, 
any day-of-month, 
March, October, November, 
Sunday,
Then execute set-tz."

Ugly, but looks isn't everything.

Friday, October 16, 2015

90: Pi Failure! And Fix.
(REVISED: seems like was SD card contacts!!!)

I have 3 Raspberry Pis: 2 of the B/rev2 and a B+. The original one operates 24/7 and provides/collects data from my live Particle Photon system.

I'll skip over #2. The B+ is connected to a large breadboard with an Arduino Nano stuck on it with USB between the Pi and the Nano -- the Nano doing analog devices. The whole setup is for trying new things.

Back to #2: this one sits in a 6" x 8" x 3" lexan box. I use it as a portable example of what you can do with a Pi (see my post 55). It is connected to a variety of devices: LEDs, PIR motion detector, temp sensor, Pi camera, clock-type 7-segment display, a 2-relay switch, a speaker for voice synthesis output, plus battery power.

And it's #2 that has failed. It had been collecting dust (not inside it's box), unplugged for 2-3 months. But I wanted to use the camera so I plugged it in and only the little red power light came on. I took the SD card out and checked it on Pi #1 with fsck. It seemed ok. So, I moved a backup SD to #2. No good. Doesn't ever find the SD card. I tried other useless stuff. Nothing. I vaguely remembered something about the Pi's SD pins getting flattened to where contact fails. Must be what happened.

So I took the nice setup apart. Nasty. The Pi was screwed down to a board. Then I messed with the SD pins on the under side of the Pi -- tried to pry them up a bit. The original SD endlessly tries to boot -- and fails. The backup SD from my Pi#1 works but the setup is all wrong. Crap.

* NEW *

Got a new 16gb SD card. copied Pi#1 data to it (see post 48). Changed all the files (/etc/hostname, /etc/network/interfaces, etc.). Copied Pi#2 data from backup. Inserted new card. It worked. Gimme back the hours wasted.

2 other things:
* The new SD: plastic shell seems a tiny bit thicker.
* I'd forgotten: at some point I had added a layer of tape on the non-contact side of Pi#1's SD card. It must have given me trouble. No wonder later Raspberry Pis went to the micro SD plug.

Saturday, September 19, 2015

89: I Installed a LIVE System!
(after 2+ years of messing around)
-- Revised below 10/11/15 --

Until recently, I have assumed that when it came to installing a real life system I would base it on a Raspberry Pi. But then the Particle Photon came along. Three 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, 2 soil moisture sensors and 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 intended to use 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. It also accumulates statistics and provides a specialized weather report.

The Photon, sensors, switches and wiring cost under $70. My control program in C++ is about 80 lines long (originally, now expanded to 200 lines).

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

Revision: I've added more information on this setup (answering questions) at --

dicks-Photon-Arduino.blogspot.com

Friday, September 18, 2015

88: Battery Backup, Revised Again

After my failures with the Adafruit Powerboost 1000 I complained at an Adafruit forum. Their responce 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.

has powered a Pi for 3 weeks now

I let this setup run for over 24 hours powering either a Raspberry Pi (drawing .34 amps -- using the post 87 device) 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 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.

Wednesday, September 16, 2015

87: Handy Electrical Gadget 

I got a "Charger Doctor" from Adafruit. Not a very enlightening name but a useful device.

It alternates displaying voltage and amps (a few seconds each). The 7-segment display can make a capital 'A' (main image) but can only manage a lame 'u' for 'V' (insert).


Place your 'Doctor' between the USB source and your device to be measured. The image above shows the usual 5v in plus that my Raspberry Pi B+ with USB wifi dongle uses .32 amps.

Thursday, August 13, 2015

86: 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

85: The Particle Photon Moves Up
* updated 8/26/15 *

My $19 Photons are moving farther ahead of Arduinos and edging toward Rpi. Having accurate time functions available from the cloud makes a difference. It isn't crontab but operations can be scheduled. See http://dicks-arduino-nano.blogspot.com/. Getting connected to wifi & the cloud is a cinch; program development: not so great (yet)!

Thursday, July 23, 2015

84: Adding a Small Monitor

I'm installing an Rpi away from my iMac and SSH. So I bought a cheap keyboard and a 7" 1024x600 HDMI monitor.  To make this work, you first need to make the following change:

% sudo nano /boot/config.txt
(delete the "#" from this line)
#disable_overscan=1

(delete the "#" and change 1280 to 1024)
#framebuffer_width=1280
(delete the "#" and change 720 to 600)
#framebuffer_height=720

(press CTRL/o, type y, press CTRL/x)
% sudo reboot

I then needed to enlarge the console font size from 6x16 pixels to something I could read. I did it like this:


When you log in to Linux (or Unix) a file named ".profile" is executed by the shell. To make the little screen readable I edited the .profile file and added the following line at the end:
setfont /usr/share/consolefonts/Uni3-Terminus28x14.pst.gz
(another reboot)
The 14x28 pixel font works for me. There many (hundreds of) fonts. If you like a bit smaller try 24x12 or bigger 32x16.


Tuesday, June 30, 2015

83: Battery Backup Correction
** revised 7/16/15 **

See http://dicks-arduino-nano.blogspot.com/, post 16.

As I am wont to do, I posted without enough testing. Hopefully, corrected now. I'm surprised (shocked?) at how little interest there is in this topic. 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).


Saturday, June 13, 2015

82: Soil Moisture Sensor

These things need analog. So I'll read it through the ether (wifi) from a Particle Core (like Arduino Mega with built-in Cloud access). See my Arduino/Particle blog post 15.