What I want to do before the end of the summer

As this is a development blog, I figure that those reading would want to know what I want to do by the end of the summer.

First things first, I really want to finish my speaker system once I get home. As you may or may not be able to tell, I’m currently away from my desk and on vacation. The final parts for the speaker are waiting at my house as I type this, so once I get home on Saturday I hope to finish the speakers either that night or at least the next day. Expect a higher-quality video / post about that project as I had help making it so I was able to get some really cool “making of footage” so the video should be a little better quality.

I also want to get a Raspberry Pi and Arduino board talking over an xbee network. Why I want to do this I’m not sure, but this seems like something it may be useful to learn how to do, so I’ll probably come up with some sort of dummy project to demo that technology. I wonder if I’ll use that serial deliminator script I wrote for the arduino so many months ago. That’s still probably my best work as a programmer.

I have a cool idea for a Raspberry Pi project. My mother takes a lot of photographs on her really nice DSLR camera. Much like most “normal” people she isn’t really keen on uploading photo after photo to an image hosting service. Because of this, she often either doesn’t share these photos with anybody, and takes separate photographs with her iPhone to share with others. I think I’m going to come up with some solution that has a very simple user interface (like 1 button and 2 LED’s) that can upload a whole SD card of photo’s to flickr and then email the user once it’s done.

Yeah! If there’s any stuff you want me to do / see let me know in the comments!

PiPlanter – A Plant Growth Automator

New Version The Post Below Is Out Of Date Click Here For The New Version

This post is many months in the making and I am very proud of the thing’s I’ve done here, and very thankful to all of those (specifically at www.reddit.com/r/raspberry_pi) who have helped me along my way to getting this project up and running.

This page contains every single post related to this project, please feel free to go back and look at my progression and pick up tips along the way if you want to try something like this.

Let’s get this going, here’s an overview video:

There are 8 parts to this system and, you guessed it, I’ll be going in-depth about every single one!

Sensor Network

So at it’s core, the PiPlanter is a Sensor Network & Pump System. Here’s a video explaining the sensor array:

This project uses a TMP35-37 sensor to get a pretty precise temperature reading of the room. Later down in this post you can find out the algorithm to determine the temperature in Fahrenheit. It also uses a basic LDR to get the relative ambient light level in the room. Along with those two sensors, there are 4 relative humidity sensors of my own design, here’s a picture of them as seen in this post:


They’re hooked up to the ADC (mentioned later) in the same way that the LDR is, with a voltage dividing resistor, and then fed directly into ADC. The principal behind this sensor is that when you insert it into soil, the water in that soil connected the two probes, causing a voltage to flow across them. So if there is more water in the soil, more electrons will flow across them, and the analog value will be higher. It’s very basic, but it works. I’ve done several long term tests, and over time, as the soil becomes dryer, the value gets lower, indicating relative dryness. Here is a picture of the four probes in the soil, with the plants.

The TMP sensor’s output is plugged directly into the ADC and the LDR is very basically connected to the ADC as well, this is essentially how how the whole thing is setup on the breadboard:


Pump System

The pump system is pretty dead simple. Essentially it is a PowerSwitch Tail II switching the mains to a 9v DC power supply. The 9v power supply is connected directly to a 12v DC submersible pump. Instead of using a motor driver chip, which requires 3 pins to do, and the chip would get hot and whatnot, I’ve decided to go with this method.

The pump is not self priming. This means it cannot make the transition from pumping air to pumping water. I wrestled with this problem for a long time, and came up with what I think is an elegant solution. I submerged the pump directly into the water, which means the pump will never fill with air, and will always pump water when activated. Here’s a video explaining the pump system:

Raspberry Pi ADC

The next system is the ADC connected to the Raspberry Pi. It is an 8 bit, 8 port analog to digital converter that can easily run on 3.3v so it’s perfect for the pi. Here is the chip, and you set it up as follows (I took this from an earlier post I wrote)

Now we need to set up the specific libraries for python the first of which being spidev, the spi tool for the raspberry pi which we can grab from git using the following commands:

