diff options
author | David Runge <david.runge@frqrec.com> | 2014-02-15 01:29:03 +0100 |
---|---|---|
committer | David Runge <david.runge@frqrec.com> | 2014-02-15 01:29:03 +0100 |
commit | 7aa2d1e204c96c7c61210361f0469c23ff11450b (patch) | |
tree | 8e5b152b5c450ac2b2d0665d96cbecd1622ec379 /remote_control | |
parent | 8198e4e885c493808c7c437bb48bcec446d6af94 (diff) | |
download | random241-7aa2d1e204c96c7c61210361f0469c23ff11450b.tar.gz random241-7aa2d1e204c96c7c61210361f0469c23ff11450b.tar.bz2 random241-7aa2d1e204c96c7c61210361f0469c23ff11450b.tar.xz random241-7aa2d1e204c96c7c61210361f0469c23ff11450b.zip |
mv of all scripts to appropriate sub-directories
Diffstat (limited to 'remote_control')
-rw-r--r-- | remote_control/read_gpio.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/remote_control/read_gpio.py b/remote_control/read_gpio.py new file mode 100644 index 0000000..6ddc4a5 --- /dev/null +++ b/remote_control/read_gpio.py @@ -0,0 +1,54 @@ +#a simple beaglebone black instrument, a/v, embedded systems, udk +#see https://github.com/redFrik/udk10-Embedded_Systems + +#this will read analog and digital sensors and send osc data locally to sc +#start it with 'sudo python thursday.py &' + +import Adafruit_BBIO.ADC as ADC +import Adafruit_BBIO.GPIO as GPIO +import time +import liblo as osc + + +#-- settings +analog_sensors= ["P9_39", "P9_40", "P9_41", "P9_42"] # customize here and add your own sensors +#digital_sensors= ["P9_41", "P9_42"] # customize here and add your own sensors +update_rate= 0.05 # time in seconds between each reading +# Define target for osc messages +target = osc.Address('127.0.0.1', 57120, osc.UDP) + +#-- init +ADC.setup() +for sensor in digital_sensors: + GPIO.setup(sensor, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + + +def send_msg(name, sensor, value): + global target + msg = osc.Message(name) + msg.add(name) + msg.add(value) + try: + sc.send(target, msg) # send out osc + except: + pass # do nothing if seding failed + #print msg # debug + +def main(): + last= {} # remember sensor values in a dict + while True: + for sensor in analog_sensors: + #val= int(ADC.read_raw(sensor)) # 0-1799 + val= float(ADC.read(sensor)) # 0.0 - 1.0 + if last.get(sensor, None)!=val: + send_osc("/ana", sensor, val) + last[sensor]= val # store sensor value +# for sensor in digital_sensors: +# val= GPIO.input(sensor) # 0-1 +# if last.get(sensor, None)!=val: +# sendOSC("/dig", sensor, val) +# last[sensor]= val # store sensor value + time.sleep(update_rate) + +if __name__=='__main__': + main() |