Wednesday, June 14, 2017

Email Smoke Detector Using Raspberry Pi

     Many years ago I built a device that would monitor the signal wire in my home's interconnected smoke detectors, and send me an email and text message when they sounded an alert.  I used a WRT54GL Linksys router that I re-flashed to run an open-source Linux based operating system, and hardware hacked to add an SD card for added storage space, 5 GPIO pins, and two serial ports.  One of the serial ports was used as a console, and the other was used to interface with an AVR microcontroller that did the actual monitoring of the smoke detectors.  It was over engineered and unnecessarily complicated, but it worked, and it introduced me to Linux scripting and microcontroller programming.  It was probably the first electronics project that I fully engineered from start to finish, and I still look back fondly on that project.

     Recently, as I was pondering on what I could do with the various Raspberry Pis I have acquired, it occurred to me that the Pi, with all it's free GPIO pins, would be perfect to revisit and re-engineer my old smoke detector email device.  In fact, this project would take so few resources that there is no reason I can't use the same Pi for several other "smart home" type tasks.  With that in mind I designed the basic layout of this project to be modular and expandable.  I used a piece of 3/16" thick acrylic sheet and some scavenged motherboard standoffs to mount the Pi and the other circuit boards.  I drilled holes in the acrylic slightly smaller than the threads on the standoffs, and just used the standoffs to tap threads into the acrylic.  It actually worked pretty well, and made for a very stable structure.  I bought a breakout board for the Pi's GPIO pins with a ribbon cable to allow for an easy disconnect point and mounted it on a perf-board with pins to provide a test point when all the cables were connected.  I made sure to leave room on the acrylic sheet for future expansion.


     The basic concept for this project is based on the fact that when one of my smoke detectors activates, it sends 9 volts down a signal wire to let all the other smoke detectors know that they also need to sound in order to alert people in all areas of the house.  If I can detect this 9V signal then it's just a matter of writing the code to send the email.  Since this is the case, the project can be broken into two parts, hardware and software.  For the hardware side, I need to determine how to take that 9V signal and convert it into a 3.3V signal that the Pi can receive on one of it's GPIO pins (more than 3.3V could seriously damage the Pi).  On the software side I need to program the Pi to detect the level change on one of it's GPIO pins and send an email when it receives that signal.  Overall this shouldn't be too complicated.  So, let's get to building.

The Hardware

     The hardware side of things ended up being a little more complicated than I expected due to the electrical noise present on signal wire from the smoke detector.  For the sake of documentation I'll go through the failure of the initial design first, but if all you are looking for is the final solution you can skip to the end of this section.
     I started the design with the idea that all I needed to do was convert the 9V signal from the smoke detector into 3.3V for the Pi's GPIO pins.  There are several ways to convert 9V to 3.3V, but I decided to go with a simple voltage divider circuit, since all it would take are a couple of resistors that I already had lying around.  This is how it works:



For the circuit above, the following formula applies:



Since I am trying to convert 9V to 3.3V, all I need to do is find two resistors in my collection that will make V(out) about 1/3 of V(in).  A little bit of math tells us that R1 needs to be about twice the value of R2.  I settled on an 8.2 kohm resistor for R1 and a 3.9 kohm for R2, since that is what I had readily available.  I built the circuit on a breadboard and tested it with a 9 volt battery.  The battery measured 9.7V across it's terminals, and I measured 3.1V for V(out), which is enough to pull the GPIO pin to high.  A little more math said that at 9V even V(out) would be 2.9V, and according to the following website, the voltage really only needs to be >2V in order to pull the input pin to high  (http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/gpio-pin-electrical-specifications)  I thought I had a quick and easy solution, but once I had everything soldered and connected, I was surprised to find that the Pi was sending out multiple false alarms.  It seems that the signal wire for the smoke detector circuit was picking up electrical noise and that was translating into false alarms.  I tried to smooth it out with capacitors, but to no avail.  I decided it was probably better this way, being forced to isolate the smoke detector circuit from the Pis circuitry would protect both the Pi and the smoke detectors, so I went about trying to find the best way to do it.

  I thought about using a relay to isolate the Pi from the noisy electrical system, but there is not enough current on the signal wire to power a relay.  A transistor would probably be just as susceptible to the noise as the Pi, so that solution was out as well.  I brainstormed and researched for days trying to find a solution to this problem, until finally I came across the website of Dr Edward Cheung (http://www.edcheung.com/).  He is a very fascinating man, and I recommend taking the time to look at his web page if you have a chance, but what was of particular interest to me was a project he did in 2004 where he tied the signal wire from his interconnected smoke detectors to his homemade home automation system (http://www.edcheung.com/automa/smoke_det.htm).  In order to do this he used an optoisolator to act as the relay between the smoke detector system and his home automation system.  An optoisolator, also referred to as a photocoupler or an optical coupler, activates a light source, typically an LED, when voltage is applied across one half of the circuit.  A receiver coupled with a transistor on the other side of the circuit detects this light and closes the circuit on that side of the optoisolator.  This electrically isolates the two sides of the circuit. That was exactly the solution I had been searching for (Thank you Dr Cheung).  With this new found idea I quickly ordered some optoisolators and sketched out a circuit design.  I settled on a PC817 for the optoisolator due to it's low cost and quick/free shipping from Amazon.  Here is the datasheet if anyone is interested: http://www.farnell.com/datasheets/73758.pdf   And here is the final circuit:
When it was finally put together it worked perfectly.  A couple of notes regarding the design, I got the idea of using redundant resistors on the smoke detector side of the circuit from Dr Cheung's website as well.  The idea is that if one of the resistors failed it would not interfere with the smoke detector's operation, so the value of R1 and R2 had to be such that just one resistor would be enough to allow for proper operation of the smoke detector, and the sum of both resistors would not be too high as to prevent the optoisolator from sensing the current.  I expected to do some trial and error here, but it turned out that my first try with 680 ohms worked perfectly with one or both resistors.  R3 is just a pull-up resistor to keep the GPIO high until the circuit is closed and it is pulled low by the ground.  The switch on the Pi side of the circuit is to allow me to test multiple iterations of my script without having to set off the smoke detectors every time (my dog hates the sound).  Basically closing the switch simulates the optoisolator closing the circuit due to the smoke detector's activation.


When it came to actually building the circuit on a circuit board instead of the breadboard, I wanted to use a socket for the optoisolator in case I ever needed to change it out.  Unfortunately the only sockets I had lying around were for 16-pin microcontrollers, which were 4 times too big.  I decided to turn this inconvenience into opportunity, and wired the circuit board up to accommodate 4 optoisolators wired to four different GPIO pins.  This way if I ever decide to monitor any other systems with this same Pi, the circuitry is already built.

The Software

While there are many ways I could have approached the software side of this project, I have always wanted to learn to program in Python, so that is what I did.  A couple of Google searches and YouTube tutorials later I was ready to start.  Since this is not a Python tutorial I will just paste the code below.  If anyone would like to use the code to do a similar project of your own please feel free to copy it.  If you republish it, all I ask is to give me credit, and possibly post a link to this blog.  If you are having problems getting the code to work for your own project, please feel free to leave questions in the comments and I will do my best to answer them.  First I am listing the modules that I will be using, as well as providing a link to the Python documentation for each module.

time (used to allow the sleep command to pause the script)
datetime (used to timestamp emails and events)
RPi.GPIO (used manipulate, set, and read GPIO pins on the Raspberry Pi)
email (used to format email messages)
smtplib (used to send email messages)
https://docs.python.org/3.5/library/smtplib.html


And here's the code (obviously email addresses and passwords have been removed):


 #!/usr/bin/env python  
   
 import RPi.GPIO as GPIO # Used to interact with GPIO pins  
 import time # Used for sleep and to timestamp the email  
 from email.mime.text import MIMEText # Used to compose email  
 import smtplib # Used to send email  
   
 # Create a function to run when pin state changes  
 # When this function is called, all it does is send an email  
 # based on the state of the pin  
 def send_alert(channel):  
   
   # Set variables  
   gmail_user = 'address@gmail.com'  
   gmail_pass = 'password'  
   sent_from = gmail_user  
   send_to = 'address1@gmail.com, address2@gmail.com'  
   
   # Create Timestamp  
   timestamp = time.strftime("%m-%d-%y %H:%M:%S")  
   
   # if statement to determine which email msg to send  
   # If the pin is low then the alarm is sounding  
   # Boolean vale of pin when high is true, low is false  
   if GPIO.input(12):  
     subject = 'Smoke Detector Stopped ' + timestamp  
     body = 'Sorry to interrupt you again, but your smoke detector has stopped sounding. It is possible that there is no fire, but it is also possible that the fire has shorted out part or all of your elecrical system. Thank you for your time. \n\n   Sincerly,\n Pi-Server'  
   else:  
     subject = 'Your House May be on Fire ' + timestamp  
     body = 'Sorry to interrupt you, but it seems that your smoke detector is sounding. It is possible that your house is on fire. Thank you for your time. \n\n   Sincerly,\n Pi-Server'  
   
   # Compose the email  
   msg = MIMEText(body)  
   msg['From'] = sent_from  
   msg['To'] = send_to  
   msg['Subject'] = subject  
   
   # Send the email  
   try:   
     server = smtplib.SMTP_SSL('smtp.gmail.com', 465)  
     server.ehlo()  
     server.login(gmail_user, gmail_pass)  
     server.sendmail(sent_from, send_to, msg.as_string())  
     server.close()  
   
     if GPIO.input(12):  
       print 'All-clear email sent!'  
     else:  
       print 'Alert email sent!'  
   except:   
     print 'Something went wrong sending email...'  
   
   
 # Beginning of Program  
   
 GPIO.setmode(GPIO.BCM) # Set's GPIO pins to BCM GPIO numbering  
 INPUT_PIN = 12 # Set's the variable representing the input pin to 12  
 GPIO.setup(INPUT_PIN, GPIO.IN) # Sets the input pin to be an input  
   
 # Wait for the input to change states, run the function send_alert when it does  
 GPIO.add_event_detect(INPUT_PIN, GPIO.BOTH, callback=send_alert, bouncetime=2000)  
   
   
 # Endless loop to keep the program running  
 var = 1  
 while var == 1:  
   print 'smoke detector is being monitored'  
   time.sleep(60)  
   
   

A couple of quick notes here.  In the example above I have only sent the alert to two email addresses.  It is also possible to send a text message using email.  For Verizon, you use the full 10-digit phone number followed by @vtext.com  The advantage of using text message is that it tends to get pushed to your phone faster, since most email just polls the server periodically.  The limitation of using text messages, at least with Verizon, is that to send it from email you are limited to 140 characters including the addresses.  Since I am already sending this to two email addresses, adding two more text message addresses to the message pushes the total over 140 characters, and the message doesn't go through.  The solution to this is simple, I just need to create a second email message that only sends a short message via text.  This is not difficult, I just haven't done it yet.

Whether you've written your own script or used mine above, don't forget to make your file executable:

chmod +x filename.py

If you want to be able to run the script using only the filename without referencing the location then copy the file to /usr/bin, although this is not really necessary in this case since I will just be running the script automatically on boot.

cp /home/pi/filename.py /usr/bin/filename.py

Finally, I want to make the script run when the Pi boots so that I don't have to log in and run the script every time the power flickers.  There are several ways to do this, but the method I used was to edit the /etc/rc.local file.  Use whatever text editor you like, I prefer Vim.

sudo vim /etc/rc.local

Add the following line under the comments, but before the "exit 0"

sudo /home/pi/filename.py &

Don't forget the ampersand at the end to tell the script to run as a separate process.  Since the script is an endless loop, if you leave off the ampersand the Pi could get hung up in the loop and never finish booting.  Also note that this script must be run as root due to accessing the GPIO pins, hence the "sudo".

And that's it.  Connect all the wires, reboot the Pi, and now the Pi is monitoring the smoke detectors.


So What Next?

At the time of writing this blog I have had this project done for about a month.  It has been running 24/7 and tested periodically with both the smoke detectors and the test switch.  No problems so far, and only one false alarm that happened during a lightning storm.  I'm planning on putting this project along with my file server and network equipment on a UPS, so that should stop any power fluctuations from causing false alarms.

So what other uses can I come up with for this Pi?  I'm up for suggestions.  I'm considering a temperature and humidity sensor in the shop, because heat and moisture are bad for both woodworking and electronics.  I'm even considering putting wireless contact sensors on the windows and doors so that the Pi can act as a home security system.

Currently, I'm building a system to allow the Pi to control water flow to a hose bib so I can schedule the sprinklers hooked up to that faucet.  It combines a little plumbing with a little electronics and results in a fairly interesting project.  As soon as I get it up and running I'll post an overview for anyone interested in building something similar.  Until then, stay safe and keep building.

Monday, June 5, 2017

Raspberry Pi

An Introduction

I have several projects that I am currently working on involving Raspberry Pis, and every time I start to write up a blog post I realize that many people might be lost from the beginning without knowing what a Pi is, and how to do the initial set-up for it.  In addition I have some links to information that I need to store for future reference, and this seems like as good of a place as any.  So, let's get started.

What is a Raspberry Pi?


I once told a friend that was stopping by that I was working on a Raspberry Pi, and he was disappointed when he arrived and wasn't offered a slice for dessert.  The Raspberry Pi is a great little single board computer that can be purchased for around $35, depending on the model.  It can do almost anything a modern desktop computer can do, albeit a little slower.  Not only is it inexpensive, but its small size and low power consumption make it ideal for a variety of projects.  It's biggest drawback is that it uses an ARM based processor instead of an X86/X64 processor, so it is limited in that it can only run operating systems that have been developed for or ported over to work on ARM based processors.  That being said, there are many flavors of Linux that have been made to run on the Pi, such as Ubuntu, Kali, and Rasbian (which was written specifically for the Pi), as well as other specialty Linux operating systems such as Kodi (media center), OpenWRT (routing), and Retropie (old video game emulator).  Even Microsoft has made an Internet-of-Things version of Windows 10 that runs on the Pi.  I could make an entire post about the Raspberry Pi and it's capabilities, but so many others have already done this that I will suggest that anyone interested in learning more about the Raspberry Pi let Google be their guide down that rabbit hole.  I have put just a few links below to get you started.

Specs: http://elinux.org/RPi_Hardware
Lots of info from the people that make them: https://www.raspberrypi.org/
More Information: http://elinux.org/RPi_Hub

I have a Raspberry Pi, now what?

Once you have a Raspberry Pi you will need to provide it with an operating system.  The Pi does not come with a built-in hard drive, but instead uses a micro SD card (sold separately) as it's hard drive.  Eight GB should be plenty of space, but I typically use the 16 GB cards since there is not much difference in price.  It is also advised to stick to reputable brands and get a class 10 card for faster write speeds.  The nice thing about using an SD card as a hard drive is that if you want to experiment with different operating systems, switching from one to the next is as easy as swapping out the card.

Now you will need to decide which operating system to use, which all comes down to what you want to do with your Pi.  If you are new to this, and just want to see what the Pi is capable of, I suggest starting with Raspbian, which is a Debian based Linux distribution designed specifically for the Pi.  You can use Raspbian with or without a GUI (called PIXEL), but for new users I would definitely suggest using PIXEL.  If you are a more advanced user, or if you have a specific application in mind, you may want to try a more specialized operating system.  For example, maybe you want to build a portable penetration testing rig, in which case you would want to use Kali Linux.  If you want to build a media center computer then I would recommend LibreELEC or OSMC which are both based on the Kodi Media Player (formally XMBC).  Below I have listed the operating systems that I have tried, and a link to where you can download them.  More comprehensive lists can be found here: https://fabiololix.blogspot.it/2016/05/raspberry-pi-distribution-list.html

Raspbian (Linux Desktop Specialized for RPi):  https://www.raspberrypi.org/downloads/raspbian/
Ubuntu MATE (Ubuntu Linux ported to work with RPi):  https://ubuntu-mate.org/download/
Kali (Linux Desktop specialized for Penetration Testing):  https://www.offensive-security.com/kali-linux-arm-images/
LibreELEC (Media Center):  https://libreelec.tv/downloads/
OSMC (Media Center):  https://osmc.tv/download/
Retropie (Classic Video Game Emulator):  https://retropie.org.uk/download/

For anyone asking "What about NOOBS?", I'm not a big fan, so I intentionally left it out.  If you are interested you can find more info here:  https://www.raspberrypi.org/downloads/noobs/


Installing the Operating System

Once you have decided on an operating system and downloaded the disk image you will need to verify the image and write it to your micro SD card.  This will have to be done from another computer.  If you are using a Linux machine then it can all be done from the command line.  You can find information on that here:  http://elinux.org/RPi_Easy_SD_Card_Setup#Using_the_Linux_command_line
If you are using a Mac then I know nothing about the world you live in, but you can find info on how to do it here:  http://elinux.org/RPi_Easy_SD_Card_Setup#Flashing_the_SD_card_using_Mac_OS_X
The only computer that I have with an SD card slot is a Windows machine, so I will give brief instructions here on how to set up the SD card using Windows.

When a file is downloaded from the internet, typically an SHA1 or MD5 checksum is provided.  The purpose of this is to verify that the file was not tampered with prior to downloading and that it was not corrupted during the download.  I have had success using the following two tools to verify SHA1 and MD5 checksums in Windows.  FCIV (Microsoft File Checksum Integrity Verifier) is a command line utility that is easy to use if you are comfortable with using a Windows terminal.  It can be downloaded from here:  https://www.microsoft.com/en-us/download/details.aspx?id=11533.  Once installed, read the readme.txt document that comes with it for further instructions.  If you would rather use a graphical tool then I recommend Igorware Hasher.  It  is a free utility and can be downloaded here: http://www.igorware.com/hasher

Once you have computed the checksum and compared it to the checksum provided on the download page to verify that your disk image is not corrupt, you are ready to write the image to the SD card.  I use Win32 Disk Imager, which can be downloaded here:  https://sourceforge.net/projects/win32diskimager/
It is pretty simple to use, just select the operating system disk image that you have downloaded for your Pi, select your SD card as the destination, and click "Write".  Just be 100% sure that the drive letter that you select is indeed your SD card, or you could end up overwriting a partition on your computer.

And that's it.  With your newly minted SD card containing the operating system for your Raspberry Pi you are ready to boot it up.  Don't forget, you will need to have a keyboard, mouse, and display in order for you to do the initial configuration on the Raspberry Pi, even if you plan on setting it up for headless operation or remote connectivity.  Below I'll go through some basic hardware options for the Pi, the initial configuration for a Pi running Raspbian, and some basic information regarding the GPIO pins.

Raspberry Pi Hardware Options

I won't spend much time on the Hardware options, just because there are so many of them, and new hardware is being developed all the time.  As I mentioned earlier, you will need a USB keyboard and mouse, as well as a monitor and HDMI cable to do the initial set-up on the Pi.  Depending on the function of the Pi, you can opt to run it headless after that, and just connect to it remotely via SSH or VNC.  If you are building a media center computer then your TV will be your monitor, and I would highly recommend a wireless keyboard/mouse combo with a USB dongle.  You will also need a 5V micro-USB power supply that can provide a minimum of 2 amps.  Most non-Apple phone chargers will work for this purpose, just check the rating on them and make sure that they provide at least 2 amps of current.  If you don't have one handy they can be purchased fairly inexpensively.


The only other piece of hardware that I would consider necessary is a case for your Pi.  Because the circuitry is exposed on all sides, you really want to have something to protect it from coming into contact with anything conductive while it is running.  I've tried many different cases, and I've even made my own.  From my experience the case made by CanaKit is the best, but there are plenty of other good ones out there.  If you are looking to buy a Pi, you can get a kit from CanaKit with the Pi, case, and power supply included, as well as a couple of heat-sinks for your processors.  This is the current link on Amazon for the kit:  https://www.amazon.com/dp/B01C6EQNNK/ref=wl_mb_recs_5_title



As far as other hardware, they sky is the limit.  The Pi has a dedicated camera socket which can be used to connect a camera for high definition pictures and video.  There are also plenty of small touchscreen monitors marketed for the Pi.  If you want to play with the GPIO pins there are breakout boards and cables made specifically for the Pi.  For additional functionality, a wide variety of "HATs" have been developed for the Pi.  These HATs typically connect to the two rows of GPIO pins, making them sit directly on top of the Pi, like a hat (hence the name.)  These can be used for a wide range of things, from driving motors and servos to reading analog sensors, and even adding a GPS module.  If you are interested, take a look at Adafruit's selection of Pi Hats at the following link:  https://www.adafruit.com/category/286
If that's not enough, just Google Raspberry Pi HATs or Pi accessories.  There are new accessories being developed for the Raspberry Pi every day.


Raspbian Initial Configuration

OK, I got off on a little bit of a tangent there regarding the hardware options.  Lets get back to actually using the Pi.  So you've got your Pi, your case, your power supply, and a micro SD card with an operating system installed on it.  What next?  Hook-up your monitor, mouse, keyboard, and Ethernet cable for internet (if you have to use Wifi, that's not a problem, but I won't be covering that here.)  Go ahead and insert the SD card and lets power this baby up.  For the purpose of brevity (if it's not too late for that), I'll only go over the initial set-up for Raspbian.  Other operating systems will likely be similar, and will probably have their own documentation regardless.