You also need to (copied from http://scruss.com/blog/2013/01/19/the-quite-rubbish-clock/):

As root, edit the kernel module blacklist file:

Comment out the spi-bcm2708 line so it looks like this:

Save the file so that the module will load on future reboots. To enable the module now, enter:

To read from the ADC, add the following to your python code. The full code will be listed later:

So just use “readadc(n)” to get a value.

Python Code

I’ve made a real effort this time to comment my code well, so I’m not going to do a line by line breakdown like I often do, but I will clearly state the installs and setup things as follows. I’m assuming you have python-dev installed.

Download and install: APScheduler, this is a very straight forward install

Download and install: tweepy, you will need to go through the API setup process.

Download and install: flickrapi, you will need to go through the API setup process.

Here’s the source code for the python component of this project:

There you go! Essentially, every hour, the raspberry pi samples data from 4 humidity probes, an LDR and a tmp sensor. Once the sampling is complete, it dumps the data into a mysql database. From there the data is rendered into a graph using pChart in the form of a .png image. From there, that .png files is uploaded to flickr using this api. Once the file is uploaded, it returns it’s photo ID to the python script. From there, a tweet is built containing the brightness at the time of the tweet, the temperature at the time of the tweet, and the average moisture of the plants. It also uses the photo ID from flickr obtained earlier to build a URL leading to that image on flickr which it tweets as well. The final part of the tweet is a url that leads to this post! (taken from)

MySQL Database

The database is extremely simple, after installing MySQL set it up and create table that follows this syntax:

Pretty basic stuff, the table is just where the python script dumps the data every hour.

PChart Graph

The software driving the graphing part of the project is a bit of php graphing software called pchart. It allows me to graph mysql values from a table in a variety of ways. It is very important, and the code for the php script is as follows:

As you may be able to guess, upon the calling of this script, the program looks for a table called “piplanter_table_17” and does a bunch of stuff as commented to produce a graph. This is what a sample graph looks like:

Wed Jun 26 19:39:17 2013

This is data taken over 6 days, and it’s a lot to look at, but it’s good stuff.

Twitter & Flickr Integration

As you hopefully derived from the python code, this project uses Twitter to send data to me. Instead of using an email server or sending sms messages, I decided on twitter because of a few reasons. I use the service constantly, so I won’t ever miss a tweet. The API seemed really easy to use (and it was!) and allowed more than one person to acess the data at any one time. I decided to use flickr as my image hosting service for a lot of the same reasons, but the main one was their 1TB storage per person. You’ve already seen a sample flickr upload, so here’s a sample tweet:

That’s essentially it! Thank you for reading, and please ask questions.

PiPlanter | Using APScheduler to get timed samples in python

I’m taking a “break” from my drone while I save some money to buy more tricopter parts, and since the weather’s getting nicer and nicer I’ve decided to start working on my PiPlanter again.

As a refresher, the PiPlanter is a Raspberry Pi powered garden. The goal is for it to just be able to be plugged in and add water to a water source and have the Pi monitor temp and moisture levels to be able to add more water as needed.

I’ve shown that is relatively easy to go from analog sensors to good looking tables and graphs using the raspberry pi, the problem that I ran into however was timing.

It became harder and harder to use the time.sleep function in python to handle long periods of time. When you are dealing with things like plants, you don’t need to water it very often, but for data’s sake, you should be polling the sensors a lot.

I’ve landed on the use of APScheduler in python, and here’s my source code:

#Timing setup
from datetime import datetime
from apscheduler.scheduler import Scheduler
import time

import logging #if you start getting logging errors, uncomment these two lines

#GPIO setup
import RPi.GPIO as GPIO


pin = 26 #pin for the adc
GPIO.setup(pin, GPIO.OUT)
led1 = 11 #pin for the short indicator led
GPIO.setup(led1, GPIO.OUT)
led2 = 13 #pin for other long indicator led
GPIO.setup(led2, GPIO.OUT)

#the adc’s SPI setup
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)

going = True

