{"id":24355312,"url":"https://github.com/redfrik/raspberrypiworkshop","last_synced_at":"2025-04-10T02:30:30.852Z","repository":{"id":67934708,"uuid":"70268602","full_name":"redFrik/raspberrypiWorkshop","owner":"redFrik","description":"vems stockholm 2016","archived":false,"fork":false,"pushed_at":"2024-04-01T09:46:37.000Z","size":3308,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T04:01:39.347Z","etag":null,"topics":["pure-data","raspberry-pi","supercollider"],"latest_commit_sha":null,"homepage":"https://www.fredrikolofsson.com/","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/redFrik.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":"2016-10-07T17:32:13.000Z","updated_at":"2024-04-01T09:46:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b0863f6-0ec3-41e2-b50e-503df3d597d6","html_url":"https://github.com/redFrik/raspberrypiWorkshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redFrik%2FraspberrypiWorkshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redFrik%2FraspberrypiWorkshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redFrik%2FraspberrypiWorkshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redFrik%2FraspberrypiWorkshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redFrik","download_url":"https://codeload.github.com/redFrik/raspberrypiWorkshop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144146,"owners_count":21054875,"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":["pure-data","raspberry-pi","supercollider"],"created_at":"2025-01-18T17:30:00.651Z","updated_at":"2025-04-10T02:30:30.818Z","avatar_url":"https://github.com/redFrik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raspberrypiWorkshop\n\nheld at [ems](http://elektronmusikstudion.se) 9oct2016, organized by [vems](https://vems.nu)\n\nin this 3h workshop we will install the raspbian operating system from scratch, install [pure data](https://puredata.info) and [supercollider](https://supercollider.github.io) and last look at how to connect an [arduino](https://arduino.cc) board and send data to/from it and the raspberry pi.\n\n**participants should bring:**\n\n* laptop - preferably with sd card reader/writer\n* micro sd card - 8gb or larger\n* raspberry pi - model 1b, 2 or 3\n* power supply - 5v micro usb for the rpi\n* headphones with minijack\n* ethernet cable\n* arduino with usb cable\n\n**additional:** (_but not necessary_)\n\n* usb sound card\n* usb wlan module\n* breadboard, sensors, leds, wires\n\noverview\n==\n\nthese are the steps we will go through. it may look complicated but in practice there are only a few things one need to do. and after you've gone through it once, you should be able to perform it all again in \u003c15min.\n\ndetails are writting in _italic_.\n\n1. [burn raspbian to your sd card](#burn-raspbian-to-your-sd-card)\n2. [start your raspberry pi](#start-your-raspberry-pi)\n3. [log in to your raspberry pi](#log-in-to-your-raspberry-pi)\n4. [setup raspbian](#setup-raspbian)\n5. [setup wifi](#setup wifi)\n6. [install pure data](#install-pure-data)\n7. [install supercollider](#install-supercollider)\n8. [tune your audio](#tune-your-audio)\n9. [autostart](#autostart)\n10. [communicate with arduino](#communicate-with-arduino)\n11. [useful terminal commands](#useful-terminal-commands)\n12. [shutdown](#shutdown)\n\nburn raspbian to your sd card\n--\n\n1. download the latest [raspbian image](https://www.raspberrypi.org/downloads/raspbian/)\n    - _or copy the zip from the provided usbstick_\n    - _to save space you can use the .zip file directly without unpacking the .img_\n    - _here we use 2016-09-23-raspbian-jessie - **not** the 'lite' version_\n    - _jessie 'lite' will fit on a smaller sd card and is useful for non-gui audio-only headless systems_\n2. download [etcher.io](https://www.balena.io/etcher/)\n    - _works on osx, linux, windows_\n    - _on osx you can also use [pifiller](http://ivanx.com/raspberrypi/)_\n3. start etcher and select the raspbian zip file\n4. insert your 8gb sd card\n5. click flash\n    - _on my machine the process takes ~9min_\n6. if you are using a raspbian image newer than 2016-11-25 make an empty file called 'ssh' on the sd card\n    - _for security reasons ssh is no longer enabled by default_\n\n![etcher](etcher.png)\n\nstart your raspberry pi\n--\n\n1. put the sd card in your raspberry pi\n2. connect the ethernet cable to your raspberry pi\n    - _the other end goes to your home wlan router or to your laptop_\n    - _if you connect to a osx: go to system preferences / network and activate internet sharing - share from wifi to ethernet_\n    - _if you connect to a windows machine: see [here](https://raspberrypi.stackexchange.com/questions/11684/how-can-i-connect-my-pi-directly-to-my-pc-and-share-the-internet-connection)_\n3. connect 5v micro usb power supply\n    - _always connect power last_\n    - _and never pull the power without properly shutting down the system (see below)_\n    - _on first boot the rpi will automatically expand the file system to make full use of the sd card_\n\nlog in to your raspberry pi\n--\n\n1. wait a bit after applying 5v\n    - _specially on first boot it will take a while to connect to the network_\n2. find your raspberry pi on the network and take note of the ip address (e.g. 192.168.1.52)\n    - _we want to see that it is accessible and which ip address it got assigned_\n    - _to find out you can log in to your router's admin setup panel_\n    - _or open terminal and type `arp -a` to list connected devices_\n    - _or on osx you can use [lanscan](https://www.iwaxx.com/lanscan)_\n3. open a terminal window and type `ssh pi@192.168.1.52` (or whatever ip you found for your rpi)\n    - _on osx terminal is found in your applications/utilities folder_\n    - _on windows you can install [putty](https://www.raspberrypi.org/documentation/remote-access/ssh/windows.md)_\n    - _if you get a warning about 'remote host identification' first do `ssh-keygen -R 192.168.1.52`_\n    - _instead of the ip you can also use `ssh pi@raspberrypi` or `pi@raspberrypi.local`_\n4. the default password 'raspberry'\n5. make sure you can log in like in the picture below\n6. then type `exit` to leave\n\n![login](login.png)\n\nsetup raspbian\n--\n\n1. log in again using ssh\n    - _via terminal or putty - see #3 above_\n2. type `sudo raspi-config`\n3. select change user password and enter a new password\n4. select change hostname under advanced options and enter a new name\n    - _this is so that you can identify your raspberry pi on the network_\n    - _then use `ssh pi@mynewhostname` to log in_\n5. optional: change memory split under advanced options\n    - _if you run headless and never use gui you can set this to the lowest (16)_\n    - _if you will do graphics (e.g. with openframeworks) set this to a higher value (256)_\n6. optional: enable vnc under advanced options\n    - _so that you can use the gui remotely with vnc viewer - see under setup wifi below_\n    - _install real's [vnc viewer](https://www.realvnc.com/download/viewer/)_\n7. finish and reboot\n\n![raspiconfig](raspiconfig.png)\n\nsetup wifi\n--\n\n1. log again in via ssh\n    - _note: use the new hostname (see #4 above) and new password_\n2. type `sudo nano /etc/wpa_supplicant/wpa_supplicant.conf`\n3. type or copy/paste the following at the bottom\n\n    ```\n    network={\n        ssid=\"wifiname\"\n        psk=\"password\"\n    }\n    ```\n4. press ctrl+o to save and ctrl+x to exit\n5. restart with `sudo reboot`\n    - _the raspberry pi should now reboot and try to connect to the wifi network - check with lanscan or in your router's setup panel like before_\n    - _if the raspberry pi could connect to wifi, you can now disconnect the ethernet cable_\n6. optional: start real's vnc viewer and try to connect to your raspberry pi\n    - _download it from [here](https://www.realvnc.com/download/viewer/)_\n    - _make sure you have activated vnc in raspi-config - see above_\n\n![wifi](wifi.png)\n\n![vnc](vnc.png)\n\n![desktop](desktop.png)\n\nreference: [setting up wifi via command line](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md)\n\ninstall pure data\n--\n\nfirst make sure your raspberry is connected to the internet and then do the following.\n\n1. `sudo apt-get update`\n2. `sudo apt-get install puredata`\n3. `apt-cache search \"^pd-\"` (this will just list libraries and externals)\n4. `sudo apt-get install pd-comport pd-cyclone` (this will install two libraries that we need for arduino below)\n5. `nano testsines.pd` and copy/paste in the following\n\n    ```\n    #N canvas 1068 88 450 300 10;\n    #X obj 238 159 dac~;\n    #X obj 235 73 osc~ 400;\n    #X obj 289 73 osc~ 404;\n    #X msg 126 154 \\; pd dsp 1;\n    #X obj 126 83 loadbang;\n    #X obj 126 123 del 100;\n    #X text 42 122 important -\u003e;\n    #X obj 238 111 *~ 0.2;\n    #X obj 280 111 *~ 0.2;\n    #X connect 1 0 7 0;\n    #X connect 2 0 8 0;\n    #X connect 4 0 5 0;\n    #X connect 5 0 3 0;\n    #X connect 7 0 0 0;\n    #X connect 8 0 0 1;\n    ```\n6. press ctrl+o to save and ctrl+x to exit\n7. `pd -stderr -nogui -verbose -audiodev 4 testsines.pd` (test different audiodev - 4 is usually the usb soundcard)\n8. you should hear two sine tones\n    - _note: if you are using the build-in headphones output (audiodev 0) you should turn up the volume to 100 with `alsamixer` (see [tune your audio](#tune-your-audio) below)_\n9. stop with ctrl+c\n10. `nano testmic.pd` and copy/paste the following\n\n    ```\n    #N canvas 1068 88 450 300 10;\n    #X obj 238 230 dac~;\n    #X msg 126 154 \\; pd dsp 1;\n    #X obj 126 83 loadbang;\n    #X obj 126 123 del 100;\n    #X text 42 122 important -\u003e;\n    #X obj 238 24 adc~;\n    #X obj 238 53 delwrite~ del1 500;\n    #X obj 238 123 delread~ del1 500;\n    #X obj 259 80 delwrite~ del2 750;\n    #X obj 280 144 delread~ del2 750;\n    #X obj 238 182 *~ 0.2;\n    #X obj 280 182 *~ 0.2;\n    #X connect 2 0 3 0;\n    #X connect 3 0 1 0;\n    #X connect 5 0 6 0;\n    #X connect 5 1 8 0;\n    #X connect 7 0 10 0;\n    #X connect 9 0 11 0;\n    #X connect 10 0 0 0;\n    #X connect 11 0 0 1;\n    ```\n11. press ctrl+o to save and ctrl+x to exit\n12. `pd -stderr -nogui -verbose -audiodev 4 testmic.pd` (test different audiodev - 4 is usually the usb soundcard)\n13. if you have a soundcard with a mic connected you should hear an echo effect\n    - _note: this example will not make any sound if you try it with the built-in audio - there is no sound input on the raspberry pi_\n14. stop with ctrl+c\n\nreference: \u003chttps://fredrikolofsson.com/f0blog/pd-on-raspberry-pi/\u003e\n\nand if you connect a monitor+keyboard or log in via vnc, you can also also patch pd like normal. just start pure data from the menu on the left hand side (under sound \u0026 video). set up your audio under 'Media' in the menu bar.\n\n![puredata](puredata.png)\n\ninstall supercollider\n--\n\njust follow the instructions under installation and headless here... \u003chttps://github.com/redFrik/supercolliderStandaloneRPI2\u003e\n\n(or if you are using an older rpi1 or a rpi0 here \u003chttps://github.com/redFrik/supercolliderStandaloneRPI1\u003e )\n\nif you connect a monitor+keyboard or log in via vnc, you can also use the supercollider ide like normal. follow the instructions under startup on the github page linked above.\n\n![supercollider](supercollider.png)\n\ntune your audio\n--\n\nby default the alsa volume on raspberry pi is quite low. it's recommended to turn it up so that you can lower the amplifier on the output and thereby get a less noisy signal.\n\n```bash\nalsamixer\n```\n\nand to make the settings permanent do...\n\n```bash\namixer controls #and check which numid is ’Master Playback Volume’\namixer cset numid=1 100% #adapt this value\nsudo alsactl store\n```\n\nautostart\n--\n\nto make puredata start the testsines.pd patch at startup do\n\n1. open terminal and type ```crontab -e```\n2. scroll down and add the following line (edit to match your audio device and path)\n\n    ```\n    @reboot /usr/bin/pd -stderr -nogui -audiodev 4 /home/pi/testsines.pd\n    ```\n3. press ctrl+o to save and ctrl+x to exit\n4. `sudo reboot`\n\nand now you should hear the sines after the rpi booted. to stop log in and type `pkill pd`\n\nto autostart supercollider see the github page linked above.\n\narduino\n--\n\nprogram an arduino from your laptop with the following\n\n```cpp\n//arduino code testarduino.ino\nvoid setup() {\n    Serial.begin(57600);\n}\nvoid loop() {\n    int val = analogRead(A0);\n    Serial.write(253);\n    Serial.write(254);\n    Serial.write(val\u003e\u003e8);\n    Serial.write(val\u0026255);\n    Serial.write(255);\n    delay(100);  //update rate\n}\n```\n\nand then on the rpi open terminal and type\n\n```bash\napt-cache search \"^pd-\" #just list libraries and externals\nsudo apt-get install pd-comport pd-cyclone #just if you did not do it above\n```\n\nthen `nano testarduino.pd` and copy/paste the following\n\n```\n#N canvas 141 95 450 300 10;\n#X msg 86 31 devices;\n#X obj 86 61 comport 1 57600;\n#X obj 86 95 cyclone/match 253 254 nn nn 255;\n#X obj 86 140 unpack f f f f f;\n#X obj 140 176 \u003c\u003c 8;\n#X obj 140 202 +;\n#X floatatom 140 230 5 0 0 0 - - -, f 5;\n#X connect 0 0 1 0;\n#X connect 1 0 2 0;\n#X connect 2 0 3 0;\n#X connect 3 2 4 0;\n#X connect 3 3 5 1;\n#X connect 4 0 5 0;\n#X connect 5 0 6 0;\n```\n\nconnect the arduino to the rpi via usb and run the pd patch with\n\n```\npd -stderr -nogui -verbose -audiodev 4 testarduino.pd\n```\n\nyou should see (and hear) values in the range 0-1023 depending on the voltage present on pin A0. stop with ctrl+c.\n\nfor supercollider use this code (testarduino.scd)...\n\n```supercollider\n(\ns.waitForBoot{\n   var syn, ser, r;\n   syn= {|freq= 0| SinOsc.ar([400, 404]+freq, 0, 0.2)}.play;\n   ser= SerialPort(\"/dev/ttyUSB0\", 57600);\n   r= Routine.run({\n      var val;\n      inf.do{\n         var data= [];\n         var d= 0;\n         while({d!=255 and:{d.size\u003c100}}, {\n            d= ser.read();\n            data= data++d;\n         });\n         if(data[0]==253 and:{data[1]==254}, {\n            val= (data[2]\u003c\u003c8)+data[3];\n            syn.set(\\freq, val);\n            val.postln;\n         });\n      };\n   });\n   CmdPeriod.doOnce({ser.close});\n};\n)\n```\n\nand also let's try python. open terminal and type `nano testarduino.py` and paste in the following code\n\n```python\nimport serial\nser= serial.Serial('/dev/ttyUSB0', 57600)\nwhile True:\n    indata= []\n    d= ''\n    while (d!='\\xff') and (len(indata)\u003c100):\n        d= ser.read()\n        indata.append(d)\n    if (indata[0]=='\\xfd') and (indata[1]=='\\xfe'):\n        hibyte= ord(indata[2])\n        lobyte= ord(indata[3])\n        val= (hibyte\u003c\u003c8)+lobyte\n        print val\n```\n\nstart it with `python testarduino.py` and stop with ctrl+c\n\nshutdown\n--\n\nto safely turn off your raspberry pi you need to log in and type:\n\n`sudo halt -p`\n\nthen wait for the led on the board to blink 10 times. now you can disconnect the 5v micro usb cable. if you don't power down the system in this way you risk corrupting the sd card.\n\nanother option is to add your own button to run a halt script when pressed. below is one way to do this using a python script that always run in the background.\n\n1. log in and type `nano shutdown.py`\n2. type or copy/paste the following\n\n    ```python\n    import sys\n    from os import system\n    from time import sleep\n    import RPi.GPIO as GPIO\n    pinoff= 3\n    GPIO.setmode(GPIO.BOARD)\n    GPIO.setup(pinoff, GPIO.IN)\n    while True:\n        if GPIO.input(pinoff)==0:\n            system('sudo halt -p')\n            sleep(10)\n            sleep(0.5)\n    ```\n3. press ctrl+o to save and ctrl+x to exit\n4. type `crontab -e` and add the following to the bottom `@reboot /usr/bin/python /home/pi/shutdown.py`\n5. `sudo reboot`, wait for a bit and then connect a cable/button between pin 3 (aka bcm2) and ground. see \u003chttps://pinout.xyz\u003e\n\ncopy files to \u0026 from rpi\n--\n\none way is to use `scp` (secure copy) in your laptop terminal.\n\nto copy a file from your laptop desktop to rpi desktop directory type:\n\n`scp ~/Desktop/myfile.pd pi@192.168.1.52:Desktop`\n\nto copy another file from your rpi home directory to your laptop home directory type:\n\n`scp pi@192.168.1.52:testsines.pd ~`\n\nto copy a whole folder add the recursive flag `-r`. for example to move a folder from your laptop documents folder to your rpi home directory type:\n\n`scp -r ~/Documents/soundfiles pi@192.168.1.52:`\n\nuseful terminal commands\n--\n\n```bash\nls              #list files\ndf -h           #disk free\nfree -h         #ram memory\ntop             #cpu usage (quit with 'q')\nlsusb           #list usb devices\naplay -l        #list available soundcards\nexit            #leave ssh\nsudo halt -p    #turn off - wait for 10 blinks\nsudo reboot     #restart\nsudo pkill pd   #force quit on some program\nls /dev/tty*    #see if /dev/ttyUSB0 is there\nrm -r sounds    #remove a folder recursively\n```\n\nreference: \u003chttps://leanpub.com/jelinux/read\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredfrik%2Fraspberrypiworkshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredfrik%2Fraspberrypiworkshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredfrik%2Fraspberrypiworkshop/lists"}