Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit f78d77f942a06c7c2fa534483e327e7aeffa9f27 @theycallmeswift committed Mar 12, 2013
Showing with 157 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +42 −0 README.md
  3. +4 −0 breakfast_serial/__init__.py
  4. +20 −0 breakfast_serial/breakfast_serial.py
  5. +32 −0 breakfast_serial/sensors.py
  6. +24 −0 breakfast_serial/util.py
  7. +13 −0 examples/led.py
  8. +17 −0 setup.py
@@ -0,0 +1,5 @@
+.DS_Store
+*~
+*.sw[a-z]
+*.pyc
+venv/
@@ -0,0 +1,42 @@
+# breakfast_serial
+
+breakfast_serial is a Firmata based framework for interacting with Arduinos over
+serial.
+
+## Arduino Setup
+
+In order to use breakfast_serial, you need to have an arduino running the
+standard firmata.
+
+1. Download the Arduino IDE from the arduino website
+
+ - [OSX](http://arduino.googlecode.com/files/arduino-1.0-macosx.zip)
+ - [Linux 32 bit](http://arduino.googlecode.com/files/arduino-1.0-linux.tgz)
+ - [Linux 64 bit](http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz)
+ - Windows support coming soon.
+
+2. Plug in your Arduino or Arduino compatible microcontroller via USB
+3. Open the Arduino IDE, select: File > Examples > Firmata > StandardFirmata
+4. Click the "Upload" button.
+
+## Installation
+
+Using PyPi
+
+``` bash
+pip install breakfast_serial
+```
+
+#### From Source
+
+``` bash
+git clone git://github.com/theycallmeswift/breakfast_serial.git && cd breakfast_serial
+
+python setup.py install
+```
+
+## Usage
+
+The breakfast_serial library provides a simple abstraction for a number of
+common components. Make sure your arduino is plugged in and is running firmata.
+
@@ -0,0 +1,4 @@
+__version__ = '0.0.0'
+
+from breakfast_serial import *
+from sensors import *
@@ -0,0 +1,20 @@
+import os, re, code
+from pyfirmata import Arduino
+
+class ArduinoNotFoundException(Exception):
+ pass
+
+class FirmataNotOnBoardException(Exception):
+ pass
+
+rport = re.compile('usb|acm')
+ports = filter(rport.search, os.listdir('/dev'))
+
+if len(ports) == 0:
+ raise ArduinoNotFoundException
+
+print "Connecting to /dev/%s" % ports[0]
+__board__ = Arduino("/dev/%s" % ports[0])
+
+if not __board__.get_firmata_version():
+ raise FirmataNotOnBoardException
@@ -0,0 +1,32 @@
+from breakfast_serial import __board__
+from util import setInterval
+
+class Led(object):
+
+ def __init__(self, pin):
+ self._pin = __board__.digital[pin]
+ self._isOn = False
+ self._interval = None
+
+ def on(self):
+ self._pin.write(1)
+ self._isOn = True
+ return self
+
+ def off(self, clear=True):
+ self._pin.write(0)
+ self._isOn = False
+
+ if self._interval and clear:
+ self._interval.clear()
+
+ return self
+
+ def toggle(self):
+ if self._isOn:
+ return self.off(clear=False)
+ else:
+ return self.on()
+
+ def blink(self, millis):
+ self._interval = setInterval(self.toggle, millis)
@@ -0,0 +1,24 @@
+import threading
+from time import sleep
+
+class setInterval(threading.Thread):
+
+ def __init__(self, func, millis):
+ threading.Thread.__init__(self)
+ self.event = threading.Event()
+ self.func = func
+ self.seconds = millis / 1000.0
+ self.shouldRun = True
+
+ self.setDaemon(True)
+ self.start()
+
+ def run(self):
+ self.func()
+ sleep(self.seconds)
+
+ if self.shouldRun:
+ self.run()
+
+ def clear(self):
+ self.shouldRun = False
@@ -0,0 +1,13 @@
+#! /usr/bin/env python
+"""
+This is an example that demonstrates how to blink an
+led using breakfast_serial. It assumes you have an
+led wired up to pin 13.
+"""
+from breakfast_serial import Led
+
+led = Led(13)
+led.blink(200)
+
+import code
+code.InteractiveConsole(locals=globals()).interact()
@@ -0,0 +1,17 @@
+from breakfast_serial import __version__
+from setuptools import setup, find_packages
+
+with open('README.md') as f:
+ long_description = f.read()
+
+setup(
+ name = "breakfast_serial",
+ version = __version__,
+ description = "Python Framework for interacting with Arduino",
+ author = "Swift",
+ author_email = "theycallmeswift@gmail.com",
+ packages = find_packages(),
+ install_requires=['pyfirmata'],
+ url = "http://github.com/theycallmeswift/breakfast_serial/",
+ keywords = ["arduino","firmata"],
+ long_description = long_description )

0 comments on commit f78d77f

Please sign in to comment.