Controlling High Voltage Mains with Raspberry Pi

As I started to seriously think about replacing my AquaLink I knew that I had to figure out all of the electrical characteristics of the Jandy JVA Valves as well as the Pentair Whisper Pumps and the relays that controlled them.

I determined that the pumps run on 208v and draw a fair amount of current. That being the case I knew that I would not be connecting them to the Pi directly.

I checked out my existing Aqualink and determined that the relays were still in good working order so I decided to use them.  They are 24V DC dual pole single throw (DPST). Here it is if you need to buy some.

 

I still had an issue with controlling even these relays.  The coils required 24VDC to activate.  The Pi supplying only 3.3v or 5v just doesn’t have the ability to drive them.   Even if it could I would need to dampen the fly-back voltage/current when the relay released as that would most certainly blow the Pi up.   You know, that magnetic field collapsing through a coil induces a voltage and current.  See :  Electromagnetic Induction

Granted, I could go and build a circuit to interface between the Pi and the relay, but my electronics skills are a bit rusty for dealing with discrete components.  The thought of blowing things up along a trail of trial and error was not appealing to me.  So off to Mr. Google for some ideas.

I decided that I would use an intermediate relay that could be driven directly from the Pi.  In fact this relay board would perfectly serve the valve actuators as well.   You can get these relay boards in a variety of configurations.  I opted for the 8 Channel because I would use at least 4 even in the most conservative utilitarian design.  I’ll describe my challenges with this board in a future post — but don’t be concerned, they work predictably and are easy to set-up and use.

Raspberry PI Pool Controller – Wiring PI & GPIO Breakout Board by CanaKit

I have been busy.   So this is all that I have done since last posting.

I purchased the CanaKit Raspberry Pi GPIO Breakout Board / Cobbler Bundle from Amazon.  It was a great buy. You can click on the link below to take a look at it.

I quickly figured out that the easiest way to read and control the GPIO pins was to get WiringPI.

Once I had the breakout board I had the  opportunity to prototype some PHP scripts to control LEDs.   That was e-z -peezy-lemon-squeezy.  The biggest challenge was figuring out the GPIO numbering.  I ended up using the -g directive on the WiringPI commands to force the pin reference to be that of the BMC,   The WiringPI website has all the details around that.  There is a CLI command you can use to print out the pin and header references.  That came in handy  Kudos to WiringPI author for providing that.

Now that I understood how to control the pins I moved on to writing a scheduling script.

More about that in the next post.

Day 2 – Setting Up the Base Line Configuration

My work on this project today was primarily house keeping and infrastructure related items.

While I had the monitor, keyboard and mouse connected I went through the process of configuring SSH v2 so that I could run the PI in headless mode.  As part of this I changed the boot configuration to go to CLI rather than the GUI.

Next, I want to have the PI at a fixed IP address, so I configured the WLAN0 with a static from my internal /24 private space.

I have a Business Class Internet connection at my home office and with it I have 5 Public IP addresses.  One of them is currently used for the public IP on the ASA as a PAT address and L2L VPN peer IP.  The others I have as spares for whatever, whenever.

What I want to do is make the Raspberry accessible from the Internet. To do this I created a one to one static NAT on the ASA that essentially points one of my public IP addresses to the private static I assigned to the PI.

I then opened up a few rules on the ASA; SSH and FTP from my known admin locations, and then http and https from the world.

Next I did the following just by following the support sections on raspberrypi.org.  The process could not have been smoother.  Much simpler than my day job.

Updated to get Debian up to snuff.

Installed Apache

Installed PHP v5

Installed MySQL

Installed WiringPI for the GPIO control

Installed WordPress

and Here we are.

 

Day 1 – Fire It Up.

Received the Rasp PI today.  It arrived in good condition.  The packaging and documentation was better than I expected.   Very clear and concise.   Great getting started guide.  I would recommend CanaKit to anyone interested in getting started with a Raspberry.

I’m not one to follow directions immediately for simple things, so I took the board out, connected the power supply and waited for a light to do something.  It did something — solid red.

Interesting I thought.  I wonder what it is doing?

At this point I figure I better not mess around too much and install the board in the case that came with the kit.  At least having it the case would help prevent my blowing the thing up with static discharge.

Next I went and hunted down an HDMI cable.   I didn’t find it in the bucket of cables I had, so I thought I was out of luck and would have to either buy an expensive one at BestBuy or hit up Amazon.   Luckily I remembered I had disconnected my Apple TV a few weeks ago and I had one from that.

Hmmmm… now if I only had a monitor with HDMI input.  Yep, had one right on my desk that I use for my work laptop.   I get the Rasp connected to the monitor and fire it up again.  Nothing, except that solid red light on the board, again.  I check the source on the monitor and confirm that it is set to HDMI.  Bad cable, bad Rasp?  Did I already blow it up?

Maybe it needs a keyboard and mouse connected — seems strange but maybe it will not initially boot headless.  I connected the keyboard and mouse and power cycled.  Nothing.  No lights on the keyboard or mouse.  Still got the solid red light on the board though.

Well, fact is I don’t have the SD card installed, so lets try getting that going.  You see, what I had thought is that the Rasp would go through at least a POST and kick up something from the BIOS to the monitor stating that it had no boot image.  My old school thinking.  I then assume that perhaps it is so stripped down and inexpensive that such a level of functionality has been omitted – not needed really.

I found my 16GB SD Card and attempted to format it to wipe it clean.  Was only able to erase it at first  Got the image on it by following the instructions that came with the kit.  Slid it into the board and rebooted.  Nuttin!  Same ole solid red light, nothing on the screen.

I found the help email address and fired off an email to help explaining the situation.  They got back to me within the hour and wanted to make sure that I was not hanging the SD off of one of the USB ports with an SD reader.  Nope, I had it installed directly in the on-board SD slot.   I let them know and they recommended that I reformat the card as the symptom suggested that a bad format was the issue.   I checked the Raspberry PI web site for help and there was a recommendation there to use the SDFormatter tool from SD Association website.  I downloaded it and ran it but it could not find the SD media despite my being able to browse it from Finder on my Mac.   I finally gave up on the SDFormatter and used Disk Utility on the Mac to force a format.  I then dropped the NOOBS on it.

Finally I got something on the screen — a splash screen with a raspberry.   After following the onscreen instructions I was able to get the unit to connect to my WiFi Network and grab an IP from the DHCP Service running on my ASA.   A few quick checks and it was able to ping out to hosts on the Internet.

 

Day T Minus 5 – Placing the order and waiting.

Ordered the Raspberry PI 3 through Amazon from Canakit.  The cost was what I feel is a reasonable $49.99.  It came with the board, a case, a couple of heat sinks, and a USB power supply.  I have Prime and the shipping was free.

There are other kits available that provide an HDMI cable, SD Card with and NOOBS pre-installed.  I knew I had a 16GB microSD and the HDMI cable, so I went with the kit I found that had just what I needed.

The are a slew of other kits from Canakit as well as others.   My advise is to do your research.

Just in case you are wondering — the date of this post I have set to Dec 21, but it was really published on Dec 28.  I’m playing catch up as I just did the install of WP today, the 28th.