def __init__(self,debug = 0,
             enc_plus = 16,
             enc_minus = 20,
             enc_button = 21,
             no_encoder = 0,
             encoder_object = None):
     #Set the encoder + and - pins and push switch pin
     self.enc_plus = enc_plus
     self.enc_minus = enc_minus
     self.enc_button = enc_button
     #Set the debug level
     self.debug = debug
     self.pos = 0
     self.pushed = 0
     self.no_encoder = no_encoder
     self.encoder_object = encoder_object #if not none, this is a curses object
     if (self.debug == 0):
         #Setup the rotary encoder module (lol idk what it does)
         self.pi = pigpio.pi()
         self.decoder = rotary_encoder.decoder(self.pi, self.enc_plus, self.enc_minus, self.callback)
         #Set the GPIO parameters for the push switch pin
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.enc_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     else:
         #self.screen = curses.initscr()
         # turn off input echoing
         #curses.noecho()
         # respond to keys immediately (don't wait for enter)
         #curses.cbreak()
         # map arrow keys to special values
         #self.screen.keypad(True)
         pass
Exemplo n.º 2
0
 def __init__(self,
              debug=0,
              enc_plus=16,
              enc_minus=20,
              enc_button=21,
              no_encoder=0,
              encoder_object=None):
     #Set the encoder + and - pins and push switch pin
     self.enc_plus = enc_plus
     self.enc_minus = enc_minus
     self.enc_button = enc_button
     #Set the debug level
     self.debug = debug
     self.pos = 0
     self.pushed = 0
     self.no_encoder = no_encoder
     self.encoder_object = encoder_object  #if not none, this is a curses object
     if (self.debug == 0):
         #Setup the rotary encoder module (lol idk what it does)
         self.pi = pigpio.pi()
         self.decoder = rotary_encoder.decoder(self.pi, self.enc_plus,
                                               self.enc_minus,
                                               self.callback)
         #Set the GPIO parameters for the push switch pin
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.enc_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     else:
         #self.screen = curses.initscr()
         # turn off input echoing
         #curses.noecho()
         # respond to keys immediately (don't wait for enter)
         #curses.cbreak()
         # map arrow keys to special values
         #self.screen.keypad(True)
         pass
Exemplo n.º 3
0
def main():
    print("Hello World!")
    pi = pigpio.pi()
    decoder = rotary_encoder.decoder(pi, 7, 8, callback)
    pid.setpoint = 800
    while True:

        v = pos
        control = pid(
            v
        )  # compute new ouput from the PID according to the systems current value
        print("Control: ", control, "Pos: ", pos)
        # feed the PID output to the system and get its current value
        # v = controlled_system.update(control)
        kit.motor4.throttle = control
 def __init__(self):
     IO.setmode(IO.BCM)
     IO.setup(2, IO.OUT)
     self.p = IO.PWM(2, 1000)
     IO.setwarnings(False)
     IO.setup(3, IO.OUT)
     IO.output(3, 1)
     IO.setup(4, IO.IN, pull_up_down=IO.PUD_UP)
     self.p.start(0)
     self.Up = 1
     self.speed = 40
     self.numToTurn = 200
     self.pos = 0
     self.pi = pigpio.pi()
     decoder = rotary_encoder.decoder(self.pi, 4, 17, self.callback)
 def __init__(self,debug = 0,enc_plus = 16, enc_minus = 20,enc_button = 21,no_encoder = 0):
     #Set the encoder + and - pins and push switch pin
     self.enc_plus = enc_plus
     self.enc_minus = enc_minus
     self.enc_button = enc_button
     #Set the debug level
     self.debug = debug
     self.pos = 0
     self.pushed = 0
     self.no_encoder = no_encoder
     if (self.debug == 0):
         #Setup the rotary encoder module (lol idk what it does)
         self.pi = pigpio.pi()
         self.decoder = rotary_encoder.decoder(self.pi, self.enc_plus, self.enc_minus, self.callback)
         #Set the GPIO parameters for the push switch pin
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.enc_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Exemplo n.º 6
0
def init_node():
    pi = pigpio.pi()
    for i in range(4):
        decoders[i] = decoder(pi, Apins[i], Bpins[i], callback)

    rospy.init_node('encoder_reader')
    pub = rospy.Publisher("/motor_status/encoder_counts",
                          EncoderCounts,
                          queue_size=10)
    rate = rospy.Rate(1000)
    rospy.loginfo("Initialized encoders")
    while not rospy.core.is_shutdown():
        array = EncoderCounts()
        array.header.stamp = rospy.get_rostime()
        array.counts = count
        pub.publish(array)
        rate.sleep()

    for dec in decoders:
        dec.cancel()
    pi.stop()
 def __init__(self,
              debug=0,
              enc_plus=16,
              enc_minus=20,
              enc_button=21,
              no_encoder=0):
     #Set the encoder + and - pins and push switch pin
     self.enc_plus = enc_plus
     self.enc_minus = enc_minus
     self.enc_button = enc_button
     #Set the debug level
     self.debug = debug
     self.pos = 0
     self.pushed = 0
     self.no_encoder = no_encoder
     if (self.debug == 0):
         #Setup the rotary encoder module (lol idk what it does)
         self.pi = pigpio.pi()
         self.decoder = rotary_encoder.decoder(self.pi, self.enc_plus,
                                               self.enc_minus,
                                               self.callback)
         #Set the GPIO parameters for the push switch pin
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.enc_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Exemplo n.º 8
0
        self.cbA.cancel()
        self.cbB.cancel()


