Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichardson23 committed Mar 11, 2012
0 parents commit 0a1d27f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README
@@ -0,0 +1,7 @@
mrBBIO

A Python module for using Arduino-like language to control IO pins on
the BeagleBone.

Some code based on PyBBIO by Alexander Hiam:
https://github.com/alexanderhiam/PyBBIO
69 changes: 69 additions & 0 deletions mrbbio.py
@@ -0,0 +1,69 @@
import time

HIGH = "HIGH"
LOW = "LOW"
OUTPUT = "OUTPUT"
INPUT = "INPUT"
pinList = []

def pinMode(pin, direction):
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (pin))
fw.close()
fileName = "/sys/class/gpio/gpio%d/direction" % (pin)
fw = file(fileName, "w")
if direction == "INPUT":
fw.write("in")
else:
fw.write("out")
fw.close()
pinList.append(pin)


def digitalWrite(pin, status):
fileName = "/sys/class/gpio/gpio%d/value" % (pin)
fw = file(fileName, "w")
if status == "HIGH":
fw.write("1")
if status == "LOW":
fw.write("0")
fw.close()

def digitalRead(pin):
fileName = "/sys/class/gpio/gpio%d/value" % (pin)
fw = file(fileName, "r")
inData = fw.read()
if inData == "0\n":
return LOW
if inData == "1\n":
return HIGH

def pinUnexport(pin):
fw = file("/sys/class/gpio/unexport", "w")
fw.write("%d" % (pin))
fw.close()

def cleanup():
for pin in pinList:
pinUnexport(pin)

def delay(millis):
time.sleep(millis/1000)

def run(setup, main): # from PyBBIO by Alexander Hiam - ahiam@marlboro.edu - www.alexanderhiam.com https://github.com/alexanderhiam/PyBBIO
""" The main loop; must be passed a setup and a main function.
First the setup function will be called once, then the main
function wil be continuously until a stop signal is raised,
e.g. CTRL-C or a call to the stop() function from within the
main function. """
try:
setup()
while (True):
main()
except KeyboardInterrupt:
# Manual exit signal, clean up and exit happy
cleanup()
except Exception, e:
# Something may have gone wrong, clean up and print exception
cleanup()
print e
15 changes: 15 additions & 0 deletions test.py
@@ -0,0 +1,15 @@
#!/usr/bin/python
from mrbbio import *

def setup():
pinMode(44, OUTPUT)
pinMode(26, OUTPUT)
pinMode(70, INPUT)

def loop():
digitalWrite(44, HIGH)
delay(1000)
digitalWrite(44, LOW)
delay(1000)

run(setup, loop)

0 comments on commit 0a1d27f

Please sign in to comment.