Micro-computing

chapter 2

Micro-computing

Physical computing

Introduction to physical computing - microcontrollers. Programming Interactivity (Noble 2012): Chapter 4: Arduino.

Introduction to Raspberry Pi (https://www.raspberrypi.org/learning/hardware-guide/).

Interactive Performance.

Artistic methods and techniques which give to performers (usually dancers or musicians) control of their medium in real time.

wireless sensors found both in the body of a performer and in the theater.

Sensors

Use of sensors: touch, movement, elasticity, camera.

Programming Interactivity

experimenting with various sensors.

experimenting with Arduino and node.js

Arduino basic examples: (https://www.arduino.cc/en/Tutorial/BuiltInExamples).

Using Python-for OSC communication libraries

(https://pypi.python.org/pypi/python-osc) - with SuperCollider.

Raspberry Pi

Install Linux Raspbian Jessie Lite OS Image on the SD card

Download Raspbian here: raspbian

Follow the instructions here: installation-guide

Installing raspbian jessie-lite on raspberry

Import your SD card to your mac

identify the disk (not partition) of your SD card. e.g. disk4 (not disk4s1)

diskutil list

Go to check the disk number on About this mac->System report

Then open disk utilities choose the partision of the SD card and unamount it so as to let you erase it.

$ sudo dd if=raspbian jessie.img of=/dev/disk2 bs=1m
dd: /dev/disk2: Resource busy
$ diskutil umountDisk disk2
Unmount of all volumes on disk2 was successful
$ sudo dd if=ro519-rc6-1876M.img of=/dev/disk2 bs=1m

Then open terminal and write the following

$ sudo dd bs=1m if=path_of_your_image.img of=/dev/rdiskn

Remember to replace n with the number that you noted before!

use Activity Monitor on Mac to see the progress.

eject sd card and connect it to raspberry

Set up network

login from external screen and edit wpa_supplicant.conf

Also enabled SSH while having the raspberry pi on the external monitor…

open raspi config

Choose Shell

$ sudo raspi-config

Go to Advanced Options and enable ssh and reboot

When you try to connect using ssh pi@raspnberrypi.local you might come across with this warning


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for raspberrypi.local has changed,
and the key for the corresponding IP address uu
has a different value. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /Users/user/.ssh/known_hosts:7
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
h. Please contact your system administrator.
Add correct host key in /Users/vasilis/.ssh/known_hosts to get rid of this
 message.
Offending ECDSA key in /Users/vasilis/.ssh/known_hosts:19
ECDSA host key for raspberrypi.local has changed and you have requested strict
 checking.
Host key verification failed.

To solve the problem try to delete previous keys in known_hosts file like pi@raspnberrypi.local

then try to login

$ ssh pi@raspnberrypi.local

and type yes to accept a new permanent key for local.

After that go and update

$ pi@raspberrypi:~ $ sudo apt-get update

and upgrade

$ pi@raspberrypi:~ $ sudo apt-get upgrade

then you can start installing software such as SuperCollider, emacs etc.

Ethernet set up

Building from Source on Raspberry

  • connect an ethernet cable from the network router or your computer to the rpi

  • insert the sd card and usb soundcard

  • last connect usb power from a 5V@1A power supply

Install emacs

Choose Shell

pi@raspberrypi:~ $ sudo apt-get install emacs25

quick installation of prelude emacs.

Install Git first;

pi@raspberrypi:~ $ sudo apt-get install git
pi@raspberrypi:~ $ curl -L https://git.io/epre | sh

The Meta key in terminal emacs is the ESC key So press ESC-x for Meta-x

next step is to install supercollider in emacs

Install SupeCollider on RPI

Installation guide from: Building SC on RPI

Choose Shell

$ ssh pi@raspberrypi.local #from your laptop, default password is raspberry
$ sudo raspi-config #change password, expand file system, reboot and log in again with ssh

update the system, install required libraries & compilers

$sudo apt-get update

$sudo apt-get upgrade

$sudo apt-get install alsa-base libicu-dev libasound2-dev libsamplerate0-dev libsndfile1-dev libreadline-dev libxt-dev libudev-dev libavahi-client-dev libfftw3-dev cmake git gcc-4.8 g++-4.8

compile & install jackd (no d-bus)

$git clone git://github.com/jackaudio/jack2 --depth 1
$cd jack2
$./waf configure --alsa #note: here we use the default gcc-4.9
$./waf build
$sudo ./waf install
$sudo ldconfig
$cd ..
$rm -rf jack2
$sudo nano /etc/security/limits.conf #and add the following two lines at the end
    * @audio - memlock 256000
    * @audio - rtprio 75
 exit #and log in again to make the limits.conf settings work

compile & install sc master

$git clone --recursive git://github.com/supercollider/supercollider
#optionally add –depth 1 here if you only need master
$cd supercollider
$git submodule init && git submodule update
$mkdir build && cd build
$export CC=/usr/bin/gcc-4.8 #here temporarily use the older gcc-4.8
$export CXX=/usr/bin/g++-4.8
$cmake -L -DCMAKE_BUILD_TYPE="Release" -DBUILD_TESTING=OFF -DSSE=OFF -DSSE2=OFF
-DSUPERNOVA=OFF -DNOVA_SIMD=ON -DNATIVE=OFF -DSC_ED=OFF
-DSC_WII=OFF -DSC_IDE=OFF -DSC_QT=OFF -DSC_EL=OFF -DSC_VIM=OFF
-DCMAKE_C_FLAGS="-mtune=cortex-a7 -mfloat-abi=hard -mfpu=neon
-funsafe-math-optimizations"
-DCMAKE_CXX_FLAGS="-mtune=cortex-a7 -mfloat-abi=hard -mfpu=neon
-funsafe-math-optimizations" ..
$make -j 4 #leave out flag j4 on single core rpi models
$sudo make install
$sudo ldconfig
$cd ../..
$rm -rf supercollider
$sudo mv /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI
/usr/local/share/SuperCollider/SCClassLibrary/scide_scqt/GUI
$sudo mv /usr/local/share/SuperCollider/SCClassLibrary/JITLib/GUI
/usr/local/share/SuperCollider/SCClassLibrary/scide_scqt/JITLibGUI

start jack & sclang & test

$jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &
#edit -dhw:1 to match your soundcard. usually it is 1 for usb, or,jackd -P75-dalsa -dhw:UA25EX -p1024
-n3 -s -r44100 &
$sclang #should start sc and compile the class library with
only 3 harmless class overwrites warnings
    $s.boot #should boot the server
    $ a= {SinOsc.ar([400, 404])}.play #should play sound in both channels
    $ a.free
     {1000000.do{2.5.sqrt}}.bench #benchmark: ~0.89 for rpi2, ~3.1 for rpi1
    $ a= {Mix(50.collect{RLPF.ar(SinOsc.ar)});DC.ar(0)}.play#benchmark
    $ s.dump #avgCPU should show ~19% for rpi2 and ~73% for rpi1
    $ a.free
    $ 0.exit #quit sclang
$ pkill jackd #quit jackd

Run SuperCollider on emacs

raspberrypi_SuperCollider

create directory packages in ~/emacs.d/personal/

and mv /directory-of-scel/el/ to /packages-directory/

then write in the init.el file

Choose emacs-lisp


(add-to-list 'load-path "~/.emacs.d/personal/packages/el")
(require 'sclang)

Create an Extensions directory in /usr/local/share/SuperCollider/

and cp the sc directory from ~/supercollider/editors/scel/sc to /usr/local/share/SuperCollider/Extensions/

Then type to the terminal

Choose Shell

pi@raspberrypi:~ $ jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &
//pi@raspberrypi:~ $ scsynth -u 57110 &
pi@raspberrypi:~ $ emacs -sclang

Copy directories from mac to pi using terminal

$ scp -r /path/to/directory pi@raspberrypi:~/path/to/remote/dir

example:

$ scp -r /Users/path pi@raspberrypi:~/SC_Stuff

Open raspberrypi3 from emacs using TRAMP

C-x C-f and type <Choose Shell

/ssh:pi@raspberrypi:

then type your raspberry password

 pass: *******

and then dired freely, open files and programms using shell as well to run sclang

Edit and save files using tramp

C-x C-f and type

/ssh:pi@raspberrypi|sudo:root@pi@raspberrypi:

dired to your file, make changes and save it!!!

Copy files from Raspberrypi to mac and the opposite

scp /path/to/py/file pi@raspberrypi:~

Replace raspberrypi with the ip address of the Pi if using the hostname doesn't work.

or from the pi

scp macuser@macipaddress:/path/to/py/file ~

replace macuser and macipaddress with your mac user and mac's ip address.

https://www.raspberrypi.org/forums/viewtopic.php?t=35152&p=296946

The following syntax is used to rename files with mv:

mv (option) filename1.ext filename2.ext

Use rsync

Choose Shell

Transfering files from raspberry to mac

On your terminal use cd to change directory to your files directory and type the following command:

 Recordings Directory git:(SuperCollider) ✗ rsync -avz -e ssh pi@192.168.1.96:/home/pi/.local/share/SuperCollider/Recordings/ Recordings/
some_dir ✗ rsync -avz -e ssh pi@192.168.1.96:~/sounds/voices/ voicesA/
pi@192.168.1.96's password:
receiving file list ... done
created directory voices

If it doesn't work with the name of the raspberry you need to find the ip of raspberry. To find the ip ssh to your raspberry and type:

$ sudo ifconfig

it will ask for the pass word:

pi@192.168.1.96's password:
receiving file list ... done
created directory Recordings
./
SC_161215_114846.aiff
SC_170422_120739.aiff
SC_170422_135403.aiff

sent 88 bytes  received 11223209 bytes  477587.11 bytes/sec
total size is 25854264  speedup is 2.30
➜  Recordings git:(SuperCollider)

Transfering files from mac to raspberry

$ onedirup~> rsync -avP a_folder_inside_this_dir/ pi@192.168.1.96:~/dir/folder/

If you asked to login as a root do the following:

  • set a root password

sudo su -
passwd

and then you can ligo as root

$ onedirup~> rsync -avP a_folder_inside_this_dir/ root@192.168.1.96:~/dir/folder/

Install Adafruit MPR121 on Raspberry

Soldering

Prepare the header strip, Add the breakout board, and solde

see more here

After you've soldered the sensor to the header strip move to wiring sesion:

Wiring

Wiring Place the MPR121 board into a breadboard and connect its inputs to the electrodes you plan to use. Then follow the wiring below for your platform to connect the MPR121 to an I2C communication channel. Raspberry Pi On a Raspberry Pi connect the hardware as follows. Note: Make sure you've enabled I2C on your Raspberry Pi!

First make sure that you've installed python.

Choose Shell

sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus python-pip git

Then clone Adafruit_Python_MPR121.git

cd ~
git clone https://github.com/adafruit/Adafruit_Python_MPR121.git

and install it

cd Adafruit_Python_MPR121
sudo python setup.py install

Configuring I2C

I2C is a very commonly used standard designed to allow one chip to talk to another. So, since the Raspberry Pi can talk I2C we can connect it to a variety of I2C capable chips and modules. Here are some of the Adafruit projects that make use of I2C devices and modules:

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

Testing I2C

Now when you log in you can type the following command to see all the connected devices

Choose Shell

$ sudo i2cdetect -y 1

Usage

Choose Shell

cd examples
sudo python simpletest.py

These are the output values of 12 capacitive touch inputs

  • 0 = 1

  • 1 = 2

  • 2 = 4

  • 3 = 8

  • 4 = 16

  • 5 = 32

  • 6 = 64

  • 7 = 128

  • 8 = 256

  • 9 = 512

  • 10 = 1024

  • 11 = 2048

install arduino on raspberrypi3

first update and upgrade raspberry

update and upgrade raspberry

$-> sudo apt-get update && sudo apt-get upgrade

then install arduino

install arduino

$-> sudo apt-get install arduino

install serial port

go and open the file config.txt on boot on you raspberry and enable serial port

Enable serial port usage by adding enable_uart=1 to the file /boot/config.txt.

install serial port

then run nmp install serialport

update nodejs 9 version

update nodejs to 9 version

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -

install nodejs 9 v

install nodejs

$ sudo apt-get install -y nodejs

in case you have already installed node you need to remove it and install nodejs again

remove node and reinstall nodejs

$ sudo apt remove node
$ sudo apt remove nodejs
$ sudo apt install nodejs
$ sudo reboot

install johny-five

install johny-five

nmp install johnny-five

install osc

install osc

$ npm intall osc

tip on serialport - server.js parser: SerialPort.parsers.Readline

run arduino ide on raspberrypi

arduino ide on raspberrypi

install dependencies

install dependencies

sudo apt-get install avr-libc libftdi1 avrdude librxtx-java

find and install java

apt-cache search java | grep openjdk
sudo apt-get install openjdk-9-jre

Makefile for Arduino sketches. It defines the workflows for compiling code, flashing it to Arduino and even communicating through Serial.

https://github.com/sudar/Arduino-Makefile

install arduino-mk

sudo apt-get install arduino-mk

Run arduino makefile on emacs

https://www.emacswiki.org/emacs/ArduinoSupport

Create simple Makefile in the same directory as your .ino file. Contents can be as simple as this (only the include is truly necessary, all other lines can be omitted for simple sketches):

makefile arduino emacs

BOARD_TAG = uno (see make show_boards)
ARDUINO_LIBS = <space separated list of libs, arduino.mk will try to guess>
MONITOR_PORT = /dev/ttyUSB0 (will be automatically guessed from IDE prefs)
include /usr/share/arduino/Arduino.mk

Chage permission to read-only files

Choose Shell

➜  ~ cd /Volumes
➜  /Volumes ls
Macintosh HD boot
➜  /Volumes cd boot
➜  boot ls
.
➜  boot sudo chmod a+w cmdline.txt
Password:
➜  boot

erase sd card

Open terminal and type:

Choose Shell

diskutil eraseVolume ExFAT MyName diskX

change diskX to your disk number; i.e. disk2s1

issue with partition: check your disk number

diskutil list

change the disk2 to your disk number and do the following:

diskutil eraseDisk FAT32 MYSD MBRFormat /dev/disk2