heathsmith
Posts: 16
Joined: Mon Jun 24, 2013 2:20 pm

I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jul 31, 2013 6:53 pm

So I thought this might belong in the beginners forum, but figure it could probably fit here as well.

Is there a general over-view of these different protocols (or whatever they're called) somewhere?

Like what's the difference between each one? What are they best at? What do they suck at? Why would I want to use one vs. the other? What's the easiest one to implement, what's the hardest?

Stuff like that.

Thanks.

Hugo2310
Posts: 4
Joined: Tue Mar 19, 2013 9:20 am

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Tue Aug 06, 2013 12:20 pm

maybe u get an overview here
gpio is general purpose input output, because u have these on the rPi u can use the other protocols.

http://electronics.stackexchange.com/qu ... -how-do-th

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Aug 07, 2013 4:25 pm

In the Raspberry Pi world, the way it boils down is like this:

I2C - Easiest and most expandable bus. Raspberry has two I2C buses, bus 0 and bus 1. Capable of expanding the Rpi to thousands of output ports. Programming is very easy.

SPI - Only 2 chip select lines so max number of devices is very limited. Bus is faster and can be driven over longer cable runs than I2C. Programming more difficult. Device selection very limited unless you are willing to solder SMD.

UART (RS-232) - Welcome to the 1970s. Lever shifters are a must. No intelligence at all. Pretty boring stuff actually.

GPIO - Good for turning on/off a few I-O ports. If all that is needed is control of a solid state relay or two for example, this is it. You could bit bang I2C or SPI but why would you when real I2C or SPI is available?
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
joan
Posts: 14949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Aug 07, 2013 4:42 pm

Depends on the device with which you wish to communicate.

If it only supports SPI, use SPI.
If it only supports I2C, use I2C.
If it only supports serial, use serial.
Otherwise use gpio.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Aug 07, 2013 6:18 pm

The road to interfacing is one of logical progression. The simplest is GPIO using a single pin or two is what most start off using. The next step is I2C and then finally SPI. I do not mention UART (RS-232) because it is such a dead method of interfacing and there is no point in messing with it. I view I2C as RS-232 on steroids.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

ljwobker
Posts: 11
Joined: Tue Dec 31, 2013 2:18 am

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 01, 2014 5:25 pm

So I have what (I think) is a related question... I'm looking on adafruit and I see these two devices:

http://www.adafruit.com/products/661, which states: "The driver chip SSD1306, communicates via SPI only. 4 or 5 pins are required to communicate with the chip in the OLED display.

http://www.adafruit.com/products/931, which states: "The driver chip SSD1306, communicates via I2C only. 3 pins are required to communicate with the chip in the OLED display, two of which are I2C data/clock pins."

So I'm a little confused by a couple of things:
1) is this a typo of some variety? Or does the driver chip actually support both of these methods?
2) If it's indeed both, is there a clear advantage to using one versus the other?
3) my project involves using an IR/light sensor (http://www.adafruit.com/products/439) -- do I need to be concerned about "running out" of pins on the Pi? If so, could someone help me figure out which of these pins are interchangeable across the sensors, and which ones I might run out of?

Apologies for what is probably really simple, but my background is much more software than hardware -- so "pins" are things that you stick in voodoo dolls ;-)

User avatar
Burngate
Posts: 6310
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 01, 2014 5:59 pm

The chip (SSD1306) can use either SPI or I2C according to the datasheet http://www.adafruit.com/datasheets/SSD1306.pdf so it's the way the boards are laid out.

That light sensor uses I2C, so it would make sense to use the I2C version of the OLED display - that way only three wires need to be connected to the Pi, and go to both devices.
OR
That light sensor uses I2C, so it would make sense to use the SPI version of the OLED display - that way the sensor and the display are kept separate.

As for running out of GPIO pins - there are upto 17 GPIO pins available. I2C and SPI together use 7 (SDA, SCL, MOSI, MISO, SCLK, CE0, CE1) so you've got 10 more including the UART TX & RX.

Finally, for the education of software people, pins are the things that hurt when you tread on the Pi with bare feet.

ljwobker
Posts: 11
Joined: Tue Dec 31, 2013 2:18 am

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 01, 2014 11:31 pm

Burngate wrote:The chip (SSD1306) can use either SPI or I2C according to the datasheet http://www.adafruit.com/datasheets/SSD1306.pdf so it's the way the boards are laid out.

