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)


  

No comments:

Post a Comment