Recent Changes - Search:

Syllabus & Assignments

Notes & Journals

Projects

More Intro Pages


Notes8

Serial Communication

Serial Communication is when data gets transmitted one bit after another. It used to be that Parallel communication was much faster, which is why computers had "parallel ports” to do data-dense operations like printing. Serial communication is dependent on processor speed, and, since processor speeds have increased so dramatically, serial communication styles like USB have been able to take over those same jobs.

Synchronous

Synchronous Serial basically means that there is one clock controlling the interaction. A “master” circuit beats out a measure over out a clock pin. Each bit gets shifted on either the rising or falling edge of that clock stroke. This is frequently referred to as shifting the data bits.

An example of this would be shift registers.

An example of this kind of protocol is SPI (Serial Peripheral Interface) also referred to by the brand name “Microwire.” The pins defined are usually MISO (Master In Slave Out), MOSI (Master Out Slave In) and SCK (Serial Clock)

More info:

Asynchronous

Asynchronous communication is what we’ve been doing with the Serial.begin() function, etc. Asynchronous serial communication means that each item has its own internal speed (we have a 20 Mhz clock Crystal on the Arduino Board, the average Mac is, well, faster) but they have an agreed upon data-rate at which they are talking. We’ve been setting it at 9600 bps (bits per second). This value is frequently referred to by the not quite technically precise term baud rate.

An example of asyncronous serial communication is SCI (Serial Communications Interface)

More Info:

Making Connections

When trying to make that initial connection between devices you need to track the

  • physical connections match up (do you plugs fit? do you have common ground, the right RX ->TX line up? )
  • your voltages match up (that logic 0 = GND and logic 1 = 5V on both or that you have some kind of translation going on)
  • that your timing matches (that your send bps is what your listener is expecting)
  • that your number of device connections are sorted
    • Point-to-Point: SMS
    • Multidrop: Chatroom / Party conversations

Some physical layer electrical specifications

ProtocolLow VHigh VCommon RatePointsCommon connectors
TTL - Transistor-Transistor Logic0V3.3V/5V9600 bpspoint-to-pointD-Subminature (DE-9)
RS-232-12V12V9600 bps (<20,000 bps)point-to-pointD-Subminature (DE-9) also DB-25, Modular Connectors / Registered Jacks - 8P8C / RJ-45, 10P10 / RJ-50
RS-485-10V10V<10Mbpsmulti-dropD-Subminature (DE-9) also DB-25, Modular Connectors / Registered Jacks - 8P8C / RJ-45, 10P10 / RJ-50
MIDI - Musical Instrument Digital Interface0V5V31,250 bpsMulti-drop5-pin DIN connectors, 15 pin D-Sub, USB
USB0.0–0.3 volts2.8–3.6 voltsLow 1.5Mbps, High up to 480 Mbpspoint-to-pointUSB
Ethernet (10BASE-T)0V3.3V?10Mbpsmulti-drop8P8C Modular Connector (Registered Jack 45, RJ-45) Twisted-Pair cable

More info and sources:

TTL <-> RS232

Focus on Midi

Midi is both a physical connection type and an established language used by musicians to electronics. The lab will give you a basic overview of how to turn on and off a single note, but you can take an entire class on mastering the whole language.

If you don't know how to get midi into your computer already, you should just get a midi-controller out of the equipment room and a set of speakers or headphones and play around.

Just so you have some pointers to get started, when you send a MIDI command you are always going to send at least 2 bytes.

The first byte contains the specific action to perform and is called the status byte. It will contain information about what you want to do (start or stop a note) and which of the 15 channels you want to do it on. It is that channel aspect that makes MIDI a multidrop protocol. Status bytes alway contain a value 128 or above.

So, for example, 0x80, 0x81, 0x82...0x8F will turn notes off on the various channels; 0x90, 0x91, 0x92...0x9F will turn notes on; 0xC0, 0xC1, 0xC2...0xCF will execute a program change, i.e. change the instrument based on what is loaded on your specific synthesizer. There is a nice chart on page 308 of the book and on the blueink.com link below.

Once you know what action you want to do you have to specify certain parameters like you already do in some functions in Processing and Arduino. The MIDI Note On command takes the note value (chart is in decimal) and velocity of strike. This isn't quite volume. It is what the intrument would sound like struck at higher velocity, which could be louder, but could have other distortion as well depending on the how that instument is programed. These parameters or data bytes, are always 127 or less. Check out the lab for an example of sending this command. You'll notice that you can send a Note On command with a "zero velocity" to a note playing on a particular channel to stop it instead of sending a stop command.

Not in the lab but a nice extra: to change channel 1 to steel-string acoustic you would send 0xC0 0x1A (192 26 in Decimal) to create a marimba accompaniment on channel 2 it would be 0xC1 0xD (193 13). There is an instrument list on wikipedia here: http://en.wikipedia.org/wiki/General_MIDI

One more thing to remind you about from chapter 12 is the very useful 0x7B databyte that when sent after the stop command (0xB0 - 0xBF) will just halt everything on that channel. So 0xB0 0x7B stops everything on channel 1 (pg. 309)

Have fun!

The overviews

More Information

Some projects

Some Example Code w/ Program Change (based on lab code)

// Variables: 
char note = 0;            // The MIDI note value to be played

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
  delay(500);
//Intrument on Channel X (0xCX) to Instrument in second value
// this is a acoustic guitar and a bass sax
  programChange(0xC1, 0x1A);
  programChange(0xC2, 0x43);
}

void loop() {
  // play notes from F#-0 (30) to F#-5 (90):
  for (note = 30; note < 90; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    // this delay creates spacing that helps make the fact that 
    // there are different instruments more clear
    delay(100);
    //Note on channel 2 (0x91), some note value a bit higher than the other
    //middle velocity (0x45):
    noteOn(0x91, (note+4), 0x45);
    delay(100);
    //Note on channel 3 (0x92), some note value a bit higher than the other two
    //middle velocity (0x45):
    noteOn(0x92, (note+8), 0x45);
    //hold
    delay(1000);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);   
    //repeat for other two notes, too
    // comment these lines out to hear the difference!
    noteOn(0x91, (note+4), 0x00);
    noteOn(0x92, (note+8), 0x00);
    delay(100);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(char cmd, char data1, char data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

void programChange(char cmd, char data1) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
}

Edit - History - Print - Recent Changes - Search
Page last modified on November 03, 2006, at 05:42 PM