Monthly Archive for October, 2005

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.

Paddle with peizo sensor

IMG_0227.jpg

Paddle with Pressure sensor

IMG_0225.jpg

Paddle with drim trigger.

IMG_0224.jpg

If it ain’t got that swing…

As part of our ongoing second project, I built two more prototypes to evaluate different sensors. The two sensor used were Piezo vibration (DigiKey #MSP1007-ND), and Force (DigiKey #102-1214-ND).

The Force sensor seemed to hold a lot of promise, as we were trying to sense when the ball is struck by a paddle. After all, that’s the focus of the project: to get the input of ball hitting paddle to create output as some other signal. For prototyping purposes, I just programmed an LED to light as my output.

Initially I peeled back the rubber pad on one side of the paddle and slipped the Sensor underneath it, and replaced the pad. This would have been a perfect solution because it was clean and tidy, but proved to be insufficient. The rubber pad dampened the collision force, and the readings were weak and sparse. If you didn’t hit the ball exactly where the sensor was or within close proximity, you got not reading at all.

For the second attempt, the sensor was placed on top of the rubber pad, and then covered with a stiff membrane (chipboard). This worked much better; no matter where you hit the ball with the paddle, the force was transferred to the sensor. We got plenty of useful readings from the sensor but the team felt that having to put the covering over it detracted too much from the original look and feel of the paddle.



On to Piezo

I was surprised when the Piezo sensors arrived because they were miniaturized versions of the Flex sensor accelerometer that I built a week ago. Working quickly, I designed a third prototype by taping the Piezo sensor to the paddle. These sensors worked fantastically, giving off tons of data. Too much so, in fact. The sensors are so sensitive that just holding the paddle steady, there’s enough vibration in your hand (time to switch to decaf?) to send a steady stream of data out to the PIC.

The challenge then was to develop a filter in the software that would only pass on a signal when the paddle struck the ball, not merely the slightest vibration or wiggle. The raw numbers coming in from the paddle ranged from 30 to 650. Tapping a ball with the paddle produced numbers from 400 to 600. The next step was to set up a filter that would knock out anything under what we thought a ball/paddle collision would produce. This presented a problem because the force of the ball hitting the paddle is always different, therefore it is never consistent. So if we set the filter to eliminate any numbers under say 350, just holding the paddle wouldn’t produce any signal. This seemed to work fine however once a ball was struck, we would then get multiple signals. After analysis, we determined that the problem was produced by the sensor continuing to reverberate after the paddle struck the ball. For instance, if a collision produced a reading of 425, we would then get a slowly descending string of readings from 425 down, until we hit the filter at 350.

To rectify this problem we introduced a new variable into the software that would represent the initial reading of a collision (the highest). We then used this reading as our cut-off point in the filter. After a set amount of time, the filter would be reset to a lower setting in anticipation of the next swing of the paddle. This produced much better results and only one output signal per collision. Unfortunately, the force of swinging the paddle sometimes was great enough to trigger the sensor as well. Much like the Flex sensor accelerometer I developed for my last prototype!

I felt that this could be interesting in our project, for we could create an event that happens when you swing the paddle and another one when the paddle collides with the ball. Sadly, my teammates were skeptical of the sensor protruding from the backside of the paddle and voted to go with the Drum trigger.



Here’s the code:

Spacer = 0

Threshold = 300

main:

High PORTD.1

pause 100

Low PORTD.1

ADCIN 0, ADCvar ‘ Read channel 0 to adval

If ((ADCvar/2) > Threshold) then

serout2 PORTC.6, 16468, [DEC ADCvar/2, 13, 10] ‘ print it to serial out,

pause 250 ‘ with linefeed and carriage return (10, 13)

Spacer = 1

endif

IF (Spacer = 1) then

High PORTD.2

Pause 100

Low PORTD.2

Spacer = 0

Threshold = ADCvar

ENDIF

if (ADCvar/2

Observation Project TWO, it’s Analog, it’s digital….it ANALOG!

Steven decided to strip the drum trigger to see what was inside. He found piezo film which basically senses vibration. We rigged the paddle so that the film was placed inside a groove cut for it near the bottom of the paddle. It picked up the vibration and so we figured out YES the drum trigger is analog. Oh and when the vibration was sensed, the LED in Santa’s mouth lit up! “Ping Pong, Santa’s ON.”

PComp Assignment 6

Bought my motor have not completed this lab because I haven’t been able to find a H-Bridge.

ICM Week 4 Assignment: Animate Array of Objects 2

Using arrays and loops have a simple drawing/object move around or appear in some decorative pattern.

* Please Note this is example comes from Dan Shiffman’s examples

Source code: bouncingball & Ball

ICM Week 4 Assignment: Animate Array of Objects

Now that your creature is an object. Make an array of your creature, with each element move independently. Add some additional functionality or interaction.

Source code: anim_train_object_array

Observation Project TWO, Phase II

We convened and decided to each take a paddle and try out different sensors. We all ended up in the lab at the same time and worked from one board, each testing after another.

Conclusions and findings:

- Drum trigger is digital NOT analog. Had to be hit at a specific pt and not big enough to cover surface area of paddle.

- Flex sensor. Idea was to attach multiple flex sensors to a paddle. Only flex sensor detects when a tennis ball hits it but the range of values is small, very similiar to values when just moving paddle. We tried a various of resistors but this just dropped the values from 900 to 200, but the overall number range stayed the same. After three different flex sensors and no consistent results we decided to try some Piezos.