aboutsummaryrefslogtreecommitdiffstats
path: root/System_Python
diff options
context:
space:
mode:
authorDat Nguyen <nguy2854@umn.edu>2019-09-27 14:40:03 -0500
committerDat Nguyen <nguy2854@umn.edu>2019-09-27 14:40:03 -0500
commit9ade21fbd9301bf8ff49af04c9805e59951a176d (patch)
tree6ae3683e9d56d6145fb9f84f738ae50ed92a597a /System_Python
parentTested on RPi and minor changes to make it work. (diff)
downloadee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar.gz
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar.bz2
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar.lz
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar.xz
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.tar.zst
ee4511w-9ade21fbd9301bf8ff49af04c9805e59951a176d.zip
Initial test_Encoder.py
Diffstat (limited to '')
-rw-r--r--System_Python/test_Encoder.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/System_Python/test_Encoder.py b/System_Python/test_Encoder.py
new file mode 100644
index 0000000..875b5be
--- /dev/null
+++ b/System_Python/test_Encoder.py
@@ -0,0 +1,55 @@
+import time
+import RPi.GPIO as GPIO
+
+GPIO.setmode(GPIO.BCM)
+
+PIN_CLK = 3 #2
+PIN_DAT = 2 #3
+PIN_CS = 4
+delay = 0.0000005
+
+# pin setup done here
+try:
+ GPIO.setup(PIN_CLK,GPIO.OUT)
+ GPIO.setup(PIN_DATA,GPIO.IN)
+ GPIO.setup(PIN_CS,GPIO.OUT)
+ GPIO.output(PIN_CS,1)
+ GPIO.output(PIN_CLK,1)
+except:
+ print "ERROR. Unable to setup the configuration requested"
+
+#wait some time to start
+time.sleep(0.5)
+
+print "GPIO configuration enabled"
+
+def clockup():
+ GPIO.output(PIN_CLK,1)
+def clockdown():
+ GPIO.output(PIN_CLK,0)
+
+def readpos():
+ GPIO.output(PIN_CS,0) #pulls low to start
+
+ time.sleep(delay*2)
+ data = [0]
+ clockdown()
+
+ for i in range(0,10); #bitcount):
+ clockup() #375 ns between each
+ data[i]<<=1
+ data[i]|=GPIO.input(PIN_DATA)
+ clockdown()
+
+ GPIO.output(PIN_CS,1) #pull high after finish
+ return data
+
+try:
+ while(1):
+ print readpos()
+ time.sleep(0.001)
+ #break
+
+finally:
+ print "cleaning up GPIO"
+ GPIO.cleanup() \ No newline at end of file