That light sensor uses I2C, so it would make sense to use the I2C version of the OLED display - that way only three wires need to be connected to the Pi, and go to both devices.
OR
That light sensor uses I2C, so it would make sense to use the SPI version of the OLED display - that way the sensor and the display are kept separate.
OK, this makes good sense. so i2c is shared across multiple devices (amazing what you can learn once you have the faintest idea of what to actually search for...) Putting both devices on the i2c clearly saves pins, but it's not clear to me at what point there is a disadvantage of doing this. Is it a function of how much data (transactions per second is the right term, or not?) you're transferring across the i2c bus?
As for running out of GPIO pins - there are upto 17 GPIO pins available. I2C and SPI together use 7 (SDA, SCL, MOSI, MISO, SCLK, CE0, CE1) so you've got 10 more including the UART TX & RX.

Finally, for the education of software people, pins are the things that hurt when you tread on the Pi with bare feet.
Love it. ;-)

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 01, 2014 11:35 pm

I2c == almost unlimited expansion capabilities, easy, almost everything can be done from the command line, programs can be written in almost any language. What's not to love?
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
DougieLawson
Posts: 39225
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 01, 2014 11:42 pm

Richard-TX wrote:I2c == almost unlimited expansion capabilities, easy, almost everything can be done from the command line, programs can be written in almost any language. What's not to love?
"Almost" being that there's a limit of 256 devices due to the I2C addressing scheme, with 7-bit I2C addressing that's reduced to 128 devices. Also assuming you don't get conflicts and have devices where the address can be chosen by the hardware (eg MCP23017).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Thu Jan 02, 2014 1:01 am

DougieLawson wrote:
Richard-TX wrote:I2c == almost unlimited expansion capabilities, easy, almost everything can be done from the command line, programs can be written in almost any language. What's not to love?
"Almost" being that there's a limit of 256 devices due to the I2C addressing scheme, with 7-bit I2C addressing that's reduced to 128 devices. Also assuming you don't get conflicts and have devices where the address can be chosen by the hardware (eg MCP23017).
Image the possibilities when adding eight PCA9547 8 channel muxes to the I2C bus. Now add thirty two 16 channel PCA9685 on each of those 64 buses. 32*64*16=32768 channels. Since the Rpi has two I2c buses, the total number of channels is 65,535.

Now we move to standard port expanders. Assuming a MCP23017, the total number of I-O ports for a Rpi with 8 muxes is 8 chips*64 buses*16 ports or 8192* 2 I2c devices for a total of 16,384 i-o ports. Then you could add ADCs, clocks, eeproms, crossbar switches, etc etc.

So if 65,535 outputs and 16,384 input/outputs (81,919 total) ports aren't enough, then it is time to buy another $35 Rpi.

Like I said, almost unlimited (>80,000)
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

toxibunny
Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Thu Jan 02, 2014 4:53 am

UART is friendly and welcoming. Stop hatin' on UART, y'all :(
note: I may or may not know what I'm talking about...

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Thu Jan 02, 2014 8:21 am

toxibunny wrote:UART is friendly and welcoming. Stop hatin' on UART, y'all :(
No one is hating the UART. I can put 4 dual UART chips (SC16IS752IBS) on a single I2C bus So the max for a Rpi without Muxes is 16 uarts. Using 8 channel Muxes , I can get 64 buses *8 uarts*2 native buses or a maximum of 1024 of them on a Rpi :D

http://www.nxp.com/documents/data_sheet ... 6IS762.pdf
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

milhead
Posts: 2
Joined: Tue Apr 15, 2014 4:46 pm

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Tue Apr 15, 2014 4:52 pm

Hello Richard,

Do you know if the pi recognize the SC16IS752 dual UART?

I have an application where I want to listen to a couple simple 3.3V serial signals.. We already use a Pi with a I2C-RTC and a 2 line display on our units..

If I could add some UARTs that would propagate to TTY devices by the OS it would be a big step forward from where I am today..

I've been flipping through the linux source looking for possibilities but yet don't have any success.

Miller

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Tue Apr 15, 2014 8:12 pm

The Pi will not recognize any added I2C connected uarts in the traditional fashion. For that to happen a device driver will have to be written,
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Killertechno
Posts: 205
Joined: Wed Jan 02, 2013 8:28 am

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 14, 2015 10:09 am

Hi guys, I have a doubt about GPIOs.....

If I'll need more GPIO pins, is there a way I can "turn off" peripheral (such PWM or I2C or other) and use that pins as simple GPIO pin?
Thanks.

User avatar
joan
Posts: 14949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C vs GPIO vs UART vs SPI - Super Noob Question

Wed Jan 14, 2015 10:11 am

Yes, just set it as an input or an output. One proviso, be aware that pins 3 and 5 have hard wired 1k8 pull-ups to 3V3.

Return to “Interfacing (DSI, CSI, I2C, etc.)”