They’re getting bigger!
Tag: python
PiPlanter 2 | Little Plants 1 / Germination Setup
The plants are coming along quite nicely, here is an album of images:
As for my grow setup in this stage, it’s pretty simple. Basically I keep the two desk lamps I have from that area on 24/7 and on the plants. Every morning I put about a half gallon into each of the trays. I also spray about 8oz onto the surface of the plants. Working pretty well so far, all of this growth is only after a week and two days.
PiPlanter 2 | Strange Fuzz
PiPlanter 2 | Update / Dirt / Germs
Hi! In order to do PiPlanter 2 at the scale I want, as always, I need money. I’m applying to this grant to hopefully take this project to unreal new heights. In order to apply, one of the component is assembling a budget. In order to do that though, I need to “complete” the whole project… in my head. I have to be able to think of exactly how I want to do the project. From PCB design to pump system, I have to plan it all in order to assemble a realistic budget. There is a lot of good work that comes with this, like schematics and the budget itself. I’ll for sure upload all of the documentation.
On a more stimulating note: I’ve planted the tomato plants in the same manor that I did last summer and here are some pictures of the growth so far.
Here is the dirt and planted seeds:
Here are some very small sprouts that have developed in the last two days.
PiPlanter 2 | Getting Started Again
So I have decided to re write the PiPlanter from the ground up. In essence, it will accomplish the same exact thing but I’d like it to be a lot more of a stable platform to expand upon in the future. I’d also like PiPlanter to be professional enough to bring to market. First off there are a few things you’d need install & a few modifications you’d need to make to Raspian. First thing’s first, you’ll need to enable SPI in the kernel so:
1 |
sudo vi /etc/modprobe.d/raspi-blacklist.conf |
Comment out the spi-bcm2708 line so it looks like this:
1 |
#blacklist spi-bcm2708 |
Then run this to make it more permanent.
1 |
sudo modprobe spi-bcm2708 |
Now for the real meat of it. You’ll need these packages for SPI and the WiringPi library makes things a whole lot easier for us. This program also relies very heavily
1 2 3 4 5 6 7 8 9 10 |
sudo apt-get install python-imaging python-imaging-tk python-pip python-dev git sudo pip install spidev sudo pip install wiringpi sudo apt-get install apache2 sudo apt-get install mysql-server sudo apt-get install php5 sudo apt-get install php5-mysql sudo pip install tweepy</pre> <pre style="color: #333333;">sudo pip install apscheduler</pre> <pre> |
Revised python code next post.
Raspberry Pi as a dedicated “Twitch Plays Pokemon” Viewer
Update: 12 October 2016
Thanks to commenter Fishscene for pointing out the following:
livestreamer for twitch is broken. Twitch made a change to require an OAUTH token and disallow annonymous viewing. livestreamer hasn’t been updated in over a year. Project was forked to streamlink and includes twitch fix:
https://github.com/streamlink/streamlink
I’ll leave this for prosperity, it has been linked to several time.
I’m not too proud of this but my laptop couldn’t handle streaming ‘Twitch Plays Pokemon’ and me doing day to day tasks and I can’t stop watching now. I’ve decided to use a spare Raspberry Pi have to keep the stream open 24/7 on a spare monitor I have.
Here’s a video:
Thanks to Livestreamer it is unbelievably easy to view this stream.
The following command will install Livestreamer:
1 2 |
apt-get install python-pip pip install livestreamer |
To make things even simpler, I have also written the following python program that will open the stream to HDMI. You can set the line that runs this program as a cron job to run at boot if you wish.
1 2 |
import os os.system("livestreamer twitch.tv/twitchplayspokemon best -np 'omxplayer -o hdmi'") |
Which you can get on your pi with:
1 |
wget https://esologic.com/source/TPP/raspberry_TPP.py |
Once it is downloaded you can run it with:
1 |
python raspberry_TPP.py |
And it will open on your HDMI monitor.
Accessing both SPI ports on the raspberry pi using python
Turns out it’s not that hard at all! Here’s a video of the whole thing working:
This basically works around concepts I first explained here. It’s still really cool though! SPI is really fast and really easy to use, perfect for a novice like me.
Here are the physical representations and schematics of the setup seen on my desk:
Images generated by fritzing.
Here’s the code that makes it all work!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#first ADC setup on SPI port 0 import spidev spi_0 = spidev.SpiDev() spi_0.open(0, 0) #this fucntion can be used to find out the ADC value on ADC 0 def readadc_0(adcnum_0): if adcnum_0 > 7 or adcnum_0 < 0: return -1 r_0 = spi_0.xfer2([1, 8 + adcnum_0 << 4, 0]) adcout_0 = ((r_0[1] & 3) << 8) + r_0[2] return adcout_0 #first ADC setup on SPI port 1 import spidev spi_1 = spidev.SpiDev() spi_1.open(0, 1) #this fucntion can be used to find out the ADC value on ADC 1 def readadc_1(adcnum_1): if adcnum_1 > 7 or adcnum_1 < 0: return -1 r_1 = spi_1.xfer2([1, 8 + adcnum_1 << 4, 0]) adcout_1 = ((r_1[1] & 3) << 8) + r_1[2] return adcout_1 while 1: for x in range (0, 8): print 'Port ' + str(x) + ' | ' + 'adc_0: ' + str(readadc_0(x)).zfill(4) + ' | ' + 'adc_1: ' + str(readadc_1(x)).zfill(4) print '----------------------------------' |
Here is some further reading:
http://www.megaleecher.net/sites/default/files/images/raspberry-pi-rev2-gpio-pinout.jpg
http://hertaville.com/2013/07/24/interfacing-an-spi-adc-mcp3008-chip-to-the-raspberry-pi-using-c/
http://tightdev.net/SpiDev_Doc.pdf
Thanks for reading!
PiPlanter | Goals and changes
So I am 151 miles away from the PiPlanter. But thanks to the internet, modern day routers, and wifi dongles I can pretty much control everything about it from here.
That being said, there are a few things I would like to change about the project. First of all, the program itself needs to be more modular. Reason being is that the core program should never stop running, even if changes need to be made. I should be able to screen the main program once, and then never have to stop it ever. This would be advantageous in a few ways but the main example is that the plants will require more water as they get larger, and then less once they start yielding fruit. I could script this, but I think that it would be best to be able to edit the ‘ontime’ value from the program without having to stop the whole process.
I’ll keep y’all posted as I try to implement this.
DSFU – Adding Email Functionality, Better User Experience, Stable Set Adding
Big post for this project, here’s a video:
This version of the code implements a few really cool features.
First things first I added 10 LEDs that display the percent uploaded of the batch. For example if 13 / 100 photos have been uploaded, the first LED will light up. If 56 / 100 the first 5 LEDs will light up. Eventually the 10 junk LEDs will be replaced with a bar graph which will be mounted externally on the front panel of the enclosure.
I am using every single available output on my Pi now, but I was able to get away with adding 1 more LED that I should be able to use by using a transistor array explained here:
On the code side of things, I updated the way photos are added to the set. It uses the same principal as described in the previous post (using APscheduler to do the adding on an interval). All of these changes can be seen below, it’s still very poorly commented however.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
#GPIO setup import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) in_flickr = 11 GPIO.setup(in_flickr, GPIO.IN) in_hdd = 13 GPIO.setup(in_hdd, GPIO.IN) button = 15 GPIO.setup(button, GPIO.IN) flickr_LED = 3 GPIO.setup(flickr_LED, GPIO.OUT) both_LED = 5 GPIO.setup(both_LED, GPIO.OUT) hdd_LED = 7 GPIO.setup(hdd_LED, GPIO.OUT) stat_LED = 26 GPIO.setup(stat_LED, GPIO.OUT) LED_bar_1 = 18 GPIO.setup(LED_bar_1, GPIO.OUT) LED_bar_2 = 16 GPIO.setup(LED_bar_2, GPIO.OUT) LED_bar_3 = 23 GPIO.setup(LED_bar_3, GPIO.OUT) LED_bar_4 = 21 GPIO.setup(LED_bar_4, GPIO.OUT) LED_bar_5 = 19 GPIO.setup(LED_bar_5, GPIO.OUT) LED_bar_6 = 12 GPIO.setup(LED_bar_6, GPIO.OUT) LED_bar_7 = 10 GPIO.setup(LED_bar_7, GPIO.OUT) LED_bar_8 = 8 GPIO.setup(LED_bar_8, GPIO.OUT) LED_bar_9 = 24 GPIO.setup(LED_bar_9, GPIO.OUT) LED_bar_10 = 22 GPIO.setup(LED_bar_10, GPIO.OUT) global led_bar led_bar = [] led_bar.insert(0,18) led_bar.insert(1,16) led_bar.insert(2,23) led_bar.insert(3,21) led_bar.insert(4,19) led_bar.insert(5,12) led_bar.insert(6,10) led_bar.insert(7,8) led_bar.insert(8,24) led_bar.insert(9,22) for x in xrange(10): GPIO.output(led_bar[x],False) import os from apscheduler.scheduler import Scheduler import logging logging.basicConfig() import time #Flickr Setup import flickrapi api_key = '' api_secret = '' flickr = flickrapi.FlickrAPI(api_key, api_secret, format='json', cache=True) (token, frob) = flickr.get_token_part_one(perms='write') if not token: raw_input("Press ENTER after you authorized this program") flickr.get_token_part_two((token, frob)) #email setup import smtplib import math def sd_walk(): global file_list global file_number global filename global file_current global file_size global file_size_total print '-Starting File Index' for path, subdirs, files in os.walk(image_dir): for filename in files: if os.path.splitext(filename)[1].lower() in ('.jpg','jpeg'): listfiles = os.path.join(path, filename) file_list.insert(file_number,listfiles) print '--File: ' + str(file_number+1) + ' - ' + 'Size: ' + str(round(float(os.path.getsize(listfiles))/(1024),2)) + ' KB ' + ' Added To List: ' + str(listfiles) file_size_total = file_size_total + os.path.getsize(listfiles) file_number = file_number + 1 print '-Indexing Completed ' + 'Total Files: ' + str(file_number) + ' - Total Size: ' + str(round(float(file_size_total)/(1024*1024*1024),2)) + ' GB' + '\n' print '---Starting Upload' def upload_file(): global file_list global file_number global filename global listfiles global file_current global file_size global file_size_total global led_bar if file_current == int(len(file_list)): print '\n----All Files Dealt With...Terminating \n' global scheduler scheduler.shutdown(shutdown_threadpool=False) else: percent = round((float(file_current+1) / float(len(file_list)))*100,0) led = round((float(file_current+1) / float(len(file_list)))*10,0) file_size = file_size + float(os.path.getsize(file_list[file_current]))/(1024) print '----File: ' + str(file_current+1) + ' / ' + str(len(file_list)) + ' - ' + str(round(file_size,2)) + ' KB' + ' / ' + str(round(float(file_size_total)/(1024*1024*1024),2)) + ' GB' + ' - ' + str(percent) + '% Done' + ' - ' + 'LEDs: ' + '1-' + str(led) + ' Lit' print '------File For Upload: ' + file_list[file_current] for x in xrange(int(led)): GPIO.output(led_bar[x],True) upload_response = flickr.upload(filename = file_list[file_current], format='etree') upload_ID = upload_response.find('photoid').text print '------Uploaded - Photo ID: ' + upload_ID id_list.insert(file_current,upload_ID) file_current = file_current + 1 def flickr_upload(): global id_list id_list = [] global file_list file_list = [] global file_current file_current = 0 global file_number file_number = 0 global file_size file_size = 0 global file_size_total file_size_total = 0 sd_walk() global scheduler scheduler = Scheduler(standalone=True) scheduler.add_interval_job(upload_file,seconds=20) scheduler.start() print '--Uploading completed - Adding Files To Set' set_name = 'Uploaded At ' + time.strftime('%m-%d-%y_%H-%M-%S') print '\n---Creating Set: ' + set_name print '---Primary Photo: ' + id_list[0] json_string = flickr.photosets_create(title=set_name, primary_photo_id=id_list[0]) global set_id set_id = json_string.split('"')[5] print '---Set Created: ' + set_id print '---Adding Files To list' global flickr_setno flickr_setno = 0 global scheduler scheduler = Scheduler(standalone=True) scheduler.add_interval_job(flickr_addset,seconds=1) scheduler.start() print '--All Photos Added, Flickr Process Complete \n' flickr_email(set_id,file_current,set_name) def flickr_addset(): global id_list global set_id global flickr_setno if flickr_setno == int(len(id_list)): print '\n---All IDs Dealt With...Terminating \n' global scheduler scheduler.shutdown(shutdown_threadpool=False) else: flickr.photosets_addPhoto(photoset_id=set_id, photo_id=id_list[flickr_setno]) print '----Photo: ' + str(flickr_setno+1) + ' Of ' + str(len(id_list)) + ' Added To Set: ' + str(set_id) + ' ID: ' + str(id_list[flickr_setno]) flickr_setno = flickr_setno + 1 def flickr_email(idd,total_files,name): global file_size_total fromaddr = '' toaddrs = '' username = '' password = '' server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.ehlo() server.login(username,password) print 'Sending Email' SUBJECT = 'Your Photos Have Been Uploaded!' TEXT = ( 'Hello! \n\n' 'You Uploaded a total of: ' + str(total_files) + ' Files' '\n' 'Which Was: ' + str(float(file_size_total)/(1024*1024*1024)) + ' GB' + '\n\n' 'Your Set is Named: "' + str(name) + '" \n\n' 'You can View These Photos Here: \n' 'http://www.flickr.com/photos/99154806@N04/sets/' + str(idd) ) msg = 'Subject: %s\n\n%s' % (SUBJECT, TEXT) server.sendmail(fromaddr, toaddrs, msg) time.sleep(10) server.quit print 'Email Sent \n' while 1: global led_bar GPIO.output(stat_LED, False) if GPIO.input(in_flickr): #print "left" GPIO.output(flickr_LED, True) GPIO.output(both_LED, False) GPIO.output(hdd_LED, False) elif GPIO.input(in_hdd): #print "right" GPIO.output(flickr_LED, False) GPIO.output(both_LED, False) GPIO.output(hdd_LED, True) else: #print "mid" GPIO.output(flickr_LED, False) GPIO.output(both_LED, True) GPIO.output(hdd_LED, False) if GPIO.input(button): GPIO.output(stat_LED, True) print '\n======Start=====\n' print 'Mounting SD' time.sleep(10) global image_dir image_dir = '/mnt/SD/' os.system('hdparm -z /dev/sda1/') os.system('mount -t vfat /dev/sda1/ ' + image_dir) print 'SD Mounted \n' if GPIO.input(in_flickr): flickr_upload() print 'SD Unmouting' time.sleep(10) os.system('umount -t vfat /dev/sda1/ ' + image_dir) print 'SD Unounted' print '======End======' GPIO.output(stat_LED, False) for x in xrange(10): GPIO.output(led_bar[x],False) elif GPIO.input(in_hdd): hdd_upload() print 'SD Unmouting' time.sleep(10) os.system('umount -t vfat /dev/sda1/ ' + image_dir) print 'SD Unounted' print '======End======' GPIO.output(stat_LED, False) for x in xrange(10): GPIO.output(led_bar[x],False) else: both_upload() print 'SD Unmouting' time.sleep(10) os.system('umount -t vfat /dev/sda1/ ' + image_dir) print 'SD Unounted' print '======End======' GPIO.output(stat_LED, False) for x in xrange(10): GPIO.output(led_bar[x],False) |
Thanks for reading!
Multiple Project Update
Hi guys
So I’ve been eeking out all that I can of my last few days of summer, and there hasn’t been much rain or bad weather at all. As a result, I’m not posting much at all.
Doesn’t mean I’m not working though, I’ve been doing a couple things.
First thing’s first my speaker is done. I just need to get a bunch of video edited, and a big post written.
Secondly I’m still working really hard on my dead simple flickr uploader (dsfu). The cool thing about this project is that it has the potential to be very useful to quite a number of people, so I’m trying to make sure that it is very stable, and very easy to duplicate. This means for the most part I’ve been doing a series of 4000+ photo uploads trying to break my script. It’s happened a lot, and you can check my twitter feed to see my brain melt as I try and figure out the problem. This project won’t necessarily be “complete” until I have a 3D printer at my disposal to create the enclosure I want.
As for the PiPlanter, it’s still a work in progress. The update I did with my last post was a start to something really complete it is in no way finished. I still need to move the camera, and the plants.
Thanks for reading!