if __name__ == "__main__":

    import time
    import pigpio

    import rotary_encoder

    pos = 0

    def callback(way):

        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 2, 4, callback)

    time.sleep(300)

    decoder.cancel()

    pi.stop()
Exemplo n.º 9
0
        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()
    pi.set_mode(motor_r[0], pigpio.OUTPUT)
    pi.set_mode(motor_r[1], pigpio.OUTPUT)
    pi.set_mode(motor_l[0], pigpio.OUTPUT)
    pi.set_mode(motor_l[1], pigpio.OUTPUT)
    pi.set_PWM_dutycycle(motor_r[0], 0)
    pi.set_PWM_dutycycle(motor_r[1], 115)
    pi.set_PWM_dutycycle(motor_l[0], 115)
    pi.set_PWM_dutycycle(motor_l[1], 0)
    decoder1 = rotary_encoder.decoder(pi, encoder_r[0], encoder_r[1], callback)
    decoder2 = rotary_encoder.decoder(pi, encoder_l[0], encoder_l[1], callback)
    time.sleep(10)
    '''
   pi.set_PWM_dutycycle(5,0)
   pi.set_PWM_dutycycle(6,255)
   
   time.sleep(1)
   '''
    pi.set_PWM_dutycycle(motor_r[0], 0)
    pi.set_PWM_dutycycle(motor_r[1], 0)
    pi.set_PWM_dutycycle(motor_l[0], 0)
    pi.set_PWM_dutycycle(motor_l[1], 0)
    print("Der: ", decoder1.count)
    print("Izq: ", decoder2.count)
    aux = (74.83 * 48)
Exemplo n.º 10
0
    updateDisplay()


def getIP():
    cmd = "ip addr show wlan0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1"
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output.strip()


if __name__ == "__main__":
    print('start')
    writeMessage('Welcome\n' + getIP())
    time.sleep(5)

    getPlayers()
    rotary_encoder.decoder(GPIO, winnerPin1, winnerPin2, updateWinner)
    rotary_encoder.decoder(GPIO, loserPin1, loserPin2, updateLoser)

    GPIO.setup(submitPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(submitPin, GPIO.FALLING, submitGame)

    while True:
        try:
            time.sleep(1e6)
        except KeyboardInterrupt:
            lcd.clear()
            lcd.message('Shutting down')
            GPIO.cleanup()
            sys.exit()
Exemplo n.º 11
0
led = LED(17)
button = Button(2)


def pushedme():
    print('You pushed me')
    device.emit_click(uinput.KEY_X)


button.when_pressed = pushedme

pos = 0


def callback(way):
    global pos
    pos += way
    print("pos={}".format(pos))
    if way < 0:
        device.emit_click(uinput.KEY_N)
    else:
        device.emit_click(uinput.KEY_M)


pi = pigpio.pi()
decoder = rotary_encoder.decoder(pi, 7, 8, callback)

raw_input()
decoder.cancel()
pi.stop()
Exemplo n.º 12
0
        self.cbA.cancel()
        self.cbB.cancel()


if __name__ == "__main__":

    import time
    import rotary_encoder

    pos = 0

    def callback(way):

        global pos
        pos += way

        print("pos={}".format(pos))
        # print("way={}".format(way))

    pi = pigpio.pi()

    print("pi connected{}".format(pi.connected))

    my_decoder = rotary_encoder.decoder(pi, 9, 10, callback)

    time.sleep(3000000000)

    decoder.cancel()

    pi.stop()
Exemplo n.º 13
0
    import rotary_encoder

    pos = 0
    actual_time = 0
    past_time = time.time()
    velocidad = 0

    def callback(way):

        global pos
        global past_time
        global tiempo_actual
        global velocidad
        actual_time = time.time()
        pos -= way
        time = actual_time - past_time
        velocidad = 0.06283185307179587 / time  #linear movement of machine from each step of stepper motor
        past_time = actual_time

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 6, 13, callback)
    while 1:

        time.sleep(1)
        print("pos={0} vel={1}".format(pos, velocidad))

    decoder.cancel()

    pi.stop()
