Showing posts with label pure data. Show all posts
Showing posts with label pure data. Show all posts

Sunday, 15 October 3015

Pd on a Pi





















This resource is for those who wish to get pure data  extended running on a raspberry pi.
Here you will find clear and concise instructions on running and installing pure data extended, running it headlessly and how to get data in and out using various sensors and peripherals.

The following pages have all been run and tested using raspberry pi's versions one and two, running the Raspbian Wheezey software. The host computer used to communicate with the pi is a mac running OSX 10.9.5 . Other pieces of hardware used are listed.

Alternative operating systems, or hardware may give different results.

Installing the operating system

Installing Pd-Extended and other software




Thursday, 22 October 2015

Using digital pins in

First make sure you have the relevant software and librarys installed, the following libraries are relevant for getting all sorts of inputs in from the pi.

in a terminal window

git clone https://github.com/ptone/pyosc.git  
cd pyosc
sudo ./setup.py install
cd
sudo apt-get install python2.7-dev
wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
unzip master.zip
rm master.zip
cd py-spidev-master
sudo python setup.py install
cd
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd
sudo apt-get install python-setuptools python-dev
git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python/
sudo python setup.py install
cd
git clone git://github.com/guyc/py-gaugette.git
cd py-gaugette
sudo python setup.py install
cd



wire up a button, heres a diagram, note the button is attached to pin 18 and ground



The button is read by a simple python script, this information is then passed to pd-extend via OSC

the pd patch starts the python patch automaticaly using the shell object

(n.b if auto-starting  the pd patch though updating the rc. file (see starting headlessly) the pd patch needs the full address of the python script)


first start up the pd patch, this will open a osc channel, then will open the python script which will start sending the data.
here's some screen shots of how the pd patch works. download the patch here



here's the python script.download it here


#!/usr/bin/python

import time
import os
import OSC
import RPi.GPIO as GPIO

# Open osc

send_address = "127.0.0.1" , 9000
c = OSC.OSCClient()
c.connect(send_address)

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)



# Define delay between readings
delay = 0.1
while True:


  input_state1 = GPIO.input(18)

  if input_state1 == False:
      print('Button 1  Pressed')
  
  
  msg = OSC.OSCMessage()
  msg.setAddress("print")  
  msg.append(input_state1) 
  


  c.send(msg)


  

Thursday, 15 October 2015

copy library to pd-extended library

first open terminal on the pi
move the terminal path to where the folder is (the folder pd is in the folder rjdj in the home/pi folder)

cd home/pi/rjdj


then to copy a folder

sudo cp -r  pd  /usr/lib/pd-extended/extra

this moves the folder pd (inside the folder rjdj - located at /hmon/pi)  to the pd library extra (inside the folder  /usr/lib/pd-extended/extra)

to remove a folder

sudo rm -r  /usr/lib/pd-extended/startup/pd



getting sensors in using the MCP3008

Attaching a mcp3008 chip to your pi will give you 8 channels of analogue ins, the pi's pins can be used straight away to register button presses


you can buy a mcp3008 chip here
to get it running, first make sure you have the relevant software and librarys installed, the following libraries are relevant for getting all sorts of inputs in from the pi



in a terminal window

git clone https://github.com/ptone/pyosc.git  
cd pyosc
sudo ./setup.py install
cd
sudo apt-get install python2.7-dev
wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
unzip master.zip
rm master.zip
cd py-spidev-master
sudo python setup.py install
cd
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd
sudo apt-get install python-setuptools python-dev
git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python/
sudo python setup.py install
cd
git clone git://github.com/guyc/py-gaugette.git
cd py-gaugette
sudo python setup.py install
cd


Next make sure you have your SPI interface enabled on the pi

in terminal

sudo raspi-config

8. Advanced Options


A6. SPI


turn it on



turn on SPI kernal module on default




then reboot the pi



wire-up yer mpc3008







these pictures came from here

this page will show you the different pins on different models of raspberry pi



raspberry pi 1 pins


raspberry pi 2 pins




communicating inputs

the mpc3008 is read by a simple python script, this information is then passed to pd-extend via OSC

