PiPlanter | Bringing most of it together

Last night I finished the majority of the software for this project. Here’s a video of me going over what happened and what the program does in simpler terms:

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!

That was a lot of explanation, but this program does quite a bit. The source comes in two parts, here’s the python script that handles the brunt of the processing. You will need a bunch of libraries to run this, you could pick through past posts of mine to find what those are, but when I do a final post for this project I will include all of those.

Here’s the .php script that renders the graph from the mysql data. It is called by the python script.

Thanks for reading!

Ammo Box Speakers | Ordering Parts

It’s summer time and I just got a bunch of money for graduating so the next logical step is make a boom box.

I have already ordered the parts, so here’s my list and an explanation for each part:

Amp – This is the heart of the system. Essentially it’s a small amplifier that will run on 12v. According to the reviews it’s pretty loud. It will take a very standard 3.5mm audio input, or a dual channel analog signal which will be easy to build around.

Battery – Long time followers will know I have a pretty big charger that should be able handle charging this beast. It’s 12v, which is the amp runs on.

Speakers – I picked these mostly because if their compatibility with the amp, and their good reviews on amazon, and the fact that they come with a grill and mounting hardware.

Bluetooth Receiver – This is another “selling point” of the system. Users will play music over Bluetooth. It can be powered via 5v, and I have a spare switching regulator that I can use to power it.

Ammo Box Enclosure – This will house the project. It is big enough, and easy enough to cut into to mount the speakers into the side. It is also sealed, so getting sand in it won’t be that big of an issue for beach trips.

I’ll keep updating as parts come in.

PiPlanter | Second round of data collection

So as I said in one of my previous posts, I am going to be collecting a lot of data over the next few weeks while the tomato plants grow. I will be doing this to determine when soil is “dry” and how temperature and light effect that process. For the last week I have been collecting data in the configuration seen in my last post and here is the graph it produced you can click to see the full image:

This graph proves a few things. The first thing is that the relative moisture sensor works. As one can intuitively understand, if you don’t add more water into the system, nature will remove water via evaporation. The overall trend of the blue line (the rel mst sensor) is downward, backing up this point.

The problem with this setup was that I was spitting the voltage across the two probes constantly, which along with the water caused the nails to rapidly oxidize, which is something I would like to avoid in the long term. This also may have seriously corrupted the data so besides general trends, this whole set is unusable.

This isn’t necessarily a bad thing though, as I wanted to conduct a second trial with more probes and more dirt.

I decided to go with 4 probes, and here are a few pictures of the assembly process. Assembly process is the same, I just did it at my school:

I cut it into 3cm sections and then drilled holes on the midpoints of the 2nd and 3rd cm as seen in a photo below.

Here are the holes drilled for the nails

Here are the nails inserted into all 4

Here is the wire wrapped around the nail

Once solder is applied, the connection is very strong and conductive

Here’s the gluing process

Here are all of the sensors assembled. I attached headers to the other ends as seen in the last post.

Since i’m using 4 sensors now, and to get around the oxidation problem, I added a NPN transistor to cut the ground current when the sensor isn’t being used so it only turns on when it’s getting polled. Here is the new python code:

It’s pretty much the same thing.

The graph is also very similar, but I won’t post that code as it’s not different enough.

Here are pictures of setting up the whole system:

I used the same soil as seen in the previous post, and added 125mL of water to each sample.

Here’s a video of me explaining the whole process:

Once enough data is collected I’ll post a graph of it here.

PiPlanter | Planting Seeds!

This is a short post illustrating the process of planting the seeds.

 

PiPlanter | Moisture detector and a few other updates

Long time viewers will remember when this idea was conceived two Novembers ago, but essentially it’s a way to detect the relative moisture of a substance.

The principal is the same as in the above post, but this time, I made it bigger and attached it to a Raspberry Pi. The reason this is essential, is because I recently purchased a 12v DC pump capable of moving water. I will be able to sense the relative moisture in the plant, and then the plant will be able to water “itself”.

That will be done in python with the same basic technique I’ve been using all along, but in addition to gathering data about the plant every hour or so, it will be able to see if the plant needs water (by checking hopefully an array of moisture sensors) and then turning on the pump and watering it. I will also eventually integrate twitter and a webcam, but those cosmetic editions come once I know the system works.

To test it, I’ve added another set of data to the graph as seen in the last post and created a testing environment in my windowsill.

Basically I’ve put some dirt and 100mL of water into a container and inserted the sensor and am monitoring the moisture level over the next n hours, here are some pictures:

And here is a graph of some of the data:

I will make another post later today illustrating the process of plating the seeds.

PiPlanter | Graphing timed mysql data with pchart

Time to get this data we’re harvesting graphed. In a couple past posts, I’ve used pChart to graph random data but now since data is getting dumped into a mysql chart, it would make sense to try and graph that data.

To install pChart on my system (same installs as listed in this post) to do that do the following:

First, get the php5-gd package by running:

Then download, rename and move the pChart files to the proper directory:

Now pChart is ready to be used.

I used a lot of the info found here:

http://wiki.pchart.net/doc.mysql.integration.html

http://wiki.pchart.net/doc.doc.draw.scale.html

The code is pretty well commented so I’m not really going to get into describing it, but essentially, the following php will retrieve data from a mysql table (which is being populated by a python script seen in this post) and after leaving it on in my room for like 3 days, render this graph:

Here’s that php script:

PiPlanter | Basic package setup and bringing everything together

I’m in a hotel trying to occupy myself with something interesting so I’ve decided to work on this. I had to re-image the SD card I’ve been developing this project on, but I saved to code so there’s no problem there. Now I need to re-install all the basic packages.

First I need to get the components of a LAMP server with the following commands:

Once you get the mysql server setup, you’ll need to create a database and tables in mysql.

To create the database you’ll be using run the following command:

And then grant the proper privileges to use later with the command:

Then we can enter the database and create a table:

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:

We will also need WiringPi:

Then you need to get APscheduler, the timing program used to execute the incremental timing with the following commands:

You will need mysqldb to interface python and mysql:

Once you reboot, the following program should work:

And there you go! The program should log data every minute and then every hour to two different tables. To view those data sets as php tables you can use this php script:

Sometime later I’ll get to graphing the data.

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:

[py]
#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
logging.basicConfig()

#GPIO setup
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)

GPIO.cleanup()

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
time.sleep(.1)
GPIO.output(led1, False) #turns the led off

def slowSample():
print “Job 2” , datetime.now()
GPIO.output(led2, True) #turns the led on
time.sleep(5)
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)
scheduler.start()
[/py]

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.

PiPlanter | Going from analog data to the web using python, mysql and php

Here’s a video:

Essentially, the adc reads an analog value and sends it to python. Python connects to a mysql database and adds the data to that. Once the user accesses the php script, a table, containing all of the values, is rendered.
First of all, you’ll need to make a mysql table with the correct specifications:
This creates a table that is found in the python script so it is very important that the TABLE values match as well as the column names.
Here’s that python script:

This reads the values from the adc (it is wired up as seen in this post)
Here’s the php, it reads the values from the adc_input_data_10 table on the adc_database.
This is all very preliminary stuff, and I’ll tighten up the code as time goes on.

PiPlanter | Graphing With PHP 2

This is a much more refined version of that graph I created earlier.

This one is much more detailed, and the sizes of the graph can easily be controlled with the imageSizeX and Y Vals.

This program will render:

This image:

And by modifying the values mentioned above to:

You will get this image: