-1

I am creating a Paino with 28 notes. I had everything working fine. Then I added a small update for the code and it stopped working. Even the after the changes a basic button press script is not working. Changed the SD card to a new Raspberry pi and the basic button press is not working. I am working with pull down. Here is the code that was working before but is not now.

import RPi.GPIO as IO
import pygame as pg

dir = '/home/pi/Desktop/sounds/'
busy = True
    print("Initializing")

pg.init()
mx = pg.mixer
mx.init()
print("Setting up channels")
mx.set_num_channels(29)

print("Assigning Channel Sounds")
print("Assinging Channel Pins")
k1 = 14
c1 = mx.Channel(1)
a1 = mx.Sound(dir+'A1.ogg')

k2 = 15
c2 = mx.Channel(2)
a2 = mx.Sound(dir+'A3.ogg')

k3 = 18
c3 = mx.Channel(3)
a3 = mx.Sound(dir+'A5.ogg')

k4 = 23
c4 = mx.Channel(4)
a4 = mx.Sound(dir+'A7.ogg')

k5 = 24
c5 = mx.Channel(5)
a5 = mx.Sound(dir+'E1.ogg')

k6 = 25
c6 = mx.Channel(6)
a6 = mx.Sound(dir+'F1.ogg')

k7 = 8
c7 = mx.Channel(7)
a7 = mx.Sound(dir+'G1.ogg')

k8 = 7
c8 = mx.Channel(8)
a8 = mx.Sound(dir+'A2.ogg')

k9 = 1
c9 = mx.Channel(9)
a9 = mx.Sound(dir+'B2.ogg')

k10 = 12
c10 = mx.Channel(10)
a10 = mx.Sound(dir+'C2.ogg')

k11 = 16
c11 = mx.Channel(11)
a11 = mx.Sound(dir+'D2.ogg')

k12 = 20
c12 = mx.Channel(12)
a12 = mx.Sound(dir+'E2.ogg')

k13 = 21
c13 = mx.Channel(13)
a13 = mx.Sound(dir+'F2.ogg')

k14 = 2
c14 = mx.Channel(14)
a14 = mx.Sound(dir+'G2.ogg')

k15 = 3
c15 = mx.Channel(15)
a15 = mx.Sound(dir+'A3.ogg')

k16 = 4
c16 = mx.Channel(16)
a16 = mx.Sound(dir+'B3.ogg')

k17 = 17
c17 = mx.Channel(17)
a17 = mx.Sound(dir+'C3.ogg')

k18 = 27
c18 = mx.Channel(18)
a18 = mx.Sound(dir+'D3.ogg')

k19 = 22
c19 = mx.Channel(19)
a19 = mx.Sound(dir+'E3.ogg')

k20 = 10
c20 = mx.Channel(20)
a20 = mx.Sound(dir+'F3.ogg')

k21 = 9
c21 = mx.Channel(21)
a21 = mx.Sound(dir+'G3.ogg')

k22 = 11
c22 = mx.Channel(22)
a22 = mx.Sound(dir+'A4.ogg')

k23 = 0
c23 = mx.Channel(23)
a23 = mx.Sound(dir+'B4.ogg')

k24 = 5
c24 = mx.Channel(24)
a24 = mx.Sound(dir+'C4.ogg')

k25 = 6
c25 = mx.Channel(25)
a25 = mx.Sound(dir+'D4.ogg')

k26 = 13
c26 = mx.Channel(26)
a26 = mx.Sound(dir+'E4.ogg')

k27 = 19
c27 = mx.Channel(27)
a27 = mx.Sound(dir+'F4.ogg')

k28 = 26
c28 = mx.Channel(28)
a28 = mx.Sound(dir+'G4.ogg')

print("configuring inputs")
IO.setmode(IO.BCM)

IO.setup(k1, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k2, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k3, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k4, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k5, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k6, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k7, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k8, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k9, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k10, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k11, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k12, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k13, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k14, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k15, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k16, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k17, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k18, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k19, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k20, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k21, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k22, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k23, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k24, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k25, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k26, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k27, IO.IN, pull_up_down = IO.PUD_DOWN)
IO.setup(k28, IO.IN, pull_up_down = IO.PUD_DOWN)

