Category Archives: Python

Python im shack mit der „STUttgart Python Interest Group“

Am Freitag, den 11. Dezember 2015 um 19 Uhr trifft sich im shackspace die Stuttgart-Python-Interest-Group StuPIG.

Diesmal zeigt @michael-k, wie man bei Aexea Celery-Tasks mit Hilfe von Dekoratoren und Metaklassen besser in den Workflow integrieren konnte. Der Vortrag stellt die einzelnen Schritte des Refactorings und was dabei gelernt wurde vor.

Jeder Python/Django-Interessierte ist eingeladen teilzunehmen.

Die Teilnahme ist kostenlos.
Wir freuen uns auf euren Besuch!

Hier die Protokolle der vergangenen Treffen.

Zum Event:
Eintritt frei! (Spenden an shack e.V. sind gerne gesehen) Jeder ist willkommen!
Datum: Freitag, 11. Dezember 2015 ab 19 Uhr
Anfahrt: U4/U9 Haltestelle “Im Degen”, Ulmer Straße 255, Stuttgart Wangen (gegenüber Kulturhaus Arena)

How I Open Sourced My Hamsters for Science

Determined to validate the oft-misguided claims of The Internet, I’ve spent the last month tracking my hamsters’ activity via a homemade Raspberry-Pi-powered Hamstrometer. And recently, I was approached by SuchWowTV to be featured in one of their videos!

If you’re interested in the details behind the build, you can head over to my blog and check out all of the pics and gifs I made of the build process!

Python Mode in Processing

I finally got around to using Python mode for Processing 2.x. I have used pyprocessing for 1.x in the past but the current version is supported by the official IDE. While I am not very good in either, I am more comfortable with Python over Java, Processing’s default language.

I create a few simple “sketches” to get used to the format. After comparison of a few animations in both languages, Python mode was noticeably slower – around 2-3 FPS versus > 15. I worked around this issue by saving each frame as an image and combining them with GIMP to make a .GIF animation. Here are a few sketch outputs – both static and dynamic.

 

Python Mode in Processing

 

 

Python Mode in Processing

Pixelmatrix

Een van de voordelen lid zijn van een hackerspace is dat er de mogelijkheid bestaat om projecten te maken door TkkrLab worden gesponsord. Zo hebben onze leden Michiel en Robert met een Raspberry Pi B+ 2 een pixelmatrix gemaakt die heel flexibel aan te sturen is, o.a. bijvoorbeeld voor een spelletje pong of net zo makkelijk een plasma effect. Dit project is al gedemonstreerd in het Rijksmuseum Twente gestaan tijdens de Overkill festival, heeft meegedaan met BYOB bij TETEM Kunstruimte en is meegegaan tijdens de eth0 winter editie.

Vind je het een leuk project? Like het dan op de Conrad pagina.

Technische informatie op onze wiki.

Bay View Boo!

I’ve lived in Bay View for the past 9 years and I have always loved trick-or-treating night here in the neighborhood (despite the fact that it isn’t actually on halloween!).  After I got some good photos of great costumes last year, I wanted to run a photo booth in front of the house on trick-or-treating night.  Add some procrastination, python and a couple of arduinos to a good idea and voila: Bay View Boo! was born!

I started by building a shelf to hold the photo booth (and double for an extra shelf in the garage for the other 364 days of the year).  On the shelf, I set up an HDMI monitor, driven by my laptop and a logitech webcam for the camera.  The electronics were simple: I had an orange sanwa arcade button attached to an arduino to trigger the photo to be taken and another Arduino connected to a thermal printer from Adafruit to print out a link to the photo.  On the computer, i had a Processing sketch to drive the display, perform the countdown when the button was pressed and send the filename to the printer.  I also ran a little python app that pushed the images to Google Cloud Storage.  An AppEngine app displayed the photos.  I was in a bit of a rush to finish Saturday as I spent half the afternoon at Fantasticon and in my haste I forgot to add page navigation links to the front page.  Oops!  Ah well.  I had the site updated after i tore everything down for the night.  I had one trick or treater ask me if I had “like a raspberry pi in there or something” and I said, “Nope, but i have a couple of Arduinos!”.  “Cool”.  Cool, indeed.

None of the individual pieces of the project were very difficult and it all came together pretty nicely.  The most gratifying part of the night was hearing from people that they had heard from other people to come over and get their photos taken.  Word spreads quickly in Bay View!  I’ll be posting all the code to a github repo shortly and I’ll update this post with the link when I’ve done that.

For next year, I plan on making a couple of changes.  First, I want to have a nicer enclosure for the photo booth and something more permanent to mount the button and printer in than the white cardboard box i cut holes in with an XActo knife.  The second thing I want to do is make some interchangeable front pieces for the booth.  I could use this for lots of events and it would be great to be able to bolt on something that was more thematically appropriate than a painter’s drop cloth with holes cut in it and secured by shiny duct tape!  Ah well, it got the job done and after a while it was dark enough that no one could see my shoddy craftsmanship!  That brings me to my final change for next year: lighting. I had one 250W light ready for when it got dark and it basically sucked.  To everyone who showed up in awesome costumes once it was dark: I’m sorry.  I’ll have better lights next year so everyone can get a great looking photo, even if you don’t come out before the sun goes down!

Bay View Boo!

Here are a few of my favorite photos from the booth.  I hope everyone who stopped by had a good time and enjoyed your photo!  I’ll see you again next year!  In the mantime, head over to Bay View Boo! to browse all the photos from the evening!

Bay View Boo!

Bay View Boo!

Bay View Boo!

Bay View Boo!

Bay View Boo!

Bay View Boo!Bay View Boo!

