I know that the question from the title isn't quite new but any question before answer really to the problem I'm having.

I have manage to make different push buttons to work on the RPi (it's a RPi3 by the way), the problem is that any one that I push do the same thing and if a give them different task they stop working, the are connect via breadboard with a common 3.3 and ground but different gpio off course, so they shouldn't work as one but somehow they do.

Have somebody had the same problem? Does anybody know how to fix it??


The code, a little bit resumed to where the mistake can be is at the bottom, but i don't have right now how to upload an image of the circuit, it isn't very complex anyway, the push button is connected to ground on one side and to the gpis numbered on the other, somehow if in the code i only put a signal for one it work, for any button, but i need to be able to give each one a different task.

import pygame
import RPi.GPIO as GPIO
import time


GPIO.setup(5, GPIO.IN)
GPIO.setup(6, GPIO.IN)
GPIO.setup(12, GPIO.IN)
GPIO.setup(13, GPIO.IN)
GPIO.setup(16, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)

displaywidth = 480
displayheight = 320

mainWindow = pygame.display.set_mode((displaywidth, displayheight), pygame.FULLSCREEN)
pygame.display.set_caption('my project')

clock = pygame.time.clock()

def displayMessage(text, tfont, tcolor, tsize, x, y):
    textFont = pygame.font.Font(tfont,tsize)
    textSurf = textFont.render(text, True, tcolor)
    textRect == textSurf.get_rect()
    textRect.center = (x, y)
    mainWindow.blit(textSurf, textRect)

def radioLoop():
    running = True

    freqcursorx = 20
    freqcursory = 193
    freqcursorw = 10
    freqcursorh = 40

    drag = False

    while running:
        radiofreq = str((float(freqcursorx) - 20) * 0.1 + 76)

        displayMessage(radiofreq, "font.ttf", (0,200,0), 80, display width/2, display height/2 - 40)

        displayMessage("radio", "font.ttf", (0,200,0), 40, 50, 20)
        display.draw.line(mainWindow, (0,100,0), (20,213), (460,213), 3)
        págame.draw.rect(mainWindow, (0,255,0), [freqcursorx, freqcursory, freqcursorw, freqcursorh])

        for e in pygame.event.get()

                if e.type == pygame.QUIT:
                    running = False

                if e.type == pygame.KEYDOWN:
                    if e.key == ord("q")
                        running = False

                if e.type == pygame.MOUSEBUTTONDOWN:
                    mouseX, mouseY = pygame.mouse.get_pos()

                    if freqcursory < mouseY < freqcursory + freqcursorh:
                        drag = True

                if e.type == pygame.MOUSEMOTION and drag == True:
                    mouseX, mouseY = pygame.mouse.get_pos()

                    if 19> mouseX:
                        freqcursorx = 20
                    elif mouseX>461:
                        freqcursor = 460
                        freqcursorx = mouseX

        if GPIO.input(5) == True:
            if 19<freqcursorx<461:
                freqcursor += 1

        if GPIO.input(6) == True:
            if 19<freqcursorx<461:
                freqcursor -= 1



  • 2
    We need to see the code you are using and photos of all the connections. – Steve Robillard Mar 13 '17 at 2:19
  • Have edited the answer with the code, hope that you can help me, thanks. – Ecangis Mar 14 '17 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.