$30 off During Our Annual Pro Sale. View Details »

How to make a Banana Beat Box with Raspberry Pi

How to make a Banana Beat Box with Raspberry Pi

Workshop on how to create a banana beat box with Python, Raspberry Pi and an Explorer HAT from Pimoroni. This workshop was given to attendees at the Powerhouse Museum in Sydney, Australia on 5th August 2015.

Carrie Anne Philbin

August 05, 2015
Tweet

More Decks by Carrie Anne Philbin

Other Decks in Education

Transcript

  1. with
    Banana Beat Box
    Raspberry Pi
    How to create a

    View Slide

  2. Carrie Anne Philbin
    Award Winning Educator, Author & YouTuber
    @MissPhilbin
    @GeekGurlDiaries
    Education Pioneer
    Raspberry Pi Foundation

    View Slide

  3. View Slide

  4. What you will need

    View Slide

  5. Explorer HAT Pro
    mini breadboard
    capacitive touch
    buttons
    buttons
    LEDs
    slots for inputs
    like motors
    To program this with python you
    need to install the python 3
    explorer hat library from pimoroni

    View Slide

  6. Connect and boot your Pi
    The explorer HAT fits onto the
    GPIO pins of a Raspberry Pi

    View Slide

  7. Log in
    login:  pi  
    password:  raspberry  
     pi@raspberrypi  ~  $  startx  

    View Slide

  8. Opening IDLE 3 as SUDO
       pi@raspberrypi  ~  $  cd  musicbox    
       pi@raspberrypi  ~  $  touch  musicbox.py  
       pi@raspberrypi  ~  $  sudo  idle3  musicbox.py  &  
    Click on the terminal icon

    View Slide

  9. IDLE 3
    you can type
    commands directly
    into the
    interpreter window
    To write longer
    programs open a
    text editor window

    View Slide

  10. Hello World with LEDs
    import  explorerhat  
    import  time  
    explorerhat.light.on()  
    time.sleep(1)  
    explorerhat.light.off()

    View Slide

  11. Hello World with LEDs
    import  explorerhat  
    import  time  
    explorerhat.light.on()  
    print(“lights  on”)  
    time.sleep(1)  
    explorerhat.light.off()  
    print(“lights  off”)
    using print
    statements is a
    good way to
    troubleshoot any
    problems in the
    code.

    View Slide

  12. Sequencing with LEDs
    import  explorerhat  
    import  time  
    explorerhat.light.yellow.on()  
    print(“yellow  light  on”)  
    time.sleep(1)  
    explorerhat.light.yellow.off()  
    print(“yellow  light  off”)
    Can you finish this
    code to sequence
    traffic lights?

    View Slide

  13. Using buttons
    import  explorerhat  
    import  time  
    def  traffic(channel,  event):  
           explorerhat.light.yellow.on()  
           print(“yellow  light  on”)  
           time.sleep(1)  
           explorerhat.light.yellow.off()  
           …  
    explorerhat.touch.one.pressed(traffic)

    View Slide

  14. Challenge 1
    Can you write a function for buttons 1 - 4 that turn on one colour
    LED when you press the button?
    e.g.
    button 1 turns on the blue LED for 1 second
    button 2 turns on the red LED for 1 second

    View Slide

  15. Adding Sounds
    import  pygame  
    pygame.mixer.init()  
    bell  =  pygame.mixer.Sound(“samples/elec_bell.wav”)  
    def  ping(channel,  event):  
           print(“button  5  pressed”)  
           bell.play()  
           explorerhat.light.blink(1,  1)  
           time.sleep(1)  
           explorerhat.light.off()  
    explorerhat.touch.five.pressed(ping)
    capital letters are
    important in
    Python
    make sure you save
    this file in the
    music box folder

    View Slide

  16. Challenge 2
    Can you add a different sound to each of your button functions
    so far?
    e.g.
    button 1 turns on the blue LED for 1 second and plays a drum
    sound.
    If you use buttons 5 - 8 you can use capacitive touch and add
    banana buttons!

    View Slide

  17. What you will need for banana buttons

    View Slide

  18. Connect to
    buttons 5 - 8

    View Slide

  19. Find more free resources

    View Slide

  20. Carrie Anne Philbin
    Award Winning Educator, Author & YouTuber
    @MissPhilbin
    @GeekGurlDiaries
    Education Pioneer
    Raspberry Pi Foundation

    View Slide