If you have installed Raspbian-lite you will be booted into a terminal.  If you have installed Raspbian with Pixel (the graphical desktop interface) you will boot into a desktop environment, similar to Windows.  Either way, you will have to log in. The default user is "pi", and the default password is "raspberry".  Once you are logged in we will need a terminal window, so if you are in the desktop environment click on the black square icon for the terminal in the upper left hand corner of the screen.  Once you are in the terminal, type the following command "sudo raspi-config".  This will bring you to the Configuration Tool.  Typically I'm an advocate of doing everything directly from the command line, just to stay familiar with the Linux terminal, but to keep things easy we'll use the built-in tool.  Below is the main menu for the configuration tool.


As Raspbian gets updated, this menu changes from time to time, so if your menu doesn't look exactly like this don't worry, you should still be able to find the options you need.

The first thing we need to do is to change the default password for the user "pi" (option 1).  This is done for security reasons, so that anyone with knowledge of the default login can't gain access to your system.  Personally I like to go in and create a new user with root permissions, and then delete the user pi altogether, but this is a bit more complicated and not completely necessary, so I won't be covering that here.

Option 2 allows us to change the hostname, which is how the Pi will identify itself on the network.  This step is optional, but I like to make a habit of giving all machines in my network unique hostnames.

The next thing we need to do is set the localization options.  By default the Pi assumes you are in Great Britain, because that is were the Pi originates.  If you are from the other side of the pond in the States, like I am, you will need to notify the Pi.  Select option 4, and proceed through all the sub-menus in order.  For the first menu item, "Change Locale", you will be looking for something like "en_US.UTF-8 UTF-8".  Once you have highlighted this option, use the space-bar to select it, then hit return.  The rest of the menu options, Change Timezone and Change Keyboard Layout, should be fairly self-explanatory.