print("Ready")

while busy:

    if IO.input(k1):
        if not c1.get_busy():
            c1.play(a1)
        print("k1")


    if IO.input(k2):
        if not c2.get_busy():
            c2.play(a2)
        print("k2")


    if IO.input(k3):
        if not c3.get_busy():
            c3.play(a3)
        print("k3")

    if IO.input(k4):
        if not c4.get_busy():
            c4.play(a4)
        print("k4")

    if IO.input(k5):
        if not c5.get_busy():
            c5.play(a5)
        print("k5")

    if IO.input(k6):
        if not c6.get_busy():
            c6.play(a6)
        print("k6")

    if IO.input(k7):
        if not c7.get_busy():
            c7.play(a7)
        print("k7")

    if IO.input(k8):
        if not c8.get_busy():
            c8.play(a8)
        print("k8")

    if IO.input(k9):
        if not c9.get_busy():
            c9.play(a9)
        print("k9")

    if IO.input(k10):
        if not c10.get_busy():
            c10.play(a10)
        print("k10")

    if IO.input(k11):
        if not c11.get_busy():
            c11.play(a11)
        print("k11")

    if IO.input(k12):
        if not c12.get_busy():
            c12.play(a12)
        print("k12")

    if IO.input(k13):
        if not c13.get_busy():
            c13.play(a13)
        print("k13")

    if not IO.input(k14):
        if not c14.get_busy():
            c14.play(a14)
        print("k14")

    if not IO.input(k15):
        if not c15.get_busy():
           c15.play(a15)
        print("k15")

    if IO.input(k16):
        if not c16.get_busy():
            c16.play(a16)
        print("k16")

    if IO.input(k17):
        if not c17.get_busy():
            c17.play(a17)
        print("k17")

    if IO.input(k18):
        if not c18.get_busy():
            c18.play(a18)
        print("k18")

    if IO.input(k19):
        if not c19.get_busy():
            c19.play(a19)
        print("k19")

    if IO.input(k20):
        if not c20.get_busy():
            c20.play(a20)
        print("k20")

    if IO.input(k21):
        if not c21.get_busy():
            c21.play(a21)
        print("k21")

    if IO.input(k22):
        if not c22.get_busy():
            c22.play(a22)
            print("k22")

    if IO.input(k23):
        if not c23.get_busy():
            c23.play(a23)
        print("k23")

    if IO.input(k24):
        if not c24.get_busy():
            c24.play(a24)
        print("k24")

    if IO.input(k25):
        if not c25.get_busy():
            c25.play(a25)
        print("k25")

    if IO.input(k26):
        if not c26.get_busy():
            c26.play(a26)
        print("k26")

    if IO.input(k27):
        if not c27.get_busy():
            c27.play(a27)
        print("k27")

    if IO.input(k28):
        if not c28.get_busy():
            c28.play(a28)
        print("k28")



print("done")
0
1

As far as I am aware 26 inputs are available on the Pi3 GPIO.

These are BCM codes : 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27

https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/

I commented out all buttons except k17 in your code and tested that with a button and 220ohm resistor connected to BCM17 and 3.3v. I changed the play to a print (as i don't have the .ogg files) and the code worked.

4
  • GPIO 0-27 are available on Pis with the 40 pin expansion header (which includes the Pi3). – joan Sep 18 '17 at 9:44
  • Ok, it seems you can access 26 inputs raspberrypi.org/documentation/usage/gpio-plus-and-raspi2 (not 0 or 1 - eeprom usage!) – CoderMike Sep 18 '17 at 10:06
  • Updated my answer based on 26 inputs – CoderMike Sep 18 '17 at 10:22
  • I'd class 0 and 1 as reserved. If no HAT is present you can use 0 and 1 as you want. However if there is a HAT attached there might be a conflict. – joan Sep 18 '17 at 10:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.