Thursday, July 26, 2012

Raspberry Pi, Blazing Fast

I just re-imaged the Raspi with a new Raspbian "wheezy" image supplied on the raspberrypi.org website. They said it would be faster and it's a LOT faster. Great job, Alex and Dom! Instructions on how to load the OS on your SD card are here.

Saturday, July 21, 2012

Switches and Arduino

Both pins are digital pin 3. The right one goes to the EL Wire
and the left one can go to whatever you want!
I was wiring up momentary switches to control some EL Wire when I discovered something interesting. The El Escudo Dos (Electroluminescent Wire sequencer) has double digital pins after you solder in the headers that allow it to stack onto an Arduino. What that means is you can assign one pin to multiple functions. If you connect a LED to the header pin and write it high you will see both the EL Wire on that pin and the LED light up. In my project linked above I unwittingly assigned the header pins as input for the switches and the same pins as output for the EL Wire, effectively programming them into a circuit so pressing the switch would automatically light the wire. I only figured this out because I wanted to program functions for different flashing sequences to each switch and they wouldn't work, just turn the wire on and off. I finally moved the switches to pins 6, 7, and 8 and everything worked. So it turns out all the code you need to make the EL Wire light up with a switch press is the following which simply assigns the input and output in setup:
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {3,4,5};              // same with switch pins

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
  }
}

void loop() {
//nothing needs to loop!
}
In the project linked above I initially had all that extra code because I was using the Lady Ada tutorial on programming switches with the Arduino and since on an Arduino each pin can only do one thing they used pin 2 for input and pin 12 for output. Their code had to use conditional statements to get the switch to work the LED.
Here is another program version using functions to assign different patterns to the 3 switches:

int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {6,7,8};              // same with switch pins
int val[3];                        // variable for reading the pin status

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
    val[i] = 0;                    // Set val array to 0
  }
}

void loop(){
  for(int i = 0;i<3;i++) {
    val[i] = digitalRead(switchPin[i]);   // read input values and store it in val array
    if (val[0] == HIGH) {
      sequence(5);
    }
    if (val[1] == HIGH) {
      flash(5);
    }
    if (val[2] == HIGH) {
      alternate(2);
    }
    // check if buttons are not pressed
    if (val[i] == LOW) {
      digitalWrite(wirePin[i], LOW);    // turn wires off
    }
  }
}
  
void sequence(int times) {
  for(int i = 0;i<times;i++) {
    digitalWrite(wirePin[0], HIGH);
    delay(90);
    digitalWrite(wirePin[0], LOW);
    digitalWrite(wirePin[1], HIGH);
    delay(90);
    digitalWrite(wirePin[1], LOW);
    digitalWrite(wirePin[2], HIGH);
    delay(90);
    digitalWrite(wirePin[2], LOW);
  }
}

void flash(int times) {
  for(int i = 0;i<times;i++) {
    for(int j = 0;j<3;j++) {
      digitalWrite(wirePin[j], HIGH);
    }
    delay(100);
    for(int j = 0;j<3;j++) {
      digitalWrite(wirePin[j], LOW);
    }
    delay(100);
  }
}

void alternate(int times) {
  for(int i = 0;i<times;i++) {
      digitalWrite(wirePin[0], HIGH);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);
      digitalWrite(wirePin[1], LOW);
      digitalWrite(wirePin[2], HIGH);
      delay(170);
      digitalWrite(wirePin[2], LOW);

      digitalWrite(wirePin[2], HIGH);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[2], LOW);
      digitalWrite(wirePin[1], LOW);
      digitalWrite(wirePin[0], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);

      digitalWrite(wirePin[0], HIGH);
      digitalWrite(wirePin[2], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);
      digitalWrite(wirePin[2], LOW);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[1], LOW);
  }
}


Thursday, July 19, 2012

EL Wire Suit Prototype

Now that the buttons are working I'm excited to make this project into a wearable suit, specifically a Halloween outfit. I modified the wiring to begin to imagine how it will work with buttons on the fingers of a glove that connect all the way down to the Arduino somewhere in a pocket on the shirt. So I put the buttons on one breadboard and all the resistors and 5V and ground connections onto a separate board. The idea is the buttons can be isolated up on the fingers of the glove and all the resistors will be on a board right next to the Arduino since that will need more space than the finger of a glove. So here's the prototype for that setup. The next step will be putting it all together on a shirt!

Monday, July 16, 2012

Button Activated EL Wire Prototype






Just trying to figure out the options for having my students this year program EL Wire for a dance performance, I wanted to find out if a momentary switch activated EL Wire costume would work. So I worked out a prototype, really just enough to make sure the wiring and programming would be feasible. It was easier than I expected. As a jumping off point I used a fantastic LadyAda Arduino switch tutorial that really explains things well. I still couldn't get the concept of a pull-down or pull-up resistor through my thick head but reading about it again in McRoberts' Beginning Arduino finally made it sink in.
The pics show that individual as well as multiple switch presses work. What my students will do if they want to pursue this idea is sew the switches into gloves and the wires into black outfits for a choreographed dance in the dark.
Here's the code:
UPDATE: The first version is all you need as I learned after making this discovery.
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {3,4,5};              // same with switch pins

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
  }
}

void loop(){
}
This version is only needed if you use different pins for input and output:
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {6,7,8};              // same with switch pins
int val[3];                        // variable for reading the pin status

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
    val[i] = 0;                    // Set val array to 0
  }
}