#fuction that can read the adc
def readadc(adcnum):
# read SPI data from MCP3008 chip, 8 possible adc’s (0 thru 7)
if adcnum > 7 or adcnum < 0:
return -1
r = spi.xfer2([1, 8 + adcnum << 4, 0])
adcout = ((r[1] & 3) << 8) + r[2]
return adcout

def rapidSample():
sampleTemp1 = (((readadc(0)*3.3)/1024)/(10.0/1000)) #this translates the analog voltage to temperature in def F
sampleLght1 = readadc(1)
samplePot1 = readadc(2)

GPIO.output(led1, True) #turns the led on
time.sleep(.1) #sleeps a little bit so you can see the LED on
print "Job 1", datetime.now(),"LDR:",sampleLght1 ,"Pot:",samplePot1,"Temp:",sampleTemp1 #prints the debug info
GPIO.output(led1, False) #turns the led off

def slowSample():
print "Job 2" , datetime.now()
GPIO.output(led2, True) #turns the led on
GPIO.output(led2, False) #turns the led on

if __name__ == ‘__main__’:
#the following 3 lines start up the interval job and keep it going
scheduler = Scheduler(standalone=True)
scheduler.add_interval_job(rapidSample, seconds=1)
scheduler.add_interval_job(slowSample, minutes=1)

This produces a loop that flashed a green led on and of for .1 seconds at a time per second, and then every minute, turns on a speaker and a red led for 5 seconds then turns it off. There are some images of what goes on below.

Here is a picture of the the print dialog in python:

You can see that the first job (green led) posts the values from the analog sensors every second

The second job (red led) just posts the time. But the function is expandable to do anything at any time.

Here are pictures of the board and the circuit in action:

Both LED’s off

The Green LED on, the red circled process in the printout

Here are both on

The next step is adding the mySQL in as seen in some other posts.

Plane | Ground based system all working! [Demonstration]

Pretty big day for me today. Here’s a video:

I’m pretty proud of this one, the only problem of this is that the l298N get’s too hot, you can see in the pictures that I’ve installed a makeshift heatsink but it still get’s really hot:

Motor Driver 1

I also installed the 5v@3a regulator I mentioned in the last post, here are some pictures:


Here’s the vehicle code:

Here’s the controller code:

I’m verrry proud of the progress thus far. As for next steps, I need to lock down the vehicle circuit into a soldered perf-board, and I need to come up with a better power solution for the controller. Thanks for reading!

Plane | Final Static Prototype [Documentation]

Let me preface this by saying that I am immensely proud of this work. The work up to here is very special and I can only hope that my work going forward is as good as this.

So I’m calling this the “Final Static Prototype” because it’s pretty damn complete for being prototype and it does not move. I intend on making a moving, non-flying prototype sometime in the future. Let’s start out with the video:

Now an explanation for each of the components starting with the controller.

It’s pretty much the same deal I’ve been using this entire time. The program works as follows.

1. The computer sends a delay value and a cycle number

2. The arduino receives that data

3. The arduino sends the debug switch value, the x and y values of the joystick and the pot value.

4. The program renders that information on the program.

Here’s the controller’s source:

Now for the output simulator (eventually the plane)

This works like the controller with the “handshake” protocol as described above, but it writes to the servos and then sends sensor values. Here’s that source:

The visual basic program which I’m calling “Vehicle Companion” can be found here in all of it’s glory. The picture below also shows the whole system.

Now all I need is the money to make this thing wireless because I’ve got a way to make it into a moving prototype using materials I already have. I’ll put a donate button somewhere on this website eventually if you want to help me out.

Thanks for reading.

New Monitor!

I recently built my 1st computer and the monitor finally came in. Pictures are below.

The computer is built around the intel i5-2500k. It’s got 8gb of ram, 500gb HDD, 60gb SSD for caching (face melting speeds), 750w PSW, nVidia GTX560ti 448core EVGA classified, and an AsRock extreme4 gen3 motherboard. It’s the fastest computer I’ve ever owned.


It’s 20 inches (way bigger than it sounds) and is LED backlit. It looks really really really nice.