Raspberry pi : Master
Rotary Encoder: Slave (14 Bit of Transmission ,3 wire communication (MISO,CLK,CE))
After each cycle of communication it is compulsory to toggle CS pin from high to low.
when clock is toggle rotary encoder send data to PI at each 9600 HZ frequency
and using MISO PIN when we rotate rotary encoder angel will print on screen clockwise rotation & anticlock wise rotation,it will display on screen using SPI protocol i have Code of Rotary Encoder in Arduino but i want to run that same Encoder on raspberry pi using Python here i mention Arduino program
import spidev import time from sys import stdout import RPi.GPIO as GPIO # import RPi.GPIO module GPIO.setmode(GPIO.BCM) # choose BCM or BOARD GPIO.setwarnings(False) GPIO.setup(8, GPIO.OUT) # set a port/pin as an output GPIO.output(8, 1) # set port/pin value to 1/GPIO.HIGH/True #Define all constants. READ_COUNTER = [0x00] READ_STATUS = [0xFF] counterSize = 1 spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz =9600 def readCounter(): result = spi.xfer2(READ_COUNTER) GPIO.output(8, 0) data =  #Double check that a list i necessary for this. EncoderCount = 0 #spi.open(0, 0) spi.xfer2(READ_COUNTER) for i in range(counterSize): data = spi.xfer2([0x00]) EncoderCount = EncoderCount*16384 + data #spi.close() return EncoderCount def readStatus(): data =  #spi.open(0,0) spi.xfer2(READ_STATUS) data = spi.xfer2([0xFF]) #spi.close() return data while True: EncoderCount =readCounter() stdout.write("\rCount is [%s] status is %s. " % (str(EncoderCount), str(readStatus()))) main()
i tried with this code but still so many lines missing as per my requirement