diff options
Diffstat (limited to 'System_Python/test_Encoder.py')
-rw-r--r-- | System_Python/test_Encoder.py | 64 |
1 files changed, 10 insertions, 54 deletions
diff --git a/System_Python/test_Encoder.py b/System_Python/test_Encoder.py index ab74c6e..08804fa 100644 --- a/System_Python/test_Encoder.py +++ b/System_Python/test_Encoder.py @@ -1,58 +1,14 @@ +from encoder import Encoder import time -import RPi.GPIO as GPIO -GPIO.setmode(GPIO.BCM) +# Decide which pins to hook up to on the Pi before running +clk_pin = 2 +cs_pin = 4 +data_pin = 3 -PIN_CLK = 2 -PIN_DATA = 3 -PIN_CS = 4 -delay = 0.0000005 +e = Encoder(clk_pin, cs_pin, data_pin) +e.setZero() -# 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() - - time1=time.clock() - for i in range(0,10): #bitcount): - clockup() #375 ns between each - 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()) - time.sleep(0.001) - #break - -finally: - print("cleaning up GPIO") - GPIO.cleanup()
\ No newline at end of file +while(1): + print(e.readPosition('Degrees')) + time.sleep(0.001)
\ No newline at end of file |