Option 5, "Interfacing Options," has several sub-menu options, but the only ones I will address here are "Enable SSH" and briefly "Enable VNC"  Both of these options will open the Pi for remote connectivity.  SSH is a protocol that will allow you text-based terminal access from another network computer.  If you are turning the Pi into a server, or you just don't want to leave the keyboard and monitor connected, you will want to enable SSH access.  If you are using a Linux machine to connect to the Pi, you can do it from the terminal command line using the following command: ssh -l <username> <ip.address>  If you are using a Windows machine you will need to use a terminal program like Hyperterminal or Putty.  Putty is the most commonly used terminal program and can be downloaded for free from here: www.putty.org  If you want remote access and are not comfortable having only a text-based terminal, you can turn on VNC server here as well.  VNC will give you remote access to the desktop environment by using a VNC client like RealVNC's VNC Viewer (downloadable from: https://www.realvnc.com/download/viewer/).  Another good option is TightVNC found here: http://www.tightvnc.com/download.php  Unfortunately I have found VNC to be a little slow and laggy on the Pi, so I recommend leaving the keyboard and monitor hooked up if you want to use the desktop environment, and only use SSH for remote connections.

The last thing we need to do is to "Expand the Filesystem" to allow Raspbian to use the entire SD card.  This option is in the sub-menu under "Advanced Options".  Once selected the filesystem will automatically be expanded, and then you should be prompted to reboot.  Once you have completed this last step and rebooted you should be finished with the initial configuration, and be ready to explore the world of Raspberry Pi.

Additional Configuration

I started to include a few other things here, like terminal-based network configuration, changing the root user, and mounting USB drives from the terminal, but I decided this post was already long enough, and the information would not be necessary for all Pi users.  Instead I decided to create a separate post for additional Linux configuration options.  It will be coming soon, and I know you are all very excited.

Raspberry Pi 2B/3B GPIO Pins

The last thing I will touch on in this post is the GPIO pins available on the Raspberry Pi (General Purpose Input/Output).  On the Pi models 2B and 3B there are 40 GPIO pins accessible via the two rows of male header pins.  These pins can be used to connect the Pi to external sensors, or use the Pi to control other electronics.  Really your imagination is the limit.  Just keep in mind that the Pi's GPIO pins use 3.3V logic, so if you are communicating with something using 5, 9, or 12V, you will need to use a level converter of some kind in order to not damage the Pi.



The image above is the layout for the pins on the Raspberry Pi models 2B and 3B.  It was borrowed from the following website, where you can also find the pinouts for other models of the Raspberry Pi:  http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/

For additional information regarding writing Python scripts utilizing the GPIO Pins see the following links:


So that is where I am going to stop for now.  In the future if I run across any useful links regarding general information on the Raspberry Pi I will post them below, just for reference.  If anyone can think of any other basic information that I have omitted please let me know and I will update this post.  

Tuesday, May 30, 2017

Experiments with Lichtenberg Figures on Hardwood

     In one of my earlier blog posts on Lichtenberg Figures I made the observation that they did not work well on hardwoods.  However, after continuing experimentation and my success with the mahogany tealight holders, I decided that I simply had not perfected the technique required for burning figures into hardwood.  When I finished the tealight holders I decided to do a little more experimentation before retiring the Lichtenberg machine back to the shelf.  I chose four species of wood: red oak, mahogany, ambrosia maple, and walnut.  I used two pieces of each species, and in an attempt to be as scientific as possible, I planed and cut all the pieces to the same dimensions, approximately 10" x 3-1/2" x 3/8".  For the electrolyte solution I used 1-1/3 tablespoons of baking soda to 1 cup of hot water.  It seems that the trick for getting hardwoods to work is to make sure that they are thoroughly saturated with electrolyte solution, so two coats are necessary before burning, and then additional coats are required throughout burning as the heat from the procedure dries out the wood.  I presoaked all of the pieces by brushing on a liberal amount of solution while avoiding the edges of the pieces.  I did the second coat of electrolyte immediately before burning, concentrating more solution around the area where the electrodes will connect.  In the video below you can see that in almost all instances the pieces will dry out around the electrodes first and will require constant re-wetting throughout the process.



     Now that all of the pieces are finished, it looks like red oak turned out the best (upper left in the picture below), followed by mahogany (upper right), then walnut (lower left), then maple (lower right) respectively.  By best I mean they had more detail, and less thick, deep burns.  This is subjective of course, and other people might be looking for a different effect.


     My hypothesis was that the harder the wood, the more detail would show up, and the softer the wood, the deeper and thicker the burn would be.  While this seems to be generally true (pine and MDF burn thicker and deeper with less detail than hardwoods), between hardwoods there seems to be other factors effecting the pattern.  Confirming my theory, Red Oak is the hardest of the woods I tested, and it did have the most detail.  Maple is the softest, consequently having the least detail.  Walnut, however, is harder than the Mahogany by a significant degree, but it burned decisively deeper lines with less detail than the Mahogany.  Further experimentation along with additional research into the characteristics of the woods will be necessary to determine what factors other than hardness effect the burn patterns on various species of wood.


     Now that the experiment is over, and the Lichtenberg machine has been relegated to it's spot on the shelf, I am once again left with a bunch of wood panels with neat designs but no real purpose.  This time I decided to do something with them.  I was not overly impressed with the Maple, so I set it aside and proceeded to finish the other panels with four coats of polyurethane.  With some brass hooks and eyelets, and a length of brass chain, I connected the panels together to create a simple wall hanging.  I think it turned out nicely.




Saturday, April 22, 2017

Tealight Candle Holder Featuring Lichtenberg Figures

     After my initial foray into Lichtenberg Figures, the machine ended up being put on a shelf to gather dust as predicted.  While it was inexplicably enjoyable to electrocute wood, the end results were underwhelming to me.  What do I do with a bunch of wood panels with Lichtenberg Figures on them?  By themselves they didn't merit hanging on a wall or giving as gifts.  In fact, the only piece that I was overly pleased with was my hiking stick with the figures burned at the top.  I decided that the best use for the Lichtenberg machine would be to add a decorative touch to pieces that were functional or decorative in their own right.

     As summer approaches and yard work threatens to monopolize my time, large projects in the shop have to take a back seat.  Faced with a little free time over last weekend I decided I could squeeze in a small weekend project, and maybe even find a way to incorporate Lichtenberg figures.  After taking stock of the materials I had on hand, I decided to make a tealight candle holder, since I had some tealights leftover from lathe projects I had done in the past.  As always, the first question to answer is what wood to use, so my first step was to do a little experimenting.





     The first pieces I cut were two pieces of poplar and a piece of mahogany.  These were chosen because they were small cut-off pieces from other projects that were already about the right thickness, and they were close to the top of my wood pile.  I also pulled out some small pieces of maple and walnut, but they would need to be planed, so I saved those for batch two.  I cut the wood to size and drilled the holes for the tealight candles.  I found in previous experiments that in order for the figures to work well in harder woods they needed two or three coats of electrolyte solution, and time to absorb between coats, so I went ahead and prepped the wood for burning.  Below are my experiments and observations burning the first three pieces.  I really do learn something new every time I get this machine out.






     The top piece in the picture above was the first piece.  The problem seemed to be that too much of the electrolyte solution dripped over and soaked into the edges of the piece, causing most of the burning to take place on the edge, not the surface.  The bottom piece above was the second burn.  For this one I made sure not to paint the electrolyte all the way to the edge, leaving a thin, dry boarder around the edge of the surface.  Unfortunately the poplar proved too eager to catch fire and burn, leaving thick smudgy lines, which was not the desired effect.  So far, two pieces burned, two lessons learned.  Just when I was getting a little discouraged, the third piece (in the middle above) brought me a pleasant surprise.  While I was hoping for a little more detail, the mahogany burned like no other wood I had tried previously.  On other woods the pattern started at both electrodes and snaked through the wood until the two ends got close enough to arc.  On the mahogany, the burn seemed to start instantaneously all throughout the wood and quickly begin to arc.

     Based on that experiment, I decided that Mahogany might be the wood to use for this project.  On the bright side, I happen to have some lying around, but on the other side, it is very expensive, and I hate to use it on a dinky little project like this.  In the long run I decided to go ahead and use a little of the Mahogany I had on hand.  What's the point in having it if I never use it for anything, waiting for that perfect project that never comes.  I ripped a length of it, planed it down to a little over a quarter inch, and cut that length into four pieces ready to be burned.  Below is the result.





     I was very pleased with the way these turned out.  You'll notice in the picture that each of these pieces has a lighter area around the boarder.  This is a result of not painting the electrolyte solution all the way to the edge.  I learned early on in the experimenting process that the electrolyte solution always discolors the wood after the electricity has been applied.  It doesn't have the same effect without the electricity, so I can't just go back and apply more around the edges after the burning.  In this case I kinda like the effect, so I don't mind it so much, but it's something to keep in mind.  The other thing to take away from this is that the patterns got better as I went along.  In the picture above, the top piece was done first, and they continue down in chronological order.  I did the first coat of electrolyte on all of them at the same time, and then went back and did the second coat immediately before burning.  This means that the pieces towards the bottom had longer for the first coat to soak in than the top pieces.  This seems to have resulted in a better burn pattern, but also a deeper discoloration from the electrolyte solution.  So it seems to be a trade-off, but the main takeaway is that on harder woods, it is better to give it a little more time to let the first coat of electrolyte solution soak in thoroughly before applying the second coat and burning. 



       OK, so now the burning is done.  Time to put the machine back on the shelf and finish up the project.  I needed some sort of legs or base to hold the mahogany up high enough for the tealights fit down through the holes.  I had a couple of ebony turning blanks that I had purchased because they were on sale, and I think the black color of ebony will go great with the mahogany.  After squaring, cutting, and drilling the ebony, the only thing left is to add a little polyurethane and do the final assembly.

     Typically I would spray-finish this type of project with lacquer or something similar, but I was out of lacquer and I had some polyurethane-type finish lying around.  Since I had never experimented with spraying this particular finish I decided to brush it on... big mistake.  Between the dry-time, the sanding, and the 3-4 re-coats the finishing took forever.  A weekend to build, a week to finish.  It's time to go get some more lacquer.





And here we have the finished product.  I think they turned out well, and they gave me a chance to play with my Lichtenberg machine again, so all-in-all I'm very pleased with this project.

Tuesday, April 11, 2017

End Grain Cutting Board

     End grain cutting boards make great gifts, and are not incredibly difficult to make if you take the time to make sure all measurements and cuts are precise.  The basic concept is to have the wood grains line up vertically so that the knife's edge actually goes down between the grains  instead of cutting across them.  This improves the life of the cutting board, and keeps your kitchen knives sharper for longer.

      The first consideration when planning out a cutting board is to pick the woods that will be used.  While it's good to think about the contrast and color coordination of the wood, there are other important factors.  Most importantly, some woods can cause allergic reactions, and even be directly toxic, which makes them a poor choice for use in a cutting board.  The second consideration is the hardness of the wood.  It is important to use a dense hardwood to extend the longevity of the board, and it is also good to make sure that the woods don't vary too much in hardness to keep the joints from stressing as the wood moves over time.  I always like to use Hard Maple in my cutting boards as it is very easy to work with, and it also has innate anti-bacterial properties.  I chose Purple Heart as the contrast wood, mainly because I like the color, and I have used it before along with Maple to make end grain boards.

       One more quick note about my wood choices, it's always good to know the characteristics of the wood that one is working with.  While Purple Heart is a pretty wood, it does like to chip and tear-out, which can be annoying, but it's not a show stopper.  Be sure to make shallow passes on both the planer and jointer to minimize tear-out, and maybe start with the wood a little thicker than needed in case it takes a couple of extra passes through the planer to get rid of tear-out.  The Hard Maple won't have as many issues with tear-out as the Purple Heart, but it does tend to get burn marks when sawing, especially when cutting two inch thick pieces like we will be doing here.  My trick to dealing with the burn marks is to cut pieces 1/16 to 1/8 inch wider than needed, and then make a second cut on each side of the piece, only taking 1/16 to 1/32 off on the second cut.  This will get rid of the burn marks, and typically will not make new burns when cutting such a small amount.

      OK, time to stop rambling and get to building...


     I was able to get some nice 8/4 Hard Maple stock for this project, but I was unable to find any 8/4 Purple Heart, so a couple of Purple Heart 2"x2" turning blanks will have to suffice.  There was no need to start planing down the whole slab of Maple, so I cut what I needed on the radial arm saw.  There is always waste on a project like this, so it is important to cut a little longer than I think I will need.


     Once the boards are cut, it's time to run them through the planer.  Everything needs to be absolutely flat on both sides and uniform thickness.


     Once the boards are flat, use the jointer to get one edge perfectly flat and perpendicular to the planed surface.  No need to worry about the other edge, we'll get that on the table saw.


     I know I mentioned it previously, but precision is key to making one of these cutting boards turn out well.  It is important to make sure that everything is perfectly square on both the table saw and the jointer or it will stick out like a sore thumb on the finished product.


Now that the board is flat and square it is time to rip some 2x2 strips on the table saw.  Pretty self explanatory.


Next cross-cut the strips to length.  I'm not worried about the length being perfectly precise, or else I would use a sled with a stop, or set a stop against fence, but if the length is not perfect it can be cleaned up after the first gluing with the table saw.


I like to line everything up before getting ready to glue, just to make sure there are no gaps, and everything lines up correctly.


Time for the first gluing.  I'm not the best at this step.  The strips always seem to want to slide and move on me while I am trying to clamp them.  Consider this step practice for the second gluing.  If things aren't perfect after this step they can be cleaned up on the planer and the table saw.  If things aren't perfect after the second gluing then either the project will go into the scrap heap, or be prepared to spend days sanding.  Let the glue dry for 24 hours.

I didn't take any pictures of the clean-up work after the first gluing, but if you've seen one board go through the planer, you've seen them all.  First I cleaned up the glue that squeezed out from in between the strips with a razor blade. Then I ran the glue-ups through the planer again to get all the rest of the glue, and make sure that they were perfectly flat.  This step is very important because sometimes, if the first glue-up is clamped too tight, it will cause the whole piece to bow upward in the middle, which can cause major problems with the second glue-up.  Once the glued-up boards are flat, use the table saw to get one flat edge, perpendicular to the lengthwise strips.


Time to cut the second set of strips.  Technically we are cross-cutting here, but I'm using the ripping fence to get uniform strips, so I'm not sure what you would call this exactly.  Cross-ripping?

You can see the burn marks on the maple I was talking about earlier.  This is where you want to cut these strips a little wider than you need, and then go back and cut off 1/32 to 1/16 of an inch to get rid of the burn marks.  Trust me, nobody wants to be sanding burn marks out of the end-grain after the glue-up, it would take forever.


As I pointed out before, always line up your pieces the way you want them before gluing, and this is an example of why.  If you look closely in the picture above, you can see that the edges of the new strips aren't perfectly parallel, so they leave thin little gaps between the strips at the top and bottom.  This is because I didn't get the boards perfectly flat on the planer after the first glue up.  Luckily, I can use the table saw to fix this at this point.  If I had gone straight to gluing, it would be too late, and the whole thing would end up in the scrap heap.  There is not much that can be done if you end up with gaps between the boards after gluing.  Gaps will leave places for bacteria to grow, hence making the cutting board possibly hazardous to your health, not to mention unsightly.  So let's get this fixed up and move on.


This is much better.  No gaps.  Let's take it over to the gluing bench.


This gluing needs to be as perfect as humanly possible.  Sanding end-grain is an extremely slow and tedious process.  It is already going to take a lot of sanding just to remove the excess glue that won't come off with a razor blade, but if your boards are off by even a little bit be prepared to sand for days.

No pictures of the sanding process either, so you'll have to use your imagination.  Imagine a 48" belt sander with an 80-grit belt.  You would think it would chew through wood faster than you could feed it, but not on end-grain.  Make slow even passes until all the glue marks are gone.  Don't assume that you will get those last few marks during clean-up sanding because you will just end up going back to the belt sander after wasting hours with the hand sander.  Once I am satisfied with both faces of the board, I change the belt to 120 grit to get the sides of the board.  I also round the corners of the board on the belt sander, just for aesthetics.

 After the belt sander, and before I do the final sanding, I like to use a hand router to round over or chamfer the edges on both faces of the board.  This is not only aesthetic, but also helps to get ones fingers under the board when picking it up off of a flat surface.  To clean up the scratches from the belt sander I use a random orbit sander starting with 60 grit, followed by 80, then 120, then 220.  When the sanding is done, take a break, you deserve it.


This particular cutting board is going to be a gift, so I thought I'd personalize it with a little bit of wood burning.  This should be done on the side of the board so as not to mar the cutting surface, and it is much easier to do before oiling the board.


I like to take several days to oil the boards to make sure the wood is fully saturated.  Always use food grade mineral oil, and if it is a gift, it doesn't hurt to give a small bottle of mineral oil with the board so the recipient can add some oil from time to time.  Since I had the oil out, I grabbed a cutting board from the kitchen that I made for my wife years ago so I could freshen up the oil on that one too.  Apply the mineral oil liberally and allow to soak for 30 mins to an hour minimum.  Flip the board over and repeat, and repeat, and repeat.  After doing this for a few days I am satisfied that the board is saturated.  I do the last two coats with a product called "Butcher Block Conditioner", which is made from bees wax and mineral oil.  It is very thick when it first comes out of the bottle, and you have to heat it up to melt the wax.  The wax helps to seal the cutting board so that it doesn't dry out as quickly.  Speaking of drying, I will let this board air out for a few days before gift wrapping it, otherwise the recipient might unwrap an oily mess.



And that's all there is to it.  Mark and Kara, if you are reading this, I hope you don't mind me making a blog post out of your wedding present.  We had a great time in Lewisburg, and I wish you both all the happiness in the world.

Monday, March 20, 2017

Lumber Racks

Storage is key for any shop, but for me, building lumber racks is long overdue, as you can see below.


Step 1:  Move all the lumber and other misc. materials.  Then clean up the area and prepare for painting.  I was hoping to be able to leave the existing stucco in place, but after I moved everything out of the way I determined that the stucco had pulled away from the wall in many places.  Leaving that would just be giving bugs, moisture, and mold a safe place to live, so I began chipping away at the loose stucco.  The picture below is just the beginning of the process.


After two days of removing stucco followed by two days of scrubbing with bleach and detergent, I was finally ready to start priming and painting.  It's amazing the difference a fresh coat of paint can make.


The next step is going to be to install the top and bottom plate for the frame.  Like the other wall project I did, I wanted to shim the bottom plate up off of the floor so that if water does come into the basement it will be able to flow under the frame and not soak into the wood.  I depleted my store of metal shims on the other part of the wall, so I had to come up with something else.  I decided that plastic would actually work better than metal since there was no chance of oxidizing, so I bought a plastic "board" 3-1/2" wide by 8' long and cut it into pieces to act as shims.


I threw together a quick jig on the drill press to drill the shims, and that was all there was to it.


Building the frame was actually the easiest part of the project.  The only tedious part was using the plumb-bob to mark the floor for the shims and the bottom plate, the rest went pretty quickly.



Making and mounting the arms on the other hand was more tedious than I realized it would be.  Two days of making the arms, mounting, and leveling.


In the end it was well worth the time and effort.  And I was even able to shrink my lumber pile further as most of the pine boards and 2x4s used for the arms were left over from other projects or reclaimed scrap from old shelving.


I still need to wire up a light switch and add an overhead electrical outlet, but for the most part I am done.  I might need to do some reorganizing of the lumber, but for now I was just happy to get most of it up off the floor and back where it belongs.


One last thing to point out in the picture below, the second row of arms from the bottom were designed to be at the same height as the top of the radial arm saw, and the first two arms on the right side of that row are 8 inches longer than the other arms on that level.  This way if I ever need to cut a piece of board between 9 and 14 ft long on the radial arm saw it can rest on the ends of those two arms.  That's not a common occurrence, but when it happens I'll be glad I planned ahead for it.


And of course, since I built the lumber racks, I had to build Courtney some shelves of her own, so we now have new laundry room shelves as well.


Wednesday, March 1, 2017

Hiking Stick

With Brass Ferrule, Tapered Grip, Wrist Strap, and Lichtenberg Figures

     Yes, this is just a hiking stick.  I know that this isn't really much of a project, but it has a few neat features that I wanted to record for future reference.  So, without further ado, here's the stick:



     Please disregard my messy network cabinet, it has since been straightened up.  The stick is made from Diamond Willow, which is a very pale color, almost white.  I didn't really like the look of a white hiking stick, so I stained it with some black cherry stain that I had leftover from refurbishing my hardwood floors.  Unfortunately, on the white wood, black cherry turns out bright purple.  The purple hiking stick was worse than a white hiking stick, so I sanded it off and went with a regular cherry stain.  I then finished it with Teak Oil, which I think will hold up better to regular outdoor use than polyurethane or lacquer.  Now, onto the "features":



     The Lichtenberg Figures are just decoration, nothing special, although they did turn out better than I expected (except for the part near the handle that looks "smudged" from where the stick caught on fire.)  The handle itself is wrapped in paracord to add a little cushion to the grip.  I carved a shoulder into the stick at the top and bottom of the grip that then tapered out toward the middle of the grip, so where the paracord meets the wood it is flush, but then the grip tapers out to be slightly thicker than the stick.  

     The best part of this project is the adjustable wrist strap.  I used to own a set of lightweight "trekking poles" that had wrist straps, and I never knew how important they were until I used them.  After a long day of hiking with a stick or a pole, your hands will get very tired from gripping the stick tightly all day.  The wrist strap allows you to put the majority of the weight on your wrist, greatly reducing hand fatigue.  I picked up a pair of "sleeping bag straps" at a local sporting goods store for less than $2 and they worked perfectly.  I drilled a 3/8" hole in the stick, fed the strap through, and then secured the strap to the stick with exterior wood screws.  Going through the hole in the stick should reduce the strain on the strap enough that I don't expect it to pull out of the screws. 

     Last, but certainly not least, is the brass ferrule I added to the tip of the stick to prevent the stick from splitting at the bottom:


     Our local hardware store sells these as brass sleeve bearings, but I like to use them as ferrules when making lathe tools because the brass is soft enough to turn on the wood lathe to add a little extra detail.  They are also very dull when first purchased so I usually shine them up by sanding them down to 1200 grit paper (the one pictured above on the stick is a little scratched from use).  When turning brass on a wood lathe it is important to set your lathe to the lowest possible speed.  I use a homemade skew chisel to SCRAPE (not cut) the decorative rings into the brass.  To secure the ferrule on the lathe I chucked up a piece of ash, and then turned a taper.  Using my largest live center on the tailstock I can push the ferrule into the ash taper and it holds really well.
     Once the ferrule was shined up and ready, I hand carved a shoulder onto the end of the stick, making the outer diameter of the end of the stick just slightly larger than the inner diameter of the ferrule.  I ended up having to use sand paper to get it just right.  I then hammered the ferrule onto the stick, using a second brass bearing to push it down flush against the shoulder.  And that's all there is to it.  Hopefully I never need to remove the ferrule from the stick because I don't believe I could get it loose without cutting it off the stick.

      And on a completely different subject, in case the messy network cabinet in the first picture on this post bothers anyone else as much as it bothers me, below is proof that I've cleaned it up.