Created
March 3, 2014 11:58
-
-
Save misza222/9323576 to your computer and use it in GitHub Desktop.
Digital Read Serial - Intel Galileo example in python
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
# This is a simple example of interacting with digital input of Intel Galileo board | |
# See http://arduino.cc/en/Tutorial/DigitalReadSerial | |
# and http://www.itsudo.com/galileo/2014/03/01/reading-digital-input-from-galileo-via-sysfs.html | |
import os | |
import time | |
button_gpio = 17 # maps to digital PIN5 on the board | |
# Export gpio port so we can interact with it | |
if(not (os.path.exists("/sys/class/gpio/gpio%d" % button_gpio + "/"))): | |
with open('/sys/class/gpio/export', 'w') as file: | |
file.write('%d' % button_gpio) | |
# Let's make sure that gpio is set to in, so it reads input | |
with open('/sys/class/gpio/gpio%d/direction' % button_gpio, 'w') as file: file.write('in') | |
# Read value from the input and output it to the console | |
while True: | |
with open('/sys/class/gpio/gpio%d/value' % button_gpio, 'r') as file: | |
print file.read() | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment