Using Arduino and Processing together

Today I got up early and fooled around in Processing…for hours. I was playing with the Minim sound library, which I’d planned to use for my Intro to Computing Media project, an mp3 player. After sitting around for so long, I could how I was getting both noticeably older in age, but also wiser about Minim. Why sit around and program something completely different when I could put the two together? Well, my fear with combing my two projects, ICM and PhysComp, was that I’d skimp out on one or the other and not fully challenge myself. However, due to the MEX conference – to be blogged about soon! – my schedule is shorter than I’d like. Something’s gotta give. Sadly, it’ll have to be a little bit here and there on my projects.

Anyway, today, I worked on combining my Arduino code and my Processing code using serial output to play a song. Before discussing this, a little recap:

Create the code to turn on/off LEDs set at a threshold. Using the map() function and an if/else statement, I can now reliably turn off and on an LED as though it were a switch.
Here’s the code for the mapping and if/else statement part:

phoVal1 = analogRead(phoPin1);
  //map the photocell values and turn on the light
  phoVal1 = map(phoVal1, 0, 255, 255, 0);
  if (phoVal1>=0) {
    digitalWrite(pholed1,HIGH);
  }
  else{
    digitalWrite(pholed1,LOW);
  }

Here’s the code for the FSR:

FSRValue = analogRead(analogFSR); // read the left FSR value
  analogWrite(motorpin, FSRValue/4);

The next step was to combine this code with the Minim library in Processing. But first, write code in Processing! Here is where several hours with Minim came in handy. I was able to hobble together enough code to be able to play and pause a song. I haven’t yet created any arrays, for a media list, but that’s next, as well as the ability to move through the array. After that I sent the output in serial DEC to Processing. I just added this little bit of code:

if (xpos > 100){
 song.play();

After that, I was able to use the serial output from the FSR and Photocell to trigger the song.play(); function. I suppose, I could find a audio visualization program to tweak, so that I can make a pretty picture show when a song plays, assuming I play a song.

Next I’ll need to refine all the code, and plan out more of how I want the sensors to interact with the plants. And, I need to get some plants.

UPDATE: Code is not working as expected. Processing is just playing a song when the sketch is run. I need to figure this out some more.

Still thinking about changing my final project idea: interactive plant vs blinky lights?

A discussion Monday night got me thinking about my Phys comp final again. I like the bionic gardening, but I also want something really fun. The other student I was talking with was trying to convince me to do my original-ish LED light board idea. So, at home I thought about it a little bit more.

If I had the time to do this, I’d get 108 RGB LEDs, and a perfboard in 5″ x 5″ squares to measure a rectangle 30″ L x 10″ H. Each LED would be spaced 2.5″ from its neighbor, so that there would be 9 LEDs per square.

The interaction: When a user walks by, the LEDs light up in response. The color of the LED depends on how far or close the user is to the LED board. So, the closer, the more red; basically it goes through the visible light spectrum starting from indigo to red.

In addition, my original idea had sound output as well. Sound might be too confusing. I sort of just like the LEDs. I think this is something that would look spectacular, but I just don’t feel that I have enough time.

UPDATE: Perhaps I’ll just do this on my own, anyway. Seems easier than the UV Sunlight watch, but more difficult than the talking plant. In any case, I need to order ton 0′ parts, soon!