Exemplo n.º 14
0
    # mm and ticks
    pos = 0
    mm = 0

    # callback function on EITHER EDGE
    def callback_left(way):
        global pos
        global mm
        pos += way
        mm = 0.196 * pos

    pi = pigpio.pi()  # GPIO daemon

    # decoding number of ticks for right wheel only
    decoder_left = rotary_encoder.decoder(pi, PIN_ENCODER_RIGHT, callback_left)

    # setting up FORWARD MOVEMENT
    print("GOING FORWARD")
    pi.set_PWM_frequency(PIN_LEFT_FORWARD, PWM_FREQUENCY)
    pi.set_PWM_range(PIN_LEFT_FORWARD, PWM_RANGE)
    pi.set_PWM_frequency(PIN_RIGHT_FORWARD, PWM_FREQUENCY)
    pi.set_PWM_range(PIN_RIGHT_FORWARD, PWM_RANGE)

    # enabling motors
    pi.write(PIN_MOTOR_ENABLE, 1)

    # going forward on 30% speed
    pi.set_PWM_dutycycle(PIN_LEFT_FORWARD, 30)
    pi.set_PWM_dutycycle(PIN_RIGHT_FORWARD, 30)
Exemplo n.º 15
0

#EXAMPLE:

if __name__ == "__main__":

    import time
    import pigpio

    import rotary_encoder

    pos = 0

    def callback(way):

        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 9, 11, callback)

    time.sleep(5)

    decoder.cancel()

    pi.stop()
Exemplo n.º 16
0
    pinOnOff = 10  # pino do rele on/off
    pinPlayPause = 17  # pino da chave do encoder 1

    # inicializacao da classe pigpiod
    pi = pigpio.pi()  # inicializa pigpiod
    pi.set_mode(pinOnOff,
                pigpio.INPUT)  # configura pino da chave on/off como input
    pi.set_glitch_filter(pinOnOff, 300)  # ativa filtro para o pino
    status = pi.read(pinOnOff)  # variavel de estado: 0 desligado, 1 ligado
    pi.set_mode(pinPlayPause,
                pigpio.INPUT)  # configura botao do rotary encoder como input
    pi.set_pull_up_down(pinPlayPause,
                        pigpio.PUD_UP)  # configura pino como pull-up
    pi.set_glitch_filter(pinPlayPause, 300)  # ativa filtro para o pino

    # configura rotary encoder que seleciona radios
    decoder = rotary_encoder.decoder(pi, enc1A, enc1B, rotary1_callback)
    # configura funcao de callback para chave on/off
    cb1 = pi.callback(pinOnOff, pigpio.EITHER_EDGE, callback_on_off)
    # configura funcao de callback para botao do rotary encoder (play/pause)
    cb2 = pi.callback(pinPlayPause, pigpio.RISING_EDGE, callback_play_pause)

    IniciaListaPlaylists()  # inicializa lista de playlists
    CriaArquivoControle()  # cria arquivo de controle do MPlayer

    if (status == 1):
        TocaPlaylist(PlaylistEscolhida)
    # loop infinito: nao faz nada
    while True:
        signal.pause()
      self.cbA.cancel()
      self.cbB.cancel()

if __name__ == "__main__":

   import time
   import pigpio

   import rotary_encoder

   pos = 0

   def callback(way):

      global pos

      pos += way

      print("pos={}".format(pos))

   pi = pigpio.pi()

   decoder = rotary_encoder.decoder(pi, 20, 21, callback)

   time.sleep(300)

   decoder.cancel()

   pi.stop()

Exemplo n.º 18
0
    def cancel(self):
        """
        Cancel the rotary encoder decoder.
        """
        pass
        #self.cbA.cancel()
        #self.cbB.cancel()


