SPI, i2c, and other serial communication methods - BleepLabs/Arduino-Light-And-Sound GitHub Wiki
SPI and I2C are digital communication techniques used to communicate will all kinds of devices.
We've been using I2C to setup the audio adapter and SPI to talk to SD cards without even knowing about it. If we want to communicate with other thing, like accelerometers, color sensors, screen, and may other deceives, there are a few things to keep in mind.
SPI
Uses a clock, data out, data in, and chip select pin.
All except the chip select pin can be shared between multiple devices. Only the chip select needs to be unique.
Most of the time you'll be able to find a library with info about how to communicate a specific device but you can see the most basic ways of using SPI in the two examples in File>examples>spi
The audio board uses the SPI1 pins for I2S communication (a specific type used for high speed audio) so you'll always need change the pins you're using and to put this in your setup. Chip select aka CS pins can be any pin.
SPI.setSCK(14); // Audio shield has SCK on pin 14
SPI.setMOSI(7); // Audio shield has MOSI on pin 7
I2C
Uses just two pins, bidirectional data and clock.
When setting up the audio adapter I2C is used to tell it what volume to be, what input to use etc. This doesn't mean you can use the pins for another I2C device though.
Unlike SPI, I2C uses addresses. Each device has a unique address that is usually selectable. For example this accelerometer has a pin that changes the address when grounded. You can attach it to the same pins 18 and 19 of the Teensy and the deices will know when to listen. Again you'll probably find a library to do the actual communication with the chip.
Serial / UART
SPI, I2C, USB and pretty much every other modern communication technique is serial. It just means one byte after another as opposed to parallel.
"Serial" in terms of the teensy or other micro controllers can more accurately be called UART. It is the most basic way of sending and receiving information. This is what MIDI and the serial monitor use. You probably won't come across it that much but it can be useful when you want to communicate between two Arduino devices.
I2S
Used for communication with audio codecs. It's what's taking up most of the pins of the Teensy when using the audio adapter. It's much more complex than the other but luckily it's all been taken care of for us!