Bay View Boo!

 

LED klok

Michiel Brink, met 17 jaar onze jongste member, heeft een poosje geleden bij de aankoop van onderdelen een leuke bonus gekregen, een led matrixbord. Er was echter een probleempje, de aanstuurelectronica zat er niet meer in. Gelukkig is Michiel als ambassadeur vd techniek handig genoeg om dit zelf in elkaar te zetten. Hij heeft met een Texas Instruments msp430 controller zelf aanstuur electronica gemaakt die mbv python de tijd laat zien. Nu kan hij genieten van een mooie zelfgemaakte klok.

Meer informatie over dit project kun je vinden op onze wiki

Raspberry Python Call Mom Button – Sunday April 28th

image

I finally got time to hack together the prototype for the class project for my class this weekend. We’re going to be using the RaspberryPi to connect to Plivo and make phone calls, nominally to our Mom’s. I thought one button was boring so our call Mom Button class will actually have 4 buttons suggested as:

* Call Mom
* Call Dad
* Text Mom “I love you”
* Mother’s day special

For more details or to sign up see Meetup.

Raspberry Pi Project: Color My Desk

Cross-posted from Will Makes Things

Control Something

Do you need to exercise some control over the physical world, but don’t want to leave your computer? Well then, take a minute to set the color of my desk on a day of your choosing at http://colormydesk.com/

Yes, I backlit my desk and connected the lights to a server that anyone can control.

First step was to breadboard the circuit to make sure it worked. It did! I then set out to solder it together on some proto board. I mounted it on a second proto board to which I soldered a Raspberry Pi header. The test worked! So I went on to write the software. Here’s the whole setup functioning with the full string of lights installed behind my desk.

THE BASICS

  • I used a Raspberry Pi, a small Linux server.
  • I built a circuit that allows me to power RGB lights with 12-volt power without frying the Raspberry Pi.
  • I developed the website, http://colormydesk.com/, on CakePHP that handles requests from the general public. I ran this on my web server.
  • I wrote some software in Python on the Raspberry Pi that pulls the information daily from the web server using JSON.

If this is already too much for you, consider just going to the site and setting a color: http://colormydesk.com/If you’re really interested in that how / why, read on.

THE NOT-SO-BASICS

Forcing the Pi to Fake PWM

The first step was to get the Raspberry Pi to run some lights. Since the Pi doesn’t have 3 PWM pins, I used this tutorial on using   ServoBlaster for RGB lights.

I ran into some issues and had to use Wheezy instead of Occidentalis because its kernel version, 3.2.7 was more up-to-date. Then I used the older version of ServoBlaster, instead of the one built for the newest 3.6.11 mainly because I didn’t want to figure out how to upgrade the kernel. I used this thread to figure out kernel versions: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=15011&p=278566

Building the Shield

Once that was working, I soldered the basic circuit onto some proto board. I then realized I should’ve used my Raspberry Pi proto board instead of the regular Radio Shack one. But no worries, I hooked up some headers and a custom shield was born.

CakePHP and a Web Server

I built the CakePHP site on a separate web server because I didn’t want the Pi to get overloaded. Besides, I’m a web developer and have plenty of server resources at my disposal. I then wrote some Python code on the Pi to pull the data from the site’s JSON feed with some simple authentication to protect email addresses from the public. A crontab runs every day at 6pm ET to pull the data and turn the lights on. Another one runs at 11pm ET to turn them off.

Translating Hex to ServoBlaster

ServoBlaster allows you to set a ‘servo position’ from 0 – 249. Since a color value for each red, green, or blue, can only be between 0 – 255, I decided to simply clip the last 6 values (250, 251, etc…) down to a servo position of 249. What this really means is that anything above the hex value of F9, just looks like F9. #FFFFFF, is just #F9F9F9, a dimmer white.

 The Python Code


#!/usr/bin/env python

import os

import requests
import json
import datetime
import time

import smtplib
# FUNCTIONS
def pwm(pin, angle):
angle = checkmax(angle)
print "servo[" + str(pin) + "][" + str(angle) + "]"
cmd = "echo " + str(pin) + "=" + str(angle) + " > /dev/servoblaster"
os.system(cmd)

def checkmax(angle): #PWM can only handle 249 units, so we're simply cutting the hex values 250-255 down to 249
if angle > 249:
angle = 249
return angle

def setcolor(hex):
pwm(5, int(hex[1:3],16))
pwm(2, int(hex[3:5],16))
pwm(0, int(hex[5:7],16))

# Define a Thank You Email
def send_email():
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587

sender = ''
password = ''
recipient = data[0]['email_address']
subject = 'Color My Desk: Thank you!'
body = 'Hey '+data[0]['name']+",<br /><br />"+"Thanks for setting my desk color to <span style='color:"+data[0]['color']+"'>" + data[0]['color'] + "</span> today! <br /><br />"+"You wrote: "+data[0]['details']+"<br /><br />"+"Will Wnekowicz"

headers = ["From: " + sender,
"Subject: " + subject,
"To: " + recipient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "rn".join(headers)

session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)

session.ehlo()
session.starttls()
session.ehlo
session.login(sender, password)

session.sendmail(sender, recipient, headers + "rnrn" + body)
session.quit()

# Getting the JSON Feed
os.environ['TZ'] = 'America/New_York'
time.tzset()
r = requests.get('http://colormydesk.com/full_calendar/events/feed?start='+str(datetime.date.today())+'&api_secret=thesecret')
data = r.json()

# Setting the Color of the Strip
if data:
setcolor(data[0]['color'])
send_email()
else:
setcolor("#7733F0") # default color if no color is scheduled, aka no one loves me.