forked from theycallmeswift/BreakfastSerial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f78d77f
Showing
8 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
*~ | ||
*.sw[a-z] | ||
*.pyc | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__version__ = '0.0.0' | ||
|
||
from breakfast_serial import * | ||
from sensors import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]", | ||
packages = find_packages(), | ||
install_requires=['pyfirmata'], | ||
url = "http://github.com/theycallmeswift/breakfast_serial/", | ||
keywords = ["arduino","firmata"], | ||
long_description = long_description ) |