void loop(){
  for(int i = 0;i<3;i++) {
    val[i] = digitalRead(switchPin[i]);   // read input values and store it in val array
    if (val[i] == HIGH) {               // check if any buttons are pressed
      for(int i = 0;i<3;i++) {
        digitalWrite(wirePin[i], HIGH);   // turn wire on in same array index
      }
  }
    if (val[i] == LOW) {              // check if buttons are not pressed
      for(int i = 0;i<3;i++) {
        digitalWrite(wirePin[i], LOW);    // turn wires off
      }
    }
  }
}

Friday, July 13, 2012

Scratch on the Raspi

No new learning today but I added one to yesterday when I brought the Raspberry Pi over to some friends' house for what was supposed to be a dinner invitation but turned into a programming workshop when their two boys, 10 and 14, got it hooked up to their TV. They had never seen Scratch before but the 10 year old, who had already been saying he wants to be a game designer, had that little cat moving all over in response to keystroke in no time despite some resolution issues that made scratch really hard to navigate. For the older boy it sparked an interest in what he could do with text based commands on his MacBook and in no time was compiling Applescripts that did fun stuff with his browser.

EL Wire Beat Detector with Processing on an Arduino

So the hardware here is an Arduino Duemilanove with an EL Escudo sequencer and 3 lengths of 3m ELWire. I'm controlling the Arduino with a Processing sketch because I wanted to use the Sonia audio library to process audio input on the laptop and send pinOut commands to the sequencer. I read a little more on that and it looks like the Minim audio library may be a better choice with more options for isolating pitch frequencies I think. You can see it starts responding to MJ's voice and other sounds. Ultimately I plan to have some students work on programming EL Wire sequences for a student dance performance where the EL Wire will be woven into some costumes. I have to figure out if I can integrate an XBee into the works to send the commands to multiple units over wifi so the costumes can be centrally controlled.
Here's the code:



import processing.serial.*;
import cc.arduino.*;
import pitaru.sonia_v2_9.*;
Arduino arduino;
int[] ledPin = {2,3,4}; // EL Escudo pinOuts start at A=2, B=3, etc.
float beat;


void setup() {
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[1], 57600);
  for(int i = 0;i<3;i++) {
    arduino.pinMode(ledPin[i], Arduino.OUTPUT);
  }
  
  size(200,200);
  frameRate(30);
  // change beat value or input volume if beat isn't accurate, or maybe your sample does not have a clear enough beat
  beat = 0.03; 
  
  Sonia.start(this);
  // Start listening to the microphone
  LiveInput.start(); 
}


void draw() {
  float level = LiveInput.getLevel();
  if(level > beat) {
     blink();
  }
}


void blink() {
  for(int i = 0;i<ledPin.length;i++) {
    arduino.digitalWrite(ledPin[i], Arduino.HIGH);
  }
  delay(100);
  for(int i = 0;i<ledPin.length;i++) {
    arduino.digitalWrite(ledPin[i], Arduino.LOW);
  }
  delay(100);
}


// Close the sound engine
public void stop() {
  Sonia.stop();
  super.stop();
}

Thursday, July 12, 2012

Configurations, Starting Applications, Current Working Directory

On starting up my Raspberry Pi today I found that my keyboard layout was set back to British, so I will have to find out how to permanently set that. No time right now, though. I did try starting Midori from the command line, which I found, obviously, required the X GUI to be started up. LXTerminal hangs on that command as long as Midori is running so I will have to learn about how to allow it to move on once the target program is running.
What I wanted to learn today I did learn, which is how to know where I am when the GUI is not running. This is not something you really know even with the GUI but the graphical illusion of a desktop gives you the feeling you are somewhere. So on the command line it helps to type 'pwd' to know your current working directory and 'ls' to know what directories and files are in your current location.

Wednesday, July 11, 2012

Changing Keyboard Layout in Linux

Here's my learning for today, although I learned a lot just getting a picture on here and uploading it. (Once I added a USB hub it was a snap.) Open the LXTerminal and type setxkbmap -layout us. The LXTerminal is pretty fancy in that you can even get a right click menu on it (to copy from and to).

Here's my source: http://how-to.linuxcareer.com/linux-command-line-basics-for-beginners-part-3

Raspberry Pi Photos

We'll see if a photo attachment is automatically inserted into a blog post when sent as an email...

Raspberry Pi!

I have a Raspberry Pi! I have a lot to learn as I am barely familiar with Linux at all. But I've decided to learn 1 simple thing a day on it and blog what I learn. My goal for today, for example, is to find out how to change the keyboard mode from UK to EN! I know there is a command for that. (There's an app for that...) Eventually I will set it up in my school's library for students to use it and learn what they can do with it. It is exciting because in this age where computers are ubiquitous black box proprietary devices kids need to also see them as things to tinker with and learn to control in ways they want.

Hmm, how to get a photo I took of the Raspi on here to upload...

Wow, even more challenging than getting a photo on here it seems is getting Midori to handle publishing or saving a post with the blogger platform. It did warn me that there might be problems.

Ok, so I'm emailing it to the blog. I have to use my Outlook Web App account since my gmail account won't work in Midori either. Now, just for the record I don't have a problem with all of these hurdles. To me it's an indication of how sophisticated and at the same time inaccessible the software is that we have come to depend on day-to-day.