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 0a1d27f
Showing
3 changed files
with
91 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,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 |
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,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 |
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,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) |