{"id":25278627,"url":"https://github.com/jwebcoder/raspberry_music_box","last_synced_at":"2025-10-11T17:01:42.512Z","repository":{"id":276713689,"uuid":"917447167","full_name":"JWebCoder/raspberry_music_box","owner":"JWebCoder","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-10T01:59:56.000Z","size":7173,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T02:32:49.921Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JWebCoder.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-16T02:09:14.000Z","updated_at":"2025-02-10T01:59:59.000Z","dependencies_parsed_at":"2025-02-10T16:31:30.567Z","dependency_job_id":null,"html_url":"https://github.com/JWebCoder/raspberry_music_box","commit_stats":null,"previous_names":["jwebcoder/raspberry_music_box"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fraspberry_music_box","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fraspberry_music_box/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fraspberry_music_box/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fraspberry_music_box/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JWebCoder","download_url":"https://codeload.github.com/JWebCoder/raspberry_music_box/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247479436,"owners_count":20945459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-12T18:00:58.821Z","updated_at":"2025-10-11T17:01:40.408Z","avatar_url":"https://github.com/JWebCoder.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Step by Step\n\n## What We Will Use\n\n- Raspberry PI  \n- Breadboard (for testing our circuit)  \n- Various cables  \n- Various buttons  \n- A switch  \n- A multimeter (optional)  \n- Legos :D  \n\n## Steps\n\n1. **Desktop** - Create a Python script that writes something on the screen  \n2. **Desktop** - Format the SD card and choose the operating system  \n3. **RPI** - Insert the SD card, connect the necessary cables, and power on the RPI  \n4. **Desktop** - Establish remote access (run some tests)  \n5. **RPI** - Add the breadboard and a LED  \n6. **Desktop** - Create a script for the LED and run it on the RPI  \n7. **RPI** - Add a button to the breadboard  \n8. **Desktop** - Create a script to play a sound when the button is pressed  \n9. **RPI** - Add more buttons to the breadboard  \n10. **Desktop** - Add more buttons to the script  \n11. **RPI** - Add the switch for different layers  \n12. **Desktop** - Add support for multiple layers of audio  \n\n---\n\n# Step 1\n\nTo start, let's write a small script and run it to see what happens.  \n\nFirst, create a file named `helloworld.py` and add the following code:\n\n```python\nprint(\"hello world\")\n```\n\nNow open a terminal and run the script by typing:\n\n```bash\npython helloworld.py\n```\n\n**Note:** What happened?\n\n---\n\n# Step 2\n\nTo format the SD card and install the desired system, we will use the [Raspberry Pi Imager](https://www.raspberrypi.com/software/).  \n\nOpen the `Raspberry Pi Imager` application.  \n\n- Select the device you are using.  \n- The OS for this project will be `Raspberry Pi OS (other) -\u003e Raspberry Pi OS Lite (32-bit)`, but you can also use the default `Raspberry Pi OS`.  \n- The storage option is your SD card.  \n\nNow just click NEXT.\n\n---\n\n# Step 3\n\nNow it's time to power on the Raspberry Pi.  \n\nConnect a network cable, or if you've set up WiFi in the previous step, the Raspberry Pi will connect automatically (for older models, you might need a WiFi dongle).  \n\nInsert the SD card.  \n\nFinally, connect the USB cable to power the Raspberry Pi.\n\n---\n\n# Step 4\n\nNow open a terminal on your desktop to remotely access the Raspberry Pi using SSH.  \n\nIn the terminal, type:\n\n```bash\nssh hostname.local -l username\n```\n\nWhere `hostname` and `username` are the details you set in step 2.  \n\nEnter your password and you're in:\n\n![raspberry pi screen after ssh login](images/image.png)\n\nFind your IP address by typing:\n\n```bash\nip addr\n```\n\n![alt text](images/image-1.png)\n\nIn this example, the IP is **192.168.50.186**.\n\nAlso, open an SFTP connection to transfer files easily. You can use [FileZilla](https://filezilla-project.org/).\n\nUse your IP **192.168.50.186** (in my case), username **username**, your **password**, and port **22**.\n\n![alt text](images/image-2.png)\n\n![alt text](images/image-3.png)\n\nNow you can see the files inside the Raspberry Pi.\n\n---\n\n# Step 5\n\nTurn off the Raspberry Pi for now.\n\nNow connect a cable between pin **6** and the line with a \"-\" on the breadboard.  \n\nThen, connect a cable between **GPIO 17** and one of the middle lines.  \n\nYou'll need a resistor and a LED.  \n\nConnect a resistor between the **GPIO 17** line and the longer leg of the LED, then connect the shorter leg of the LED to the \"-\" line.\n\n![alt text](images/led.drawio.png)\n\n---\n\n# Step 6\n\nNow, let's control the LED by making it blink.  \n\nOn your desktop, create a file named `led.py` with the following code:\n\n```python\nfrom gpiozero import LED\nfrom time import sleep\n\nled = LED(17)\n\nwhile True:\n    led.on()\n    sleep(1)\n    led.off()\n    sleep(1)\n```\n\nThis will activate the LED on **GPIO 17**, turning it on and off continuously.\n\nNow turn the Raspberry Pi back on and access it via FileZilla.  \n\nCopy the file to the Raspberry Pi.  \n\nThen, connect via SSH and run `python led.py` to see the magic happen.\n\n**Note:** Try modifying the timing or even changing the script. If you have a multimeter, you can use it to see the voltage change when the LED turns on or off.\n\n---\n\n# Step 7\n\nTurn off the Raspberry Pi for now.\n\nNow, let's add the first button.\n\nA button is simply an electronic component that allows current to pass only when pressed. You'll use this to send data to the Raspberry Pi.\n\nThe connection is very simple: place the button in the center of the breadboard.\n\nConnect a cable between **GPIO 27** and the breadboard line connected to one leg of the button.  \n\nThen, connect another cable between \"-\" and the other leg of the button, on the same side as the first wire.  \n\nDon't forget to connect a speaker to the Raspberry Pi's audio jack.\n\n![alt text](images/button.drawio.png)\n\nNow, let's add the code.\n\n---\n\n# Step 8\n\nCreate a file **step7.py** with the following code:\n\n```python\nfrom gpiozero import LED\nfrom time import sleep\nfrom sound_button import SoundButton\n\nled = LED(17)\n\nSoundButton(\n  27,\n  [\n    \"./audio_button1_1.wav\"\n  ]\n)\n\nwhile True:\n    led.on()\n    sleep(1)\n    led.off()\n    sleep(1)\n```\n\nNow turn the Raspberry Pi back on and access it via FileZilla.  \n\nCopy the files **step7.py, sound_button.py, sound_file.py, and fileParser.py** to the Raspberry Pi.  \n\nConnect via SSH and install the dependencies with:\n\n```bash\npip install numpy simpleaudio\n```\n\nFinally, run:\n\n```bash\npython s  \n```\n\n---\n\n# Step 9\n\nAlways remember: **if you're going to modify the breadboard, turn off the Raspberry Pi first**.\n\nUse what you've learned so far and try adding more buttons to the breadboard.\n\n---\n\n# Step 10\n\nNow that you have more buttons, update the script to include them and assign a different sound to each.\n\n---\n\n# Step 11\n\nEverything working? Great!\n\nNow let's add even more options to our buttons.\n\nWe'll make each button support up to four sounds and allow switching between them.\n\nFor this, you'll need one more button, which will act as a **layer switch** instead of playing a sound.\n\nEach time you press this button, it will activate a new set of sounds for the buttons.\n\nPlace the button in the center of the breadboard.\n\nConnect a cable between **GPIO 16** and the breadboard line connected to one leg of the button.\n\nThen, connect another cable between \"-\" and the other leg of the button, on the same side as the first wire.\n\n![alt text](images/layerSwitch.drawio.png)\n\n---\n\n# Step 12\n\nNow, update your script.\n\nAdd the following code:\n\n```python\nfrom layer_switch import LayerSwitch\n\nlayerSwitch = LayerSwitch(16)\n```\n\nAlso, update your buttons by adding another parameter:\n\n```python\nSoundButton(\n  27,\n  [\n    \"./audio_button1_1.wav\"\n  ],\n  layerSwitch\n)\n```\n\nNotice that now we are passing `layerSwitch` as a parameter to the button. This allows the button to know which sound to play when pressed.\n\n**Note:** What is happening? How can you improve it? What ideas do you have to expand on this even further?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Fraspberry_music_box","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwebcoder%2Fraspberry_music_box","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Fraspberry_music_box/lists"}