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.

Plane | Adding an LCD to the controller, and using Visual Basic for feedback

So here’s a video:

So pretty easy but important step here. For a while I’ve known that I need to have some more feedback from the robot that just LED brightness levels on the controller. This VB program allows me to get analog values from the vehicle and interpret them in any number of ways. You can download and run that program HERE, and like I said in the video I’ve refrained from going open source with my VB programs in the past because they’ve never really had any polish to them. But now I think it will be good to keep this all open.

I also added a 16 * 2 character LCD to my controller. I’ve sacrificed the 6 pins because hopefully in the long run it will be a better experience for the user. I may go back, but for now I’d rather build around something that’s a little more constraining as it will force me to innovate a little bit more. Here’s a picture of the new controller:

Here’s the program:

I didn’t mention in in the video, but I moved the mux from the controller, to the vehicle. It allows me to have 22 analog inputs, and the reason I took so long to finally add it was primarily laziness on my part. Aside from the the code is still very similar but close followers will notice that I cleaned up the way the program receives and sends code. It is much much more organized, and much more expandable. Here’s the “new” controller:

Here’s the new program:

Like I promised in the video, here are a few more properly focused pictures:

Plane | List of things to do [Documentation]

So as school and sports start to ramp up, it’s going to get harder and harder to make time for this project as I want to complete it by the first week of summer.

I made some huge progress today, but it’s really still a baby step, the proof of concept using a brushless motor was reassuring that this will be expandable into something  that is powered by brushless motors (some kind of tricopter) but there’s still quite a lot to get done.

 

First things first, I’d like to get started on re-tooling “Vehicle_Companion” to fit the needs of this new communication protocol I’ve established. Before it acted as an intermediate between the Arduinos, and now it shouldn’t have any effect on that at all, and should only supply visual feedback from the controller.

Reason being is that I need to get more feedback from the drone than led brightness levels. Plus I’m getting a little tired of C, it’ll be good to get back into VB for a while.

 

I also need to come up with a way to power the controller. Plain and simple it doesn’t make sense that it’s still tied to a computer.

 

After that I need to start locking down the vehicle’s PCB. I don’t need to do this to the controller as it’s BOUND to go through countless revisions as the vehicle does. Since the RC car is going to be able to be operated basically with just the joystick, It wouldn’t make sense to over complicate things. Here’s a preview of what it may look like.

 

After that it’s time to make some decisions on what the final form of this thing is going to be, I go back and forth because of a few reasons but for now I that some sort of multirotor is going to be the best.

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 | Powering and Dual Motor Speed + Direction Control [Documentation]

Okay this post is going to be pretty media heavy, here’s a video of the overview of the system:

There are 4 main systems at work here, and like the video said I’ll be going over all of them.

The first is the power system. At it’s core, it’s a Turnigy 5000mAh 3S 20C Lipo Battery Pack that is fed through two voltage converters. The first is 12v-9v@3A and the second is 12v-5v@3A. They are connected all via screw terminals in case they blow out. This all is fed through a large switch before it is fed into the controller and the motor driver, so it can all be cut off at a moments notice.

Here’s a video of me explaining that:

And here are some more detailed pictures:

This is the bottom, I’m still not great at going from breadboard to perfboard so bear with me.

And here’s the top without the 5v module installed, but it would be exactly the same as the 9v one that is:

Power_Top

From there we go to the controller. It’s an Arduino Micro connected to a UartSBee V4 with a XBee Pro 60mW Wire Antenna – Series 1 (802.15.4) installed (the same goes for the controller). It also has a 74HC595 to free up pins which drive LED’s and the motor driver:

Here are some pictures:

Here’s the code:

Next is the motor driver. It’s built around the L298N. Here’s the video

Here are pictures:

It’s my first real use of a perfboard to make a project more permanent which is why it looks awful, but this is what it should look like:

Image generated by fritzing.

The last system is the controller. It’s an arduino micro hooked up to the same xbee system as seen earlier with a joystick and a multiplexer for more inputs. Here’s a video:

And some pictures:

So basically it receives and sends data to and from the controller as seen in the following code:

All of the parts listed in this video can be seen here which is the parts list.

That was a huge post! Thanks for reading and leave a comment if you have any questions.

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:

PiPlanter | Graphing With PHP

Again, short post. This php code:

will produce this graph:

I learned this using this resource:

http://phpmaster.com/charting-with-pchart/