Obs Proj TWO, the Final Stretch [um, Prototype]

Although the drum trigger was working, it was not giving us reliable results. As suggested in class we decided to work in parallel. We ultimately wanted two working paddles, so we decided to have one hooked up to a midi synth box and the other one using the Sonia sound library in Processing.

I am not taking ICM so I had never used Processing before. Dan Shiffman’s book draft was invaluable in getting me up to speed, but soon realized that sound was not Processing’s forte. At the end of the day I got Daniel to come by and take a look at my code and even he couldn’t figure out why it wasn’t working!

So I ditched Sonia for the time being and got the midi synth box from the ER. I got some simple tones to play with the paddle. Going back to my days of playing flute I got the paddles to play Salt ‘n Peppa’s “Push It”.

DEFINE OSC 20
DEFINE HSER_RCSTA 90h ‘ enable the receive register
DEFINE HSER_TXSTA 20h ‘ enable the transmit register
DEFINE HSER_BAUD 31250 ‘ set the baud rate

TRISD = %00000000 ‘Set all of PORTD pins to output mode

paddleVar VAR word ‘Create variable to store result
pitch var byte(12)

i var byte
i=0

‘ ranges for reference
pitch(0) = 60′ mid c
pitch(1) = 61′ c#
pitch(2) = 62′ d
pitch(3) = 63′ d#
pitch(4) = 64′ e
pitch(5) = 65′ f
pitch(6) = 66′ f#
pitch(7) = 67′ g
pitch(8) = 68′ g#
pitch(9) = 69′ a
pitch(10) = 70′ a#
pitch(11) = 71′ b

‘ a,e,d,c,b,g,g,b,c,b,g - salt n peppa push it!
‘69,64,62,60,71,67,67,71,60,71,67
song var byte(11)
song(0)=69
song(1)=64
song(2)=62
song(3)=60
song(4)=71
song(5)=67
song(6)=67
song(7)=71
song(8)=60
song(9)=71
song(10)=67

‘light debug sequence
high PORTD.0
pause 200
low PORTD.0

high PORTD.1
PAUSE 200
low PORTD.1

main:
ADCIN 3, paddleVar ‘coming in at analog port 3

if paddleVar > 100 THEN ’set to 100 since slight vibrations give off readings
hserout [$90, pitch(i),$40]
if(i>11) then ‘loop thru song once its at end reset to 0 o
i=0
ELSE
i=i+1
ENDIF
ENDIF

PAUSE 100

goto main

*One thing to remember, when working with the midi box, you need a 20 hz clock and when you program the chip you have to change the oscillator from XT to HS.

ConstructionWOES
On the sensor/paddle side, Steve ran into Danny Tsang [who had done a similiar project for a class] and he told us a better way to rig the paddles. Steve stripped a piezo speaker and took out the piezo film inside, carefully soldered the connections.

We hollowed out the paddle handle, ran wires through it and glued the pieces back on.

Steve used Gorilla Glue, which takes about 3 hours to dry. BUT the glue expands which fixes the sensor into place. [pic here]

We got some code that handled the sensor peak readings and luckily got Sonia to work at the last minute.

‘ Define ADCIN parameters
DEFINE ADC_BITS 10 ‘ Set number of bits in result
DEFINE ADC_CLOCK 3 ‘ Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 20 ‘ Set sampling time in uS

PeakValue var word
SensorValue var word
LastSensorValue var word
Threshold var word
Noise var word
PingPong VAR WORD

PingPong = 420

‘ serial pins and data reate:
tx var portc.6
rx var portc.7
n9600 con 16468

Threshold = 50 ‘ set your own value based on your sensors
PeakValue = 0 ‘ initialize peakValue
noise = 5 ‘ set a noise value based on your particular sensor

‘ Set PORTA to all input
TRISA = %11111111
‘ Set up ADCON1
ADCON1 = %10000010

Main:
‘ read sensor on pin RA0:
ADCin 3, sensorValue

‘ check to see that it’s above the threshold:
If sensorValue >= threshold + noise then
‘ if it’s greater than the last reading,
‘ then make it our current peak:
If sensorValue >= lastSensorValue + Noise then
PeakValue = sensorValue
endif
‘ if the sensorValue is not above the threshold,
‘ then the last peak value we got would be the actual peak:
Else
If peakValue >= threshold then

‘ this is the final peak value; take action
’serout2 tx, n9600, ["peak reading", DEC peakValue, 13,10]
’serout2 tx, n9600, [DEC peakValue]
serout2 tx, n9600, [DEC pingPong]
endif

‘ reset peakValue, since we’ve finished with this peak:
peakValue = 0
Endif

‘ store the current sensor value for the next loop:
lastSensorValue = sensorValue
Goto main

//PROCESSING CODE FOR SOUNDS

import pitaru.sonia_v2_9.*;
import processing.serial.*;

/*avani added, put sounds in array, sounds should reside in same folder as .pde file */
String[] wavArray = {”first.wav”, “second.wav”,”third.wav”};// new String[3];

//end avani additions
int bgcolor; // background color
int fgcolor; // fill color
Serial port; // the serial port
int[] serialInArray = new int[3]; // where we’ll put what we receive
int serialPong = 0;
int serialCount = 0; // a count of how many bytes we receive

boolean firstContact = false; // whether we’ve heard from the microcontroller
int j=0; //wavs index
Sample bounce;

void setup() {
size(256, 256); // stage size
noStroke(); // no border on the next thing drawn

// print a list of the serial ports, for debugging purposes:
println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);
//port.write(65); // send a capital A to start the microcontroller sending
Sonia.start(this); // Start Sonia engine.

}

void draw() {
background(bgcolor);
fill(fgcolor);
// get any new serial data:
while (port.available() > 0) {
serialEvent();
// note that we heard from the microntroller:
firstContact = true;
}
}

void serialEvent() {
processByte((char)port.read());
}

void processByte(char inByte) {
// add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;

// if we have 3 bytes:
if (serialCount > 2 ) {
bounce = new Sample(wavArray[j]);
serialPong = (int)serialInArray[0];
println(serialPong);

if (serialPong == 52) {
bounce.play();
j++;
if (j>2) { j=0;}
} serialCount = 0;
}
}

// Safely close the sound engine upon Browser shutdown.
public void stop(){
Sonia.stop();
super.stop();
}

[processing code here]

We constructed two Radio Shack project boxes in order to keep the components in place when the user swings the paddle.

So without further ado….see the project in action! That’s right! Click here

Lots of fun was had.

0 Responses to “Obs Proj TWO, the Final Stretch [um, Prototype]”


  1. No Comments

Leave a Reply