if __name__ == "__main__":

    import time
    import RPi.GPIO as GPIO
    import RPi.GPIO as GPIO
    from time import sleep
    import rotary_encoder

    pos = 0

    def callback(way):
        global pos
        pos += way
        print("pos={}".format(pos))

    GPIO.setmode(GPIO.BOARD)

    decoder = rotary_encoder.decoder(GPIO, 10, 12, callback)
    time.sleep(300)
    decoder.cancel()
Exemplo n.º 19
0
    def __init__(self, A, B):
        super().__init__(A, B)
        self.Count = 0

        pi = pigpio.pi()
        decoder = rotary_encoder.decoder(pi, self.encA, self.encB, callback)
 def __init__(self):
     self.pi_gpio_object = pigpio.pi()
     self.decoder_motorR = rotary_encoder.decoder(self.pi_gpio_object, self.RW_A, self.RW_B, self.callback_right_wheel)
     self.decoder_motorL  = rotary_encoder.decoder(self.pi_gpio_object, self.LW_A, self.LW_B, self.callback_left_wheel)
Exemplo n.º 21
0
#EXAMPLE:

if __name__ == "__main__":

    import time
    import pigpio

    import rotary_encoder

    pos = 0

    def callback(way):

        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 9, 11, callback)

    time.sleep(5)

    decoder.cancel()

    pi.stop()

Exemplo n.º 22
0
        self.cbA.cancel()
        self.cbB.cancel()


if __name__ == "__main__":

    import time
    import pigpio

    import rotary_encoder

    pos = 0

    def callback(way):

        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 22, 23, callback)

    time.sleep(300)

    decoder.cancel()

    pi.stop()
Exemplo n.º 23
0
    uinput.KEY_M,
    ])

led = LED(17)
button = Button(2)

def pushedme():
    print('You pushed me')
    device.emit_click(uinput.KEY_X)


button.when_pressed = pushedme

pos = 0

def callback(way):
   global pos
   pos += way
   print("pos={}".format(pos))
   if way < 0:
       device.emit_click(uinput.KEY_N)
   else:
       device.emit_click(uinput.KEY_M)

pi = pigpio.pi()
decoder = rotary_encoder.decoder(pi, 7, 8, callback)

raw_input()
decoder.cancel()
pi.stop()
Exemplo n.º 24
0
      self.cbA.cancel()
      self.cbB.cancel()

if __name__ == "__main__":

   import time
   import pigpio

   import rotary_encoder

   pos = 0

   def callback(way):

      global pos

      pos += way

      print("pos={}".format(pos))

   pi = pigpio.pi('192.168.2.105',2222)

   decoder = rotary_encoder.decoder(pi, 17, 18, callback)

   time.sleep(300)

   decoder.cancel()

   pi.stop()

Exemplo n.º 25
0
      gpioA = int(sys.argv[2])
      gpioB = int(sys.argv[3])

   elif len(sys.argv) == 3: # gpioA gpioB (chip 0)
      chip = 0
      gpioA = int(sys.argv[1])
      gpioB = int(sys.argv[2])

   else:
      print("Usage: ./rotary_encoder.py [chip] gpioA gpioB")
      exit()

   pos = 0

   def callback(way):

      global pos

      pos += way

      print("pos={}".format(pos))

   decoder = rotary_encoder.decoder(sbc, chip, gpioA, gpioB, callback)

   time.sleep(300)

   decoder.cancel()

   sbc.stop()

Exemplo n.º 26
0
        self.cbA.cancel()
        self.cbB.cancel()


if __name__ == "__main__":

    import time
    import pigpio

    import rotary_encoder

    pos = 0

    def callback(way):

        global pos

        pos += way

        print("pos={}".format(pos))

    pi = pigpio.pi()

    decoder = rotary_encoder.decoder(pi, 20, 21, callback)

    time.sleep(300)

    decoder.cancel()

    pi.stop()
      self.cbA.cancel()
      self.cbB.cancel()

if __name__ == "__main__":

   import time
   import pigpio

   import rotary_encoder

   pos = 1

   def callback(way):

      global pos

      pos += way

      print("pos={}".format(pos))

   pi = pigpio.pi()

   decoder = rotary_encoder.decoder(pi, 20, 26, callback) #pin A=38  pin B=37

   time.sleep(300)

   decoder.cancel()

   pi.stop()