Tuesday, August 14, 2012

Raspberry Pi in the Classroom


I posted this today on an ed tech listserv and figured it's worth getting out here, too.

The Raspberry Pi is ready for prime time in the sense that the one-per-order restriction has been lifted and you can now purchase as many as you want. I've been tinkering with one this summer and I keep coming back to the question of what will we do with them in our schools. I think it's an urgent question which I'll explain as I go (sorry for the tl;dr).
The Raspberry Pi is a $35 computer. $35! (The one with only 1 USB port and no Ethernet is $25!) It's the size of a bar of soap. It comes with no case (yet); you have to make one. No I/O devices, just a board and ports. That number still doesn't compute for me, but consider how many you could get for an iPad. But you might say well then you have to get a monitor, keyboard, and mouse, at least. Actually, all you really need are a power supply (mine runs on a Blackberry charger, even 4 AA batteries will work), an SD card (the only storage!), and a network connection-either Ethernet or several wireless adapters will work. Then what? It's Linux, so you can hook it up to a monitor and keyboard just to enable SSH and create a few accounts and tunnel in from any computer on your network. And besides, the educational value of an iPad lies in all the apps you have to purchase, not to mention the time and expense of setting up an infrastructure that makes collective use feasible.
But cost is somewhat beside the point. Well, though, certainly not for public schools or cash-strapped independent schools. The main point is that it is nothing like the experience of an iPad, in fact it's the antithesis, and a sorely needed one, which is really the point made by the Raspberry Pi Foundation. Where the iPad (sorry, I really mean all proprietary devices) should work out of the box, you must hack your world and the Raspi just to make it work (hmm, i have to buy a charger...do I have any 5v chargers around? How do I know if it's 5v? wait I don’t have enough USB ports for a mouse, keyboard, and wifi adapter…ok a non-powered USB hub won’t work but a powered one will, why is that? Oh, there’s some help here, http://elinux.org/RPi_VerifiedPeripherals#Working_USB_Hubs, …now, a monitor, what, no VGA? Wait, I can plug it right into my 64” TV?!? And it looks awesome! etc, etc). Where the iPad wants you to think you don’t need to know anything about computers to use it, the Raspi forces you to learn just to get it to do anything. I didn’t know anything about Linux before I got this and now Linux is blowing my mind. I’m realizing the power, control, and options you can have with a computer if it’s designed to let you have those. Combing Linux forums for basic information I’ve read so many answers to queries that start, “Well, here are 4 ways you could do that…”
So getting back to the question of what to do with this device I can see it doesn’t belong as a standard integrated device like the iPad is becoming or laptops have been. It’s all about getting back to the basics of computer science and even physical computing. It belongs as a standard device in these makerspaces we are talking about and developing. It can do anything you want it to, really (though running it as a media server at home was a bit more than it could handle with 256MB of memory on board). We need to be alongside interested students helping them think about what they want to do with it and then guiding them through the mind blowing experience of learning how to get Linux to do anything you want with the decades of crowdsourced information you can tap into out there. I can see coming up with some really creative applications and having people see it and say, “What, a computer can do that?!? Wait, that’s a computer?” It’s really akin to the Arduino, in fact people are figuring out how to get the two to work together (http://www.raspberrypi.org/archives/1171). Interesting side note, this link is to a post about some resentment on the part of some in the Arduino community and makes the point that the two are fundamentally different and in fact can work well together, and I realized in looking at the accompanying photo that that difference is represented in a striking way by looking at the USB ports, where one uses the host type A port and the other the target type B.
Anyway if you’ve read all this thank you and I would love to hear your thoughts. 

Friday, August 10, 2012

Hack Time Machine Backup with Linux

If you need to get your files out of a Time Machine backup but you don't have a Mac, look no further. Get a computer with Linux on it. I'm using Ubuntu 12.04 but mostly you will just need to use the standard Linux shell terminal. It will be a painful experience, but hopefully a few things I've learned will help ease the pain a bit.
I started with Carson Baker's very helpful blog post on this which draws the basic map very clearly and succinctly. I needed to do a little research to clarify what he meant by cd'ing to the /media/Time Machine/.HFS+ Private Directory Data folder because you can't just type that in the terminal and get anywhere. In his comments he explains the use of tab-completion, which is amazingly helpful to know about.
In my case I cd'ed to the root level of my external drive, then typed .H, hit tab, and the rest filled itself in. That's voila for you! You can see it does mess with the spacing on the terminal command line, overwriting itself. But you get used to it.
Following his directions to figure out the hard link codes I found my backed up Pictures folder, which contained a Shoebox folder, for the app I had been using to store photos. Inside that is a folder for each year I've been using it for photo storage.
Listing the folders I discovered a huge problem. The photos for 2012 were there but the other years were simply more hard links! I had to find their hidden directory codes and cd to their folders. One thing I did to make the task a little easier is to write those codes to a file: ls -ls > /home/usr/Desktop/dirs.txt.
Looking further into the sub-folders for each year, my next problem was some contained a mixture of actual folders and hard links, which I had to get codes for, etc.
The above was the result of listing the contents of 2011, the folders being the months. So I needed to write those to a file for reference.
What a mess. Now the intact folders could be copied directly over very easily:
cp -rv . /home/usr/Pictures/2011. The copied hard links had to be deleted: rm -v /home/usr/Pictures/2011/01, etc.
Now one more level down are the folders for each day there were pictures. Inside those are the actual image files. These were also mixed folders and hard links. Rather than going through these one by one, finding the code, copying each day's folder, I made a script to automate at least this part. It creates the directories in the target drive for each missing folder (represented by a hard link), cd's to the coded directory for each, and copies the pictures over. All of that data has to be hard coded so that's a pain, but here's what it looked like.
The folders for July, 2011 looked like the above. Only 2 folders could be copied straight over. I saved the long form data to a text file: ls -ls > /home/usr/Desktop/dirs.txt.
That revealed the codes for each missing folder. I used that to write the following script and run it from the terminal in the top level of the .HFS+ Private Directory Data folder.
When it's moving all those files it's a beautiful thing to see, but it sure is a pain to create.

Saturday, August 04, 2012

RasPi Wi-Fi

I looked on this list of working wifi adapters for one to try out and found the Linksys WUSB100 adapter worked out of the box. I just had to add my network details to a config file as described at the bottom of this blog post. Now the problem is I need a powered USB hub to get enough juice to my keyboard, mouse, and wifi adapter. I can only plug in two at a time for now so I tried out text browsing the Internet with the command line browser Lynx. It's a different experience, cool!

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

video
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.

Sunday, April 29, 2012

LED Driver project, work in progress

I've been interested in the Arduino for a while now and played with it a little bit. Until now the most involved project I've done with it is playing around with variations on using it to program a web server with an ethernet shield. Well now I'm deep into something that is introducing me to the complexities involved in working a project up as a prototype with breadboards and then taking it to the next level by soldering components together on a generic PCB. I'm using a Philips 4794 LED driver to extend the Arduino's control of LEDs beyond the 8 or so it can control directly with pinouts. Actually I'm using 6 LED drivers to control 43 LEDs that spell out my son's name traced along his toddler version of his written name, bringing his early signature to life in a blinky way. To figure out the components and schematics I relied a lot on this post and this post, and then this post to extend to multiple LED drivers.
So, first the prototype:
 You can see here the Arduino (Duemilanove), breadboards, one LED driver, lots of leads.
And here the LEDs and the circuitry behind.








For programming I used the example in the first link above and changed the value associated with the count variable to include larger numbers of LEDs. I still don't really understand how the program works and ultimately I would like it to do something a little different than it does so I will have to figure that out later. But since that worked for 16 LEDs I started working on a more permanent version. That work in progress is below. There is a lot of soldering to do. By the time I finish, he will be in college:
All 6 LED drivers are soldered in and I tested the circuit to make sure my sloppy soldering
would work with one LED, which I was lucky enough to catch blinking for the camera.

Sloppy soldering...I will blame the cheap soldering iron until
I get a better one and will have no excuse.

Thursday, April 26, 2012

Build Your Own Computer

It's been a long time since I've written anything for no particular reason but being busy. But I recently had 20 high school girls in a class doing something I have to write about. As part of a day full of STEM activities in our high school I had a bunch of girls put together some old PC desktops we were planning to put out to pasture. It was a morning full of anticipation, exploration, frustration, and finally, pure exaltation. I provided scaffolding in the form of a Prezi they could explore  as they needed, gave them screw drivers, and pointed them towards the pile of parts. The best moments were booting up. With some false starts and reseated processors the Dell and Windows splashes started appearing on screens around the room and the girls yelled for joy. They were so excited and proud of their work.