the pd patch starts the python patch automaticaly using the shell object
(n.b if auto-starting  the pd patch though updating the rc. file (see starting headlessly) the pd patch needs the full address of the python script


first start up the pd patch, this will open a osc channel, then will open the python script which will start sending the data.

here's some screen shots of how the pd patch works. download the patch here





inside the subpatcher pd sortmes



here is the python script, download it here




#!/usr/bin/python

import spidev
import time
import os
import OSC
import RPi.GPIO as GPIO

# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)

# Open osc

send_address = "127.0.0.1" , 9000
c = OSC.OSCClient()
c.connect(send_address)

# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data


# Define sensor channels
l0 = 0
l1 = 1
l2 = 2
l3 = 3
l4 = 4
l5 = 5
l6 = 6
l7 = 7


# Define delay between readings
delay = 0.1

while True:

  # Read the light sensor data
  ll0 = ReadChannel(l0)
  ll1 = ReadChannel(l1)
  ll2 = ReadChannel(l2)
  ll3 = ReadChannel(l3)
  ll4 = ReadChannel(l4)
  ll5 = ReadChannel(l5)
  ll6 = ReadChannel(l6)
  ll7 = ReadChannel(l7)


  msg = OSC.OSCMessage()
  msg.setAddress("print")  
  msg.append(ll0)
  msg.append(ll1)
  msg.append(ll2)
  msg.append(ll3)
  msg.append(ll4)
  msg.append(ll5)
  msg.append(ll6)
  msg.append(ll7)
  









i





handy stuff to know

to copy a folder

sudo cp -r  pd  /usr/lib/pd-extended/extra


remove a folder

sudo rm -r  /usr/lib/pd-extended/startup/pd


update operating system, and aplications

sudo apt-get update


to stop program

sudo pkill pd-extended


to stop process in terminal

press ctrl and c together

auto-start pd patch- to run headlessly

open terminal, type this in to edit  file.

sudo nano /etc/rc.local

Add this line below the comment, but leave the line exit 0 at the end, then save the file and exit.

pd-extended -nogui /home/pi/sensors/allsensorwritetolist.pd &





The & at the end stops an infinate loop so dont forget to put that in.
"-nogui" in the address starts the program up without its graphic display, if you want  graphic display remove this.
If running the pi headless, got to raspi-config and turn down how much memory the interface uses.
note!!!! and any script inside pd needs the full address

to copy sd card

use pi-copy,follow on screen instructions


download it here 



install espeak

open terminimal, type this in

sudo apt-get install espeak



to get it talking
open terminimal, type this in


 espeak "hello kathy, i am mark"

the espeak website is here

set up pd-extended

set up pd extended

experiment with these

go to audio settings

sample rate 22050
delay 100 ms
block size  512

turn off input device

VNC server - get your pi desktop on your mac

download vnc for the mac here 

first ssh from your mac to your pi. see how to do that here


then on the pi download and install VNC,open terminal and type

sudo apt-get install tightvncserver

start VNC on the pi, by typing in the terminal


sudo tightvncserver

(give it a password different to the pi- on first time install)

then on mac launch vnc viewer


vnc will want to connect to the pi- input the pi's ip address and then password .

Netatalk

Netatalk allows you to take files on and off a pi when connected through ssh
heres its website

To find out more about connecting via ssh look here

getting it working


on the pi type into a terminal window

sudo apt-get install netatalk


then on the mac open a new terminal window

open afp://192.168.0.10 (pi ip address here) - to find your pi's ip address look here

input pi password


then a finder window with the pi's home directory appears

Control the pi from a mac using SSH

to use the pi without keyboard, mouse or screen use ssh.
In order to use ssh the pi needs an active wifi connection , or needs to be joined to a mac via its ethernet port

first open a terminal window on the pi and type

hostname -I

the pi will return the pi's ip adress, something like 192.168.0.10



now go to your mac, and open terminal

first get rid of any old address by entering

ssh-keygen -R 192.168.0.10 (put in your pi ip address)

then connect by typing

ssh pi@192.168.0.10 (put in your pi ip address)

then input the pi's password (raspberry)

now you can copy files using netatalk
get graphic environment on mac by using VNC


Installing software

The following terminal commands downloads and installs various bits of software i have found useful for running on the pi together pd-extended. A fuller explanation of what you are installing is underneath.
Make sure the pi has an open internet connection
 Open a terminal window




first you need to update your sources list.

 sudo pico /etc/apt/sources.list

then put this line at the bottom of the file and save (control o, then return, control x)

deb http://apt.puredata.info/releases wheezy main 




open terminal and input each one of these one line at a time

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-key 9f0fe587374bbe81
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-key D63D3D09C39F5EEB
sudo apt-get update
sudo apt-get install pd-extended
git clone https://github.com/rjdj/rjlib.git
cd rjlib
sudo cp -r  pd  /usr/lib/pd-extended/extra
sudo cp -r  rj  /usr/lib/pd-extended/extra
cd
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd
sudo apt-get install python-setuptools python-dev
git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python/
sudo python setup.py install
cd
git clone git://github.com/guyc/py-gaugette.git
cd py-gaugette
sudo python setup.py install
cd
git clone https://github.com/ptone/pyosc.git
cd pyosc
sudo ./setup.py install
cd
sudo apt-get install python2.7-dev
wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
unzip master.zip
rm master.zip
cd py-spidev-master
sudo python setup.py install
cd
sudo apt-get install espeak
sudo apt-get install netatalk
sudo apt-get install tightvncserver
sudo apt-get install omxplayer

sudo apt-get update



what you have installed


Pd-Extended

RJDJ pd-extended library

Netatalk

VNC server

Espeak

Python 2.7

PyOSC python library
Py-spidev python library
Python-set up tools python library
WiringPi2-Python python library
WiringPi python library
Py-gaugette python library

OMXPlayer

installing the operating system

Installing Raspberry Wheezy, onto a Raspberry Pi Mk2 using a Mac powerbook os 10.9.5

Download Raspbian Wheezy
 - download here 
Download Pi-filler
  - download here

install onto a SD card using Pi-filler.
Start up raspberry pi attached to a monitor, with mouse, keyboard attached and wifi adapter .
- the wifi adapter used is this one 

ELEMENT14  WIPI  WLAN USB Module for Raspberry Pi
avalible here




now boot up your pi, when it boots up you are presented with


choose 

1 Expand Filesystem
7 Overclock  (overclocked to raspberry pi version 2)
8 Advanced options

A6 SPI 


turn on SPI as defualt, and load it by default



select <Back> then select <Finish>

reboot the pi and start the graphic enviroment

raspberrypi login: pi

password:             raspberry

then type               startx

which brings up the raspberry pi desktop



when the desktop loads move the mouse to the network icon, top right, and click. Input your wifi password, press return.



If you've typed the password correct a wireless icon is displayed.



alternatively you can connect the pi to the internet by simply plugging in an ethernet cable from your modem/router.