Inside the Black Box (or chipboard box)

Posted on Nov 1, 2013 in Physical Computing
Inside the Black Box (or chipboard box)

Assembled and Then Dis-Assembled!

So I managed to pull together the box and the wiring today… knowing full well that I’d likely need to make gears if I want the film to spin appropriately.
I can’t say that I’ve worked out all the bugs. In fact, I think it will always sound a bit like Charlie Brown’s teacher, but it does seem to be getting close to being a musical instrument in spite of itself. I’m going to walk through the process before moving on to tomorrow’s code and assembly tasks.

The Process


1. Hooked everything up and  set it inside the ‘box’. I ran a first iteration of code which looked something like below (#1) only to realize that the motor, while audible didn’t really have the power to turn given friction and the light readings were really, really low, 0-10 low. So, I cracked open the box and began an open wiring session to test things again.

Yep, it’s super messy. (I’ll upload a wiring diagram tomorrow/edit post)

messy wiring initial

2. So yes, my screw posts refused to stay seated in the breadboard. So there will be a better solution tomorrow.  But the triumph of this round was realizing that an approximate seat for the light sensor was not enough. There is now a gracious helping of epoxy making sure it’s completely stabilized and, viola!, it reads.

It sounds crazy, but those are the oscilloscope beeps in the original. From there, I went on to testing switches…basically making sure to set thresholds (for the analog sensors) and booleans (for the toogle switch) that covered all possibilities. Because before that… I was getting:

3. So now that the switches are jiving and the light sensor is reading with some sort of sound feedback, I turn to the motor speeds. I’d started with the straight forward DC switching lab, which seemed ok, but because I had everything dispersed but on the same circuit in serial fashion I was getting mixed reads. A shift in the light sensor was effecting the motor potentiometer and visa versa.


4. Just spatially my brain wasn’t quite able to wrap itself around how to clean-up the breadboard for a true parallel setup. Instead I decided to split power supplies and keep the two haves disentangled. The motor, H-bridge, and it’s potentiometer could work off of battery power while the light sensor and speaker side of things would work from the Arduino’s 5V. It’s completely straight forward and, just to be safe, at 250 mA in the motor side of things, I brought the voltage for the motor and H-bridge down to 5v using 20+ ohm resistors.  It still looks radically chaotic.

messy wiring final

(see the screw connector, bringing power actually into the battery side).

5. And so now, things seem to be nicely disentangled, but I wonder if I’m getting some spikes in the momentary button. (I’ll have to check the readings in the morning.)

The other issue to be dealt with is the fact that I’ve decided to incorporate a) the speaker and b) the motor into a tiny little box of wiring. Both of those generate current or use induction (amp?) as their basic mode of functioning (yes?) and I’m pretty sure that packing them together is going to create some really unanticipated feedback.

I did switch out the oscilloscope reel section for a bit of  more varied speech, just to see its effect on readings mappings, but I think the speed of the system and the note duration is still going to be problematic. The ‘Charlie Brown’s Teacher sound’ isn’t particularly a faithful analog by any means. I’ve added a little delay (to be fine tuned tomorrow) just to make the noise musical. The slot reading dimension for the light sensor is a bit bigger (laser kerf) than each individual sound frame (@ 720/second or approx. .01″) and so there’s no way to mechanically improve performance. Happy accidents and code adjustment will have to do.

Anyways- tomorrow is going to be cleaning and clarifying the system- tweeking code and streamlining connections/box setup. I really need to can lift all the panels off to work with and something that can play ‘open’ so that the feedback is minimized without disrupting the interface and interaction.


Current Code (75% comments):
int powerPin=2;//push to right= continuous, push to left = momentary-WORKS!

int readerPin=A0;
int lightPin=8;

int speakerPin=13;

int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;// the enable, and two inout pins for the motor
int switchPin = 7;//direction button
int potPin =A5;//analog potentiometer for speed-less potential for short between A0 and A5…

void setup(){// all the digital read devices
pinMode(powerPin, INPUT);
pinMode(lightPin, OUTPUT);
//speaker to be specified in loop-tone setup
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);

void loop(){
//start with digital power state
if (digitalRead(powerPin) == HIGH) {
//then begin with the light on, motor on, and sensor readings
//film light ON
digitalWrite(lightPin, HIGH);
//temp speaker turned off! digitalWrite(speakerPin, LOW); //still getting some static noise from circuit in general

//motor reads and writes
int speed = analogRead(potPin) /4;//speed = the potentiometer input-WORKS-secondary 9v
boolean reverse = digitalRead(switchPin);//direction=digital on-off-??
int speedM=map(speed,175,255, 0, 255); //remap for the higher power supply- up resistance beyond
//500 mA H bridge to whatever toy motor is rated
if (speedM>10){//
setMotor(speedM, reverse);// see function below- motor too tight right now
// Serial.println(speedM);//READ OUT OK-0 TO 255 AS NORMAL

//getting general interferance between potPin readings AO and readerPin A1
//need to get them in parallel to so that they don’t mess with the full 5V readings
//or give them different power (yes, done) sources so that shift in resistence in one area
//isn’t reading in the other

//or is this literally spatial- both the speaker and motor can induce current in a certain range
// is this just a little box of feedback interference.

//or can I H-bridge with a second power supply,
//make sure it steps down to 5v and then take out ground?

//light and motor test first for mapping speed values
//sensor is read from light/film- secondary mapping of values
int filmRead=analogRead(readerPin);//getting very, very low read- trouble shoot…
Serial.println(filmRead);// 310 to 455 for the oscilloscope areas, 325 as cutoff
float frequency = map(filmRead, 325, 450, 325, 450);//arghhh… not audible as speech at any speed.
//change the pitch, map milliseconds- 720 frames/second, but that sounds horrible/choppy
tone(speakerPin, frequency, 1000/2);//overlaps but w/ delay sounds ok
delay(frequency/3);//this makes it musical… since we’re cutting out slivers read
//delay(1000/720);// to get voice reading… still ‘charlie brown’s teacher’ sound.
if (filmRead<325){// cut out lower range
// will need to tie duration to the motor speed?
// float pitchTime=float(speed)/x; or something to that end

} else{
digitalWrite(lightPin, LOW);//perfect light on & light off
//motor reads and writes
int speed = 0;//speed = the potentiometer input-WORKS- turn off
boolean reverse = digitalRead(switchPin);//direction=digital on-off-??
setMotor(speed, reverse);// will this have enough power?


void setMotor(int speedM, boolean reverse){
if (speedM>10){
analogWrite(enablePin, speedM);
digitalWrite(in1Pin, ! reverse);
digitalWrite(in2Pin, reverse);
} else {
analogWrite(enablePin, 0);