Thursday, April 20, 2006

sog #3 - fun and education

So, some people who might someday be given a link to this blog know that I am a big advocate of "no curriculum" education. What this basically means is that students are left to pursue their own interests, and learn basic skills such as reading, writing through these pursuits.

I volunteer everyweek (well, it's supposed to be every week) helping teens use technology in the Lower East Side. The place is pretty cool, there's a recording studio for kids to make CDs, video editing materials and lots of art supplies. Mostly I help the kids to design web pages and create art using Photoshop.

One kid I helped, NJ, has what is apparently a pretty severe learning disability. Although he is 13, he can't really spell and has trouble reading. I was helping him to create a piece of Photoshop "art" a couple of weeks ago, and went through an interesting thought journey.

It started off with NJ wanting to take a picture of himself and make it look like he was drinking beer. Although I didn't think this was necessarily the most appropriate image to create, he was really insistent that this is what he wanted to make. In his words "What, you don't think my momma let's me drink beer?" How could I argue with that?

So, we began looking for pictures of beer on the internet. NJ got onto Google images and proceeded to ask me how to spell "beer". I was a flabbergasted but told him. As he typed it in and looked through the resulting images, I couldn't help thinking to myself "Why am I helping him use Photoshop? This kid needs to learn to read, not create images of him getting drunk." He found the image he wanted to use and downloaded it to his desktop.

Then we began using Photoshop. NJ wanted to cut himself out of a photo he took so he could superimpose himself on an image of a night club. We went through that process, and at one point I told him to copy and paste what he had selected. He asked me how to copy, and I told him the copy command was in the Edit menu. He asked me where the Edit menu was; I started to point to it but then stopped myself.

"NJ, how do you spell edit?" He replied that he didn't know.

"Well, what do you think the first letter is?" He sounded 'edit' out to himself and then replied "e?" with a very questioning note in his voice. I told him that was right and we repeated the procedure until he had figured out how to spell Edit. Then after he went to the Edit menu, we started all over again with the word "copy". And then "paste". Over and over, for every different menu command, and every different Google search that he needed to do.

Eventually, he completed his image of him holding a 40 floating on top of a very abstract background. He was really excited and printed it out to show his friends. His friends teased him about not letting the cops see it. I think NJ has a lot of trouble relating to the other kids his age normally and he was really happy to interact with them like this.

So, in the end, NJ got to create something he was really excited about. His desire for peer approval made him push through the difficulties he had with spelling and reading; he had a goal. I think this goal helped him learn a lot more than if he had just been reading a story that had no relevance to him.

I stand by my theory of throwing curriculum out the window.

Wednesday, March 01, 2006

sog #2 - midi input with PIC

Here's some information about my recent attempts to get MIDI input to work with a PIC microcontroller. It took me a long time to get this to work correctly; info published on the net seems to focus much more heavily on MIDI output than on MIDI input. So hopefully this can help some people out in the future.

Here is a schematic for both input and output that is currently available on the web:

midi input and output schematics

We'll only be looking at the top circuit, which is MIDI input. Here is my breadboard of that top circuit:

midi input circuit on breadboard

A. The PIC 18F452, there's a good deal of info about this PIC floating around
B. A 20 Mhz powered osciallator. We'll come back to this.
C. An opto-isolator, part 6N138. This is used to prevent any one MIDI input from damaging others in a circuit. I've heard you can get by without using one of these, but I wasn't able to pull it off and also use terminal communication at the same time.
D. A zener diode, part 1N914
E. The ground from the MIDI input
F. The transmission feed from the MIDI input

The Oscillator


Let's talk about the osciallator (B) first. It's important to use a reasonably fast clock source in order to accomodate MIDI's 31250 baud transfer rate. I tried using a 20Mhz crystal coupled with 22 pf capacitors to generate this clock, but they wouldn't clock the PIC correctly at that high a speed; I read from one excellent source that 20 Mhz crystals don't work well on breadboards. A powered oscillator is just as easy to hook up anyways, and also frees up a pin on your PIC.

One other option is to use the PLL(Phase Locked Loop) feature of the PIC 18F452. This allows you to run at 4 times the speed of whatever crystal you are using. Since the PIC 18F452 runs at 40Mhz tops, if you get a 10Mhz crystal and enable PLL you should be able to run twice as fast as using the 20MHz oscillator usehere. I haven't tried it, but I know that projects at the midiBox site use this method.

When you program your PIC, make sure that your "External Clock" or "External Clock Input/Output" option is selected as the oscillator. It doesn't matter which one; EC allows you to use OSC2/CLK0 as clock output running at 1/4 speed; ECIO allows you to use that pin (RA6) as an extra input or output. I've included a fuse in the C code that selects EC automatically when the .hex file is loaded into your programmer.

The Opto-Isolator / MIDI input


There are eight pins on the isolator; only six are used. First, our MIDI input (F) is passing through a 220 ohm resistor and into the positive input of the opto-isolator(O-I). The ground from our MIDI Input (E) is connected to the negative input pin on the O-I. A diode is put in place between this two pins to make sure that current travels in the correct direction.

The other side of the O-I is more confusing, at least to me. Power enters the top pin, the bottom pin is grounded. There's a resistor placed between the top power pin and the second pin from the bottom, which is where the MIDI signal (travelling on the blue wire) is outputted from. I'm not quite sure why this is there, but I couldn't get it ot work without it, so so be it. The MIDI signal is then sent to the UART on the PIC, in this case RC7. It's easy to poll the UART for data without having to hang the chip waiting for it.

It's worth pointing out again that I've read the opto-isolator isn't strictly necessary. I was in fact able to get MIDI input going into the PIC without it. However, as soon as I hooked up another RS232 port on the chip so that I could monitor the data the PIC was receiving on a computer terminal, the MIDI no longer seemed to work correctly. Adding in the O-I fixed the problem. At least I think that was what fixed the problem...

Edit: I got a little more info about the opto-isolator from my father, who is an electrical engineer. Apparently it completely separates the input voltage from the output voltage. Information is sent from input to output using flashes of light as opposed to toggling electrical connections. In the above circuit diagram, pin 6 (the output pin) flips back and forth between being connected to pin 5 (the ground) and pin 8 (power). When it is flipped to ground (most likely when no light is being transmitted across the o-i) the current flows to the +5 input. The 270 ohm resistor prevents a short circuit in this event. When it is flipped to power, the signal flows to the microcontroller, as this is the path of least resistance (no 270 ohm resistor).

Miscellaneous


If you don't know how to use the Watchdog timer, make sure you turn it off. There's a fuse in the code below that turns it off automatically.

If you want to use a RS-232 connection to a computer terminal in addition to MIDI, make sure you send the ground connection of the RS-232 through a 22k resistor... otherwise it seems to interfere with the MIDI signal somehow.

The Code


This code was written for the CCS C compiler. When noteOn messages are received it will pin high on D0 (lighting up the LED in my breadboard picture). When noteOff messages are received it will pin low on D0, turning the LED off. This code only manipulates note messages, it ignores everything else. I made this code as simple as possible to just show the basic concepts; still it would be good if you knew a little bit about MIDI messages before looking at the code. There's a great link at the bottom of the article which will tell you more than you ever needed to know about MIDI.


/* Midi Input - 2006 Charlie Roberts - http://www.charlie-roberts.com
** Outputs high to a selected pin (D0) when a noteon MIDI message is received,
** outputs low to the pin when a noteoff message is received
**
** Written for the PIC 18F452 and the CCS C compiler
*/

#include<18F452.h>
#fuses EC, NOWDT
#use delay(clock=20000000)

#use rs232(stream=MIDI, baud=31250, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)

BYTE msg[3]; // an array that will hold store MIDI info until an entire three byte message is received
BYTE msgCheck; // use to check if we are dealing with note messages.
int count=0; // count the number of MIDI bytes received in the current message
int1 startTest=0; // have we started a note message yet?

void performMsg(); // turn pin D0 on or off based on type of MIDI message received


#int_RDA // this interrupt occurs whenever info is "RS232 (R) Data (D) is Available (A)"
void RxBytes() { // the function to be carried out when the intterupt occurs
msgCheck = fgetc(MIDI); // get the byte currently in the MIDI stream
if(count == 0 && msgCheck == 0x90) {
// if we have not started a message and this is the start byte of a note message
msg[0] = msgCheck; // store the byte in our msg array
count++; // update the count so that we know we have one byte of our message
startTest = 1; // we have started a new message
}else if (startTest == 1) {
msg[count] = msgCheck; // store the next byte
count++;
if (count == 3) { // ... then we have a complete MIDI note message
performMsg();
count = 0;
startTest = 0;
}
}
}

void performMsg() {
if (msg[2] != 0x00) { // if it is not a 0 velocity noteOff message
output_high(PIN_D0); // light the led on PIN_Do
}else{
output_low(PIN_D0); // turn the LED off
}
}

main() {
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
while(TRUE) {
// empty loop to keep program going
}
}


Suggested Links


http://www.borg.com/~jglatt
Excellent MIDI reference
http://tigoe.net/pcomp/midi.shtml
Information on Tom Igoe's site about MIDI I/O.

Wednesday, February 22, 2006

sog #1

We must quantify, quantify, quantify... A recent New York Times article (link at bottom) titled "Panel Explores Standardized Testing For Colleges" describes an attempt to standardize elements of college education. The Bush administration has appointed a panel to the examine possible assessments of writing, analytical skills and critical thinking for undergraduate college students.

Not all of the commisioners are named in the article, but the ones who are have me worried. Jonathan Grayer, one comissioner, is the chief executive of Kaplan Inc., a company that offers test preparation services. Hmmm... what interest could the CEO of a company that trains students to take standardized tests have in implementing standardized tests in colleges across the nation? I'm sure his opinion on the comission is very neutral.

But wait... these tests would be for assesment purposes only, right? Then the question becomes how to motivate students to actually perform well on the test. A "testing expert" at the National Center for Higher Education Management Systems in Colorado was quoted in the article as saying such tests need to be "embedded in the curriculum" for students to take them seriously.

Ahh... so if we connect the dots, the CEO of Kaplan is serving on a committee that will make recommendations about whether or not to apply standardized tests to assess the knowledge gained in college. These standardized tests need to be part of the curriculum for students to taken them seriously (I certainly wouldn't take them seriously otherwise). The next logical step is to make students grades somehow dependent on these tests. Maybe just for extra credit at first. But then later, as colleges are forced to compete with one another about the score results, suddenly the tests loom large over the undergraduate curriculum. That's when Kaplan steps in and offers up their services for students who are stressed out (yet again) over the prospect of filling in tiny bubbles in order to assess their knowledge.

Diabolical.

http://www.nytimes.com/2006/02/09/education/09testing.html?ex=1140757200&en=fc750cf83bb47269&ei=5070