aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaspberry Pi <pi@umn.edu>2019-10-01 18:28:44 -0500
committerRaspberry Pi <pi@umn.edu>2019-10-01 18:28:44 -0500
commitc9be15667f62ba33dbbe0015037bb58d824fcdd5 (patch)
tree84b6a0e95716d272bcfe72f702804a0b57899ff5
parentInitial test_Encoder.py (diff)
downloadee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar.gz
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar.bz2
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar.lz
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar.xz
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.tar.zst
ee4511w-c9be15667f62ba33dbbe0015037bb58d824fcdd5.zip
Got encoder working
-rw-r--r--System_Python/test_Encoder.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/System_Python/test_Encoder.py b/System_Python/test_Encoder.py
index 875b5be..ab74c6e 100644
--- a/System_Python/test_Encoder.py
+++ b/System_Python/test_Encoder.py
@@ -3,8 +3,8 @@ import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
-PIN_CLK = 3 #2
-PIN_DAT = 2 #3
+PIN_CLK = 2
+PIN_DATA = 3
PIN_CS = 4
delay = 0.0000005
@@ -16,12 +16,12 @@ try:
GPIO.output(PIN_CS,1)
GPIO.output(PIN_CLK,1)
except:
- print "ERROR. Unable to setup the configuration requested"
+ print("ERROR. Unable to setup the configuration requested")
#wait some time to start
time.sleep(0.5)
-print "GPIO configuration enabled"
+print("GPIO configuration enabled")
def clockup():
GPIO.output(PIN_CLK,1)
@@ -32,24 +32,27 @@ def readpos():
GPIO.output(PIN_CS,0) #pulls low to start
time.sleep(delay*2)
- data = [0]
+ data = 0
clockdown()
- for i in range(0,10); #bitcount):
+ time1=time.clock()
+ for i in range(0,10): #bitcount):
clockup() #375 ns between each
- data[i]<<=1
- data[i]|=GPIO.input(PIN_DATA)
+ data<<=1
+ data|=GPIO.input(PIN_DATA)
+ #while(time.clock()-time1<minReadValue);
clockdown()
-
+ print(time.clock()-time1)
GPIO.output(PIN_CS,1) #pull high after finish
+
return data
try:
while(1):
- print readpos()
+ print(readpos())
time.sleep(0.001)
#break
finally:
- print "cleaning up GPIO"
+ print("cleaning up GPIO")
GPIO.cleanup() \ No newline at end of file