https://elinux.org/api.php?action=feedcontributions&user=MattHawkinsUK&feedformat=atomeLinux.org - User contributions [en]2024-03-28T23:36:08ZUser contributionsMediaWiki 1.31.0https://elinux.org/index.php?title=RPi_Expansion_Boards&diff=214484RPi Expansion Boards2013-01-28T13:38:38Z<p>MattHawkinsUK: Added BerryClip addon board.</p>
<hr />
<div>[[Category: RaspberryPi]]<br />
{{Template:RPi_Hardware}}<br />
<br />
<br />
==Introduction==<br />
On the Raspberry Pi, there are several connections which can be used for expansion:<br />
* The [[RPi Low-level peripherals|Rpi GPIO]] (General Purpose Input/Output) pins are exposed, that means that expansion boards are able to talk directly to the CPU.<br />
* The DSI connector will allow low-level interfacing with LCDs and other displays.<br />
* The CSI connector will allow camera modules to be added in future.<br />
<br />
==Current expansion boards==<br />
<br />
=== AFLEX Robotic Board ===<br />
[http://www.web4robot.com AFLEX Robotic Board] is dual motor control and data acquisition board with I2C and Serial interfaces. The board provides 2 motor control drivers with max current up to 3.5A, 8-bits data port with each pin setup as digital input /output or analog input, 10-bits ADC with up to 5 analog channels, 4 inputs for the sensor connections, infrared (IR) remote control. The board provides direct connection to Raspberry Pi.<br />
<br />
=== ADC Pi, Delta Sigma Pi and RTC Pi===<br />
ADC Pi from AB Electronics UK brings 8 channel 15 bit analogue sampling to the Raspberry Pi platform. A buffered 5V i2c bus and stackable headers make this a useful addition to your Raspberry Pi project. The Delta Sigma Pi is a 18 bit Delta Sigma ADC board with 8 inputs, a buffered 5V i2c bus and stackable headers. The RTC Pi is a Real Time Clock module with a buffered 5V i2c bus and stackable headers.<br />
http://www.abelectronics.co.uk/default.aspx (see also: [[RPi_ADC_I2C_Python|setup tutorial]])<br />
<br />
=== Arduino Shield and Raspberry Pi ===<br />
a little board with Arduino socket and Raspberry Pi socket<br />
you can power the boards with 12Volt or 5Volt<br />
http://www.progetti-hw-sw.it/raspberry.htm<br />
<br />
===Buffer Board===<br />
[http://www.thebox.myzen.co.uk/Raspberry/Buffer_Board.html Buffer Board] How to make a Pi Buffer on Veroboard. Each of the 14 outputs can drive up to 500mA using a Darlington array.<br />
<br />
=== Buzzberry Buzz-Board Interface ===<br />
[http://fortito.com Buzzberry] is an interface board enabling expansion using the Buzz-Board modular system designed primarily for educational use.<br />
<br />
===CJE/4D RTC===<br />
On 2nd January 2012, CJE/4D announced that they have a real-time clock (RTC) expansion board in the works: [http://www.raspberrypi.org/forum/features-and-requests/rtc]<br />
<br />
===GertBoard===<br />
::''main page: [[RPi Gertboard]]''<br />
This board is a buffer between your Rpi and the real world, use it to flash LEDs on and off, drive motors, run sensors and all that other fun stuff.<ref>http://www.raspberrypi.org/archives/411</ref><br />
<br />
===GELI 'jelly'(GPIO Experimenter and Lab Interface Board)===<br />
[http://www.fulburncams.gb.net/ Raspberry Geli Board] Extends the GPIO and provides I2C, D2A/A2D, DC Motor(L298), RS232, Realtime Clock (DS1307), 1-wire and prototyping area on 150 * 100mmm PCB.<br />
<br />
=== GPIO isolated expansion/RTC ===<br />
[http://www.utelectronics.com UT Electronics] is developing a expansion board containing a fully isolated 16-I/O I2C GPIO expander and RTC, with extensive options for further expansion. C and Python libraries will be available at launch. The board will probably be sold as a kit, with SMT components already in place.<br />
<br />
Update: According to their website, the realities of life prevent them from bringing the product to market. They are hoping someone will pick up the ball. They have released the PCB layout and all documentation for free on their website.<br />
<br />
=== Heber x10i ===<br />
[http://www.heber.co.uk/gaming-amusement/xline/x10i-overview/ Heber Ltd] X10i integrates real time I/O into a RPi control system. A secure real-time controller that permits control over multiple and different types of inputs and outputs, and uses the USB 2.0 communication standard. It is an all in one plug and play board for developing LED drivers, control, sensing of different switches, and driving stepper motors. Exclusive features include a real time clock, battery backed static ram, a Dallas chip (for unique board identification), 2 serial communication ports, a powerful audio amp and a independent dedicated on board processor.<br />
<br />
Heber now offers drivers in C/C++ and Linux to make it even easier for programmers, inventors and developers to connect with the outside world using X10i and their Raspberry Pi.<br />
<br />
=== aLaMode ===<br />
[http://wyolum.com/?p=824 “À la mode”] is an Arduino clone specifically designed to interface with the Raspberry Pi. You can of course connect a standard Arduino to a Pi USB port using a cord, but when you want a turnkey solution, how about an Arduino compatible “plate” (shield) that fits right on top of the Raspberry Pi with direct access to GPIO port? The Linux side handles all of the displays, human interfaces, and number crunching. The low power Arduino compatible “à la mode” board handles sensors, servos/motors, and provides a highly accurate real time clock.<br />
<br />
=== LedBorg ===<br />
[http://www.piborg.org/ledborg LedBorg] is an ultra bright RGB LED add on board for your Raspberry Pi. Capable of 27 colour combinations and controllable from either a GUI or the command line, it can also perform patterns.<br />
Small board which connects directly to the GPIO header.<br />
<br />
=== Paper-Duino-Pi ===<br />
[http://www.paperpcb.dernulleffekt.de/doku.php?id=raspberry_boards:paperduinopi Paper-Duino-Pi] is an Arduino shield for the Raspberry Pi. Due to the fact that it is designed as Paper-PCB it is easy to create and one doesn't need a printed circuit board. All components are cheap standard electronic parts. [http://youtu.be/e-x_ZPg8ymo A video is found here].<br />
<br />
=== PiBorg ===<br />
[http://www.piborg.org PiBorg] is a Robotics add on board which adds the ability to control motors - from small to large (including DC motors, Stepper motors, BLDC motors and Solenoids) from your Raspberry Pi. It supports feedback via Encoders and Potentiometers, allowing closed loop (servo) control of motors to set positions, velocities and accelerations and it is capable of monitoring drive current and voltages. The loop is PID based and as PiBorg is an [http://sourceforge.net/p/piborg/wiki/Home/ Open Source project], you may change the code as you please. It has the ability to drive 10A motors and more, so you'll never be left underpowered with this board!<br />
<br />
=== Pi Crust ===<br />
[http://picru.st picru.st] is a very compact and cheap breakout board for your Raspberry Pi that allows easy access to the Pi's pins, grouping them into a logical order and adding clear labeling. Small and simple.<br />
<br />
===Piface===<br />
[http://piface.openlx.org.uk Piface] is simpler than the [[RPi Gertboard]] (it's aimed at less experienced users), but also intended to connect to PCs and Android to be platform agnostic<br />
<br />
===Pi232 RS232 board===<br />
[http://www.logicethos.com/Blog/2012-06-21:_Pi232_Raspberry_Pi_RS232_boards Pi232] is an RS232 expansion board that plugs onto GPIO connector.<br />
<br />
=== PiDuino ===<br />
[http://www.youtube.com/watch?v=u5c1Dfaf57g Youtube video] showing prototype board<br />
<br />
=== Pi Plates ===<br />
[http://www.adafruit.com Adafruit Industries] announced in March 2012 the intention of making expansion boards for the Raspberry Pi under the "Pi Plate" name.<ref><br />
http://www.adafruit.com/blog/2012/03/14/adafruit-experimenting-with-pi-plates-for-raspberry_pi-shields-for-the-raspberry-pi/</ref>.<br />
<br />
The first board available is a [http://adafruit.com/products/801 prototyping board] that overlays the Raspberry Pi via a long plug-in header. It has screw terminals for all the Pi [[GPIO]] lines.<br />
<br />
=== PiPLUS Multifunction I/O Extension Board ===<br />
[http://www.web4robot.com PiPLUS Multifunction I/O Extension Board] is designed as versatile, general-purpose data acquisition and control module.<br />
Key Features: Battery-backed Real Time Clock; 3.5A DC motor driver chip; 8-bits digital I/O Data Port; 10-bits ADC with 4 analog channels; DAC; 4 high power outputs; 4 PWM outputs; IR Remote Control input; 2 user's buttons; AVR ATMEGA328P microcontroller with a preloaded Arduino bootloader and Arduino Shields connectors; 3V - 5V buffers for I2C, SPI and Serial interfaces; Power supply with 5V and 3V regulators.<br />
<br />
PiPLUS board also works as a bridge between Raspberry Pi and ARDUINO and provides a direct connection to Arduino Shields. You can use the standard ARDUINO environment and graphical interface for Windows or Linux for software development and ATMEGA328P microcontroller programming.<br />
<br />
=== Pi Tin ===<br />
Not yet tested, comments welcome<br />
Project files for Eagle here: [http://www.delong.com/Raspbery%20PI/]<br />
Schematic and Board images: [http://elinux.org/File:PiTin_Schematic.png] [http://elinux.org/File:PiTin_Boardpng.png]<br />
This board uses Microchip 16-pin GPIO expanders driven by SPI to provide up to 256 additional GPIO pins at a very low cost. Optionally, it can supply power<br />
for the board and the Raspberry PI.<br />
<br />
The board can be made in a stackable manner allowing you to also place additional peripherals on the GPIO connector. It makes non-exclusive use of all<br />
four SPI pins as well as exclusive use of the CE0 Pin.<br />
<br />
If you install (and power) the power supply components, the board will supply up to 1A at 5VDC. This is not enough to power all GPIO pins on a fully populated board, but in most applications should be sufficient to power the RPI and a reasonable number of GPIOs. An external power supply should be used for higher-power applications. This board should never be powered from the RPI as even one of the chips can draw more than the RPI can provide.<br />
<br />
The power supply is quite flexible and will accept anything from 8-25VAC or 8-42VDC. It is based on a Recom module which provides a switching power supply in a form factor that is a drop-in replacement for 7805 series TO-220 linear regulators.<br />
<br />
The 8 chips can be had for about $4@ or less and the power supply components total about $15. A fully populated board is about $49+PCB, $31+PCB for 64 GPIO pins.<br />
<br />
You can have the PCB made at a variety of fabricators. [http://batchpcb.com] does very nice work and is hobbyist friendly at very reasonable prices.<br />
<br />
===Pi-Wire===<br />
[http://go.je/18z Pi-Wire] Homelabs are developing options for connection of a 1-wire bus to the RaspberryPi. Boards include SPI breakout connections for future boards.<br />
<br />
=== Ponte ===<br />
[http://omer.me/2012/05/introducing-ponte/ PONTE initial post] An arduino shield bridge from Omer and SKPang<br />
<br />
=== Quick2Wire GPIO Expansion Board ===<br />
[http://quick2wire.com Quick2Wire GPIO board and experimenters kit] is an extension board for the Raspberry Pi that has level converters to allow the driving of TTL and real world devices such as LED's and switches. It will also provide an experimenters kit, a software framework and a number of tutorials.<br />
<br />
=== Raspberry Pi IO Interface ===<br />
[http://dangerousprototypes.com/forum/viewtopic.php?f=56&t=3996 forum thread] showing 'paper mockup'. Another buffered IO expander.<br />
<br />
=== Raspberry Pi to Arduino Shields Connection Bridge ===<br />
[http://www.cooking-hacks.com/index.php/documentation/tutorials/raspberry-pi-to-arduino-shields-connection-bridge Raspberry Pi to Arduino Shields Connection Bridge] allows you to use any of the shields, boards and modules designed for Arduino in Raspberry Pi. It includes also the possibility of connecting digital and analog sensors, using the same pinout of Arduino but with the power and capabilities of Raspberry. Using arduPi library, you will be able to make programs in Raspberry with the same code used in Arduino. To do so, Cooking Hacks Team have implemented conversion functions so that you can control in the same way as in Arduino all the I/O interfaces: i2C, SPI, UART, analog, digital, in Raspberry Pi.<br />
<br />
=== Relay board and Raspberry Pi GPIO ===<br />
a board with 8 relays and 8 input with a Raspberry Pi socket<br />
you can power the boards with 12Volt, the board has a DIN rail container<br />
http://www.progetti-hw-sw.it/raspberry.htm<br />
<br />
=== MiniPiio L293D ===<br />
[http://zuzebox.wordpress.com/2012/09/07/minipiio-l293d-board-v0-10/] is a small (50x40mm) add-on board which provides a dual H-Bridge DC-Motor circuit using the venerable L293D chip.<br />
<br />
=== MiniPiio Relay2 ===<br />
[http://zuzebox.wordpress.com/2012/09/07/minipiio-relay2-board-v0-10/] is a small (50x40mm) add-on board which provides a two 1A DPCO Relays. Each relay has a set of screw terminals for easy wiring.<br />
<br />
=== MiniPiio DIO16 ===<br />
[http://zuzebox.wordpress.com/2012/06/24/minipiio-dio16-v0-10/ MiniPiio DIO16] is a small (50x40mm) add-on board which provides an additional 16-channels of Digital Input/Outputs for the RPi. It can use either a MCP23S17 (SPI) or MCP23017 (I2C) Port Expander.<br />
<br />
=== MiniPiio RS232 ===<br />
[http://zuzebox.wordpress.com/2012/06/24/minipiio-rs232-v0-10/ MiniPiio RS232] is a small (50x40mm) add-on board which provides a basic RS232 to TTL interface for the RPi. It uses a 3.3V MAX3232 to provide the RS232 interface.<br />
<br />
=== MiniPiio ULN2803 ===<br />
[http://zuzebox.wordpress.com/2012/06/24/minipiio-uln2803-v0-10/ MiniPiio ULN2803] is a small(50x40mm) add-on board which connects a ULN2803 Darlington Driver chip to the RPi's GPIO allowing the RPi to control electronic circuits which require more current to drive them.<br />
<br />
=== RPi MIDI Breakout Board ===<br />
[http://zuzebox.wordpress.com/2012/03/18/midi-breakout-board-for-raspberry-pi-v0-10/ RPi MIDI Breakout Board] is a simple MIDI breakout board for the Raspberry Pi using the hardware UART from the RPi's expansion interface<br />
<br />
=== RPi Protoboard SM===<br />
[http://zuzebox.wordpress.com/2012/06/25/raspberry-pi-protoboard-sm-v0-10/ RPi Protoboard SM] is a simple prototype board for the Raspberry Pi<br><br />
[http://www.designspark.com/knowledge/raspberry-pi-prototype-board-files another link] to the same project?<br />
<br />
=== RPi "UserPort" ===<br />
[http://zuzebox.wordpress.com/2012/03/14/userport-for-raspberry-pi-v0-10/ RPi UserPort] is a digital and analogue I/O board for the Raspberry Pi. UserPort replicates the original BBC Micros digital User Port and Analogue Port but uses more modern components such as the MCP23S17 16-ch GPIO and MCP3204 4-ch 12-bit ADC.<br />
<br />
===rpi_serial===<br />
BitWizard has a [http://www.bitwizard.nl/wiki/index.php/Raspberry_pi_expansion_system_page#expansion_boards Raspberrypi serial breakout board]. It breaks out four serial buses from the GPIO port.<br />
<br />
BitWizard then has a series SPI (or I2C) expansion boards that can be daisy-chained off the SPI (or I2C) buses of the expansion board. A virtually unlimited number of expansion boards can be connected. Expansion boards are available that drive a simple 16x2 text LCD, more general purpose IOs, servos, temperature sensors, relays, optocouplers etc. <br />
<br />
===RPi RS232 Breakout Board===<br />
[http://zuzebox.wordpress.com/2012/02/07/rs232-breakout-board-v0-20-for-raspberry-pi/ RPi RS232 Breakout Board] is a simple RS232 breakout board for the Raspberry Pi<br />
<br />
=== 1-Wire Masters from Sheepwalk Electronics ===<br />
<br />
[http://www.sheepwalkelectronics.co.uk/ Sheepwalk Electronics] are currently developing a series of expansion boards for the Raspberry Pi to interface your Raspberry Pi to a Dallas/Maxim 1-Wire network. The range includes a simple passive "master" (called the RPI1) to allow easy use of the kernel 1-Wire driver, a single channel I2C master based around the DS2482-100 (called the RPI2) and an 8 channel I2C master based around the DS2482-800 (the RPI3). The RPI1 and RPI2 modules are now available on our website. The RPI3 8 channel master is still under development. The modules are all available as a bare PCB, kit of parts or fully assembled/tested.<br />
<br />
===Slice of Pi===<br />
[http://shop.ciseco.co.uk/slice-of-pi/ Slice of Pi] Ciseco have produced a convienient small break out board for the Raspberry PI. XBee style connector for XRF / XBee / RN-XV / XBT / RF-BEE etc. Has the SPI and I2C pins on one standard 8 way header and the Raspberry PI's 8 general purpose I/O pins on another for easy access. Comes as a kit of parts that needs to be soldered. Construction is very easy and suitable for children with basic soldering skills.<br />
<br />
=== XBee ZB SMT Backpack ===<br />
The [http://www.bootc.net/archives/2012/06/20/raspberry-pi-xbee-smt-backpack/ Raspberry Pi XBee ZB SMT Backpack] by [[User:bootc|bootc]] is a carrier board for [http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/zigbee-mesh-module/xbee-smt Digi XBee ZB SMT] modules. These are different to the normal XBee modules because they are surface mount and additionally can interface to a host using SPI as well as serial. The backpack also features 3 LEDs for status signals as well as two FTDI headers (one for the RPi and one for the XBee), as well as being able to host a 'normal' XBee module (though of course you can't use SPI with those).<br />
<br />
=== RPi Servo board ===<br />
The [http://electronics.chroma.se/rpisb.php Raspberry Pi Servo board] by [[User:adent|adent]] is a small expansion board for connecting up to eight RC servos and/or an ESC (Electronic Speed Controller) to the RPi. It has a pass through for the GPIO port and it uses the serial line in it for commands. The interface is a simple ASCII-protocol via the serial port. It also has five own GPIO-pins that is not supported by card firmware yet. Firmware is released as GPL. Can power RPi from ESC or external source.<br />
Youtube clip of [http://youtu.be/_W1WXnL9MeA first prototype]. Working on an alternate firmware to connect DHT22/11 humidity/temperature sensors to the board instead.<br />
<br />
=== RPi SOFTWARE Servo board ===<br />
The [http://electronics.chroma.se/rpiswsb.php Raspberry Pi SOFTWARE Servo board] by [[User:adent|adent]] is a small expansion board for connecting up to eight RC servos and/or an ESC (Electronic Speed Controller) to the RPi. It has a pass through for the GPIO port. Can power RPi from ESC or external source.<br />
It needs a [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=15011&hilit=servo kernel module] to work. The card only buffers the GPIO of the RPi and <br />
provides convenient connectors. Since there was room on the PCB, the serialport, GND and 3V3 is broken out.<br />
<br />
=== Raspy Juice Exp Board ===<br />
[http://2-watt-elements.myshopify.com/ Raspy Juice] by 2-Watt Elements is an experimental board that supplies the Raspberry Pi with +5V through the GPIO header. With its wide input voltage range (6~23V), the buck regulator can be powered by batteries, 12V Adapters, solar, etc. Other features are the RS232 level console port, PCF8523 RTC, and an expansion ATmega168A microcontroller as an I2C slave. This latter MCU has interfaces of an RS485 port, an additional RS232 port, 4 RC-servo ports and unused-pins expansion header. The MCU firmware is updateable through the I2C interface. Hardware details are in http://code.google.com/p/raspy-juice/wiki/1_Hardware_Description<br />
<br />
=== pyMCU ===<br />
[http://www.pymcu.com pyMCU] is a python controlled microcontroller that works with the Raspberry Pi, connects to the USB port and uses the pyMCU python module and pyserial to control the microcontroller in your python script. You can communicate with i2c, spi, serial, and one wire devices, software configurable pulse in / out functions, has 13 Digital IO Pins, 6 10-bit Analog Pins, 5 10-Bit PWM Pins, blink LEDs, control servos and motors, read various sensors, built-in functions for sound generation: arbitrary frequency generator, misc. sound / tone generator, DTMF generator. PyBootloader - python script for uploading new firmware versions or your own microcontroller code. Check out some of the [http://pymcu.com/Tutorials.html Tutorials] and [http://pymcu.com/Examples.html Examples]<br />
<br />
=== RPi CC1101-OneWire-Clock extension ===<br />
The [http://busware.de/tiki-index.php?page=COC RPi-COC board] from [http://busware.de busware.de] adds Onewire, a Sub-1 GHz RF Transceiver, RTC and an EEPROM mainly for smart home automation. The Onewire RJ11 port is driven by a DS2482 chip supported by 5V levelshifter and strong pullup. The DS1339-RTC is powered by CR2032 battery or on-board 60mF supercap. The 2Kbit EEPROM (at24c02) is mainly to hold board specific config data. The CC1101 Sub-1 GHz RF Transceiver is controlled by an atmega1284 to pre-process air data. It is connected to RPis UART and contains a avr109-bootloader for firmware updates. The popular [http://culfw.de culfw-firmware] lets you interact with FS20, Homematic, Intertechno or similar actors and sensors - easily using [http://fhem.de FHEM]-home automation server. In addition a secured 5V power socket for external power supplies is provided.<br />
<br />
=== RFM12Pi - Wireless OpenEnergyMonitor Base-station ===<br />
Add's RFM12B wireless (868/433/912Mhz) RF transceiver capability to the Raspberry Pi. The RFM12pi has got an-board ATtiny84 microcontroller pre-loaded with firmware to decode RFM12B packets from [http://jeelabs.org JeeNode] and [http://openenergymonitor.org OpenEnergyMonitor] sensor modules onto Raspberry Pi's internal serial UART. Designed to be used with [http://emoncms.org emoncms] running on a Raspberry Pi web-server to make a low power energy, temperature and other environmental data logging and visualisation server. Developed as part of the [http://openenergymonitor.org openenergymonitor.org] project. For more info see [http://openenergymonitor.blogspot.com/2012/11/raspberry-pi-emonbase.html introductory blog] post, [http://openenergymonitor.org/emon/emonbase/raspberrypi overview documentation page] and [http://wiki.openenergymonitor.org/index.php?title=Raspberry_Pi technical documentation wiki].<br />
<br />
=== Rs-Pi 4 USB hub & multi-function I2C AD/DA RTC RS232 board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 4 Ports USB hub with multi-function I2C board <br />
size 71mm x 54mm small than Raspberry Pi<br />
(RTC-DS1307, Temperature Sensor-TMP102, D/A MCP4725,A/D ADS1015,EEPROM, MCP23008, FT232RL, ZT3243) <br />
[http://www.pridopia.co.uk/pi-usb-hub-i2c-ad-da-ft232-r1.html Rs-Pi-USB-hub-I2C-multi-function AD/DA Board] <br />
with USB to RS232 full DB9 9pin signal or USB to TTL (FT232RL) console port), RTC with CR1220 battrey, USB with 1.6A PTC fuse for all four USB ports. No extra extension cable need. and no extra Power adapter for USB hub. <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
We have three different models with different function, you can choose anyone you want.<br />
* 1. Rs-Pi 4 USB Hub with ( ds1307,tmp102, mcp4725,24c32) [http://www.pridopia.co.uk/pi-usb-hub-i2c-lite.html Rs-Pi USB Hub-Lite]<br />
* 2. Rs-Pi 4 USB Hub with ( ds1307,tmp102, mcp4725,24c32, ft232RL) - with USB to TTL (just need one USB cable plug-in your PC and Rs-Pi) [http://www.pridopia.co.uk/pi-usb-hub-i2c-ft232-lite.html Rs-Pi USB Hub FT232RL-Lite ]<br />
* 3 Rs-Pi 4 USB Hub with ( ds1307,tmp102, mcp4725,ads1015, 24c32, mcp23008, ft232RL, zt3243) with USB to RS232 (DB9 full 9pin RS232 COM port output) or USB to TTL console port [http://www.pridopia.co.uk/pi-usb-hub-i2c-ad-da-ft232-r1.html Rs-Pi-USB-hub-I2C-multi-function AD/DA Board]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi 4 USB hub with I2C 23017x2 32 GPIO board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 4 Ports USB hub with I2C 23017x2 32 GPIO board <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-usb-4-hub-i2c-23017-2.html Rs-Pi-4-USB-hub-I2C-23017x2 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi 4 USB hub with SPI 23s17x2 32 GPIO board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 4 Ports USB hub with SPI 23s17x2 32 GPIO board <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-usb-4-hub-spi-23s17-2.html Rs-Pi-4-USB-hub-SPI-23s17x2 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi 7 USB hub with multi-function I2C AD/DA board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 7 Ports USB hub with multi-function I2C board <br />
size 71mm x 54mm small than Raspberry Pi<br />
(RTC-DS1307, Temperature Sensor-TMP102, D/A MCP4725,A/D ADS1015,EEPROM) <br />
[http://www.pridopia.co.uk/pi-usb-7-hub-i2c-ad-da.html Rs-Pi-7-USB-hub-I2C-multi-function AD/DA Board] <br />
RTC with CR2032 battrey, USB with 2 x 1.6A PTC fuse for all seven USB ports. No extra extension cable need. and no extra Power adapter for USB hub. <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
<br />
We have two different models with different function, you can choose anyone you want.<br />
* 1. Rs-Pi 7 USB Hub with ( ds1307,tmp102,24c32) [http://www.pridopia.co.uk/pi-usb-7-hub-i2c-lite.html Rs-Pi 7 USB Hub -Lite]<br />
* 2. Rs-Pi 7 USB Hub with ( ds1307,tmp102,24c32,ads1015,mcp4725 ) [http://www.pridopia.co.uk/pi-usb-7-hub-i2c-ad-da.html Rs-Pi 7 USB Hub AD/DA Board ]<br />
<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi 7 USB hub with I2C 23017x1 16 GPIO board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 7 Ports USB hub with I2C 23017 16 GPIO board <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-usb-7-hub-i2c-23017-1.html Rs-Pi-7-USB-hub-I2C-23017 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi 7 USB hub with SPI 23s17x1 16 GPIO board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi Internal 7 Ports USB hub with SPI 23S17 16 GPIO board <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-usb-7-hub-spi-23s17-1.html Rs-Pi-7-USB-hub-SPI-23S17 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi I2C 23017x2 32 GPIO with uln2803 x2 board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi I2C 23017x2 32 GPIO with 8 Switch input & uln2803x2 output board <br />
each 23017 port A output to ULN2803, first one 23017 port B for 8 switch input, second one 23017 port B for normal output with 8 LED.<br />
with 3.5mm block terminal 9pin output, can plug in our 2803 relay board<br />
with two Step motor connector (5V,D0,D1,D2,D3) (5V,D4,D5,D6,D7) can use Step motor (28BYJ-48 5VDC)<br />
with 4 5V motor output port <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-i2c-23017x2-2803x2.html Rs-Pi-I2C-23017x2-2803x2 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi SPI 23s17x2 32 GPIO with uln2803 x2 board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* The Rs-Pi SPI 23s17x2 32 GPIO with 8 Switch input & uln2803x2 output board <br />
each 23s17 port A output to ULN2803, first one 23s17 port B for 8 switch input, second one 23s17 port B for normal output with 8 LED.<br />
with 3.5mm block terminal 9pin output, can plug in our 2803 relay board<br />
with two Step motor connector (5V,D0,D1,D2,D3) (5V,D4,D5,D6,D7) can use Step motor (28BYJ-48 5VDC)<br />
with 4 5V motor output port <br />
size 71mm x 54mm small than Raspberry Pi<br />
[http://www.pridopia.co.uk/pi-spi-23s17x2-2803x2.html Rs-Pi-SPI-23s17x2-2803x2 Board] <br />
All from [http://www.pridopia.co.uk/index.html Pridopia]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi I2C 23017-2 32 GPIO Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi I2c 23017 x2 32GPIO board I2C interface <br />
size 49mm x 49mm <br />
with 32 Blue SMD LED [http://www.pridopia.co.uk/pi-23017-2-lp.html Rs-Pi-23017-2]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi SPI 23s17-2 32 GPIO Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi SPI 23s17 x2 32GPIO Board SPI Interface<br />
size 49mm x 49mm<br />
with 32 Blue SMD LED [http://www.pridopia.co.uk/pi-23s17-2-lp.html Rs-Pi-23S17-2]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi ULN2803 & SPI AD/DA Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi ULN2803 & SPI AD/DA Board <br />
ULN2803 8 Darlington transistor array output<br />
can output to 8 5V relay <br />
with 2 Step motor connector,can connect Step motor(28BYJ-48 5VDC)<br />
and MCP3002 SPI Interface 10 bit Analog-to-Digital Converter<br />
and MCP4802 SPI Interface 8 bit Digital-to-Analog Converter<br />
size 49mm x 39mm<br />
[http://www.pridopia.co.uk/pi-2803-sm-ad-da-lp.html Rs-Pi-2803-ADDA]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi ULN2803 8bit 2 Relay Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi ULN2803 2 Relay Board <br />
ULN2803 8 Darlington transistor array output<br />
size 49mm x 40mm<br />
[http://www.pridopia.co.uk/pi-2803-2relay.html Rs-Pi-2803-2Relay]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi ULN2803 8bit 4 Relay Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi ULN2803 4 Relay Board <br />
ULN2803 8 Darlington transistor array output<br />
size 76mm x 36mm<br />
[http://www.pridopia.co.uk/pi-2803-4relay.html Rs-Pi-2803-4Relay]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi USB to TTL console Board ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi USB to TTL Console Board <br />
USB to TTL Console module plug in Rs-Pi with normal USb to Mini USb cable with your PC or Mac<br />
size 32mm x 39mm<br />
[http://www.pridopia.co.uk/pi-usb-ttl.html Rs-Pi-USB-TTL Console Board]<br />
All of our Rs-Pi Products are design and Made in UK<br />
<br />
=== Rs-Pi RS232 DB9 cable ===<br />
[http://www.pridopia.co.uk/ixx-rspi.html Pridopia] P-pi serials for Raspberry Pi <br />
* Rs-Pi RS232 DB9 console cable with 90cm length cable [http://www.pridopia.co.uk/pi-232r1-db9.html Rs-Pi-RS232-DB9]<br />
<br />
All of our Rs-Pi Products are design and Made in UK<br />
All can plug in our RS-Pi USB hub multi-function Board and work together.<br />
<br />
<br />
=== (MyPiShop) Pi 8 LED & 8 Button ===<br />
[http://mypishop.com/Pi%208%20LED%20&%208%20Button.html Pi 8 LED & 8 Button] interface board for Raspberry Pi. <br />
<br />
Perfect way to learn how to use the GPIO pins.<br/><br />
Plugs directly into the Raspberry Pi GPIO connector. (P1 header)<br/><br />
Has eight bright green LED's and eight momentary switches.<br/><br />
For a more detailed description see: http://mypishop.com/Pi%208%20LED%20&%208%20Button.html<br />
<br />
=== (MyPiShop) Stepper Motor Controller Board ===<br />
[http://mypishop.com/Stepper.html Pi Stepper Motor Controller] interface board for Raspberry Pi. <br />
<br />
The stepper board uses 8 GPIO pins to drive up to two stepper motors.<br/><br />
(One stepper motor is included in the kit)<br/><br />
Plugs directly into the Raspberry Pi GPIO connector. (P1 header)<br/><br />
The board can use the 5 VDC provided by the Raspberry Pi or you can optionally provide your own source voltage to drive the motors.<br/><br />
This board includes a ULN2803 8 Channel Darlington Driver and can be used to control other higher current devices such as relay boards, etc.<br/><br />
For a more detailed description see: http://mypishop.com/Stepper.html<br />
<br />
=== (MyPiShop) Read Your Pi !(LCD Interface Board) ===<br />
[http://mypishop.com/Read%20Your%20Pi%20!.html Read Your Pi (LCD)] interface board for Raspberry Pi. <br />
<br />
Available kits with 20x4 LCD display or 16x2 LCD display.<br />
The interface board uses the GPIO pins display characters on a LCD display.<br/><br />
Plugs directly into the Raspberry Pi GPIO connector. (P1 header)<br/><br />
For a more detailed description see: http://mypishop.com/Read%20Your%20Pi%20!.html<br />
<br />
=== (MyPiShop) Protect Your Pi ! (16 or 32 IO Expansion Kit) ===<br />
[http://mypishop.com/ Protect Your Pi (LCD)] interface board for Raspberry Pi. <br />
<br />
Available kits with 16 or 32 GPIO expansion pins.<br />
The expansion board uses the I2C bus on the Raspberry Pi to provide up to 32 additional GPIO pins.<br/><br />
Plugs directly into the Raspberry Pi GPIO connector. (P1 header)<br/><br />
For a more detailed description see: http://mypishop.com<br />
<br />
=== (MyPiShop) Pi MATRIX ! 8X8 LED Matrix with 16 bit I/O ! ===<br />
[http://mypishop.com/ Pi MATRIX !] 8X8 LED Matrix with 16 bit I/O kit for the Raspberry Pi. <br />
<br />
HUGE 8X8 LED MATRIX<br/><br />
Plugs directly into the Raspberry Pi GPIO connector. (P1 header)<br/><br />
Take the display off and use it for 16 bits of I/O<br/><br />
For a more detailed description see: http://mypishop.com<br />
<br />
=== BerryClip 6 LED Buzzer Board ===<br />
The [http://www.raspberrypi-spy.co.uk/berryclip-6-led-add-on-board/ BerryClip] is a small board providing 6 coloured LEDs, 1 buzzer and 1 switch. It provides an easy and quick introduction to GPIO experimenting. The board plugs directly onto the Raspberry Pi GPIO connector and there are lots of Python example scripts available.<br /><br />
For a more detailed description see: [http://www.raspberrypi-spy.co.uk/berryclip-6-led-add-on-board/ BerryClip on Raspberrypi-spy.co.uk]<br />
<br />
==References==<br />
<references/><br />
<br />
<br />
{{Template:Raspberry Pi}}</div>MattHawkinsUKhttps://elinux.org/index.php?title=RPi_Low-level_peripherals&diff=169916RPi Low-level peripherals2012-09-14T22:51:52Z<p>MattHawkinsUK: /* P5 header */</p>
<hr />
<div>[[Category: RaspberryPi]]<br />
{{Template:RPi_Hardware}}<br />
<br />
<br />
==Introduction==<br />
In addition to the familiar USB, Ethernet and HDMI ports, the R-Pi offers lower-level interfaces intended to connect more directly with chips and subsystem modules. These GPIO (general purpose I/O) signals on the 2x13 header pins include SPI, I2C, serial UART, 3V3 and 5V power. These interfaces are not "plug and play" but require care to avoid miswiring. The pins use a 3V3 logic level and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. Not yet software-enabled are the flex cable connectors with CSI (camera serial interface) and DSI (display serial interface), and a serial link inside the HDMI connector called CEC (consumer electronics control).<br />
<br />
==General Purpose Input/Output (GPIO)==<br />
[[File:GPIOs.png|thumb|254px|right|The layout of the Raspberry Pi GPIOs, colour coded to the table. [https://sites.google.com/site/burngatehouse/home/drawings/GPIOs2.gif Source] ]]<br />
<br />
General Purpose Input/Output (a.k.a. GPIO) is a generic pin on a chip whose behavior (including whether it is an input or output pin) can be controlled (programmed) through software.<br />
<br />
The Raspberry Pi allows peripherals and expansion boards (such as the [[Rpi Gertboard]]) to access the CPU by exposing the inputs and outputs.<br />
<br />
For further general information about GPIOs, see:[http://en.wikipedia.org/wiki/GPIO the wikipedia article].<br />
<br />
The production Raspberry Pi board has a 26-pin 2.54&nbsp;mm (100&nbsp;mil)<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-3/#p31907</ref> expansion header, marked as P1, arranged in a 2x13 strip. They provide 8 GPIO pins plus access to I²C, SPI, UART), as well as +3.3&nbsp;V, +5&nbsp;V and GND supply lines. Pin one is the pin in the first column and on the bottom row. <ref>http://www.raspberrypi.org/archives/384</ref><br />
<br />
'''GPIO voltage levels are 3.3&nbsp;V and are not 5&nbsp;V tolerant. There is no over-voltage protection on the board''' - the intention is that people interested in serious interfacing will use an external board with buffers, level conversion and analog I/O rather than soldering directly onto the main board.<br />
<br />
All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so. At reset only pins GPIO 14 & 15 are assigned to the alternate function UART, these two can be switched back to GPIO to provide a total of 17 GPIO pins<ref>http://www.raspberrypi.org/archives/384</ref>. Each of their functions and full details of how to access are detailed in the chipset datasheet <ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref>.<br />
<br />
Each GPIO can interrupt, high/low/rise/fall/change.<ref>http://www.raspberrypi.org/archives/384#comment-5217</ref><ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref> There is currently no support for GPIO interrupts in the official kernel, howewer a patch exists, requiring compilation of modified source tree.<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=7509</ref><br />
<br />
GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited, and source and sink current is configurable from 2&nbsp;mA up to 16&nbsp;mA. Note that chipset GPIO pins 0-27 are in the same block and these properties are set per block, not per pin. See [http://www.scribd.com/doc/101830961/GPIO-Pads-Control2 GPIO Datasheet Addendum - GPIO Pads Control]. Particular attention should be applied to the note regarding SSO (Simultaneous Switching Outputs): to avoid interference, driving currents should be kept as low as possible.<br />
<br />
The available [[RPi_BCM2835_GPIOs|alternative functions]] and their corresponding pins are detailed below. These numbers are in reference to the chipset documentation and may not match the numbers exposed in Linux. Only fully usable functions are detailed, for some alternative functions not all the necessary pins are available for the funtionality to be actually used.<br />
<br />
There is also some information on the [[RPi Tutorial Easy GPIO Hardware & Software|Tutorial on Easy GPIO Hardware & Software]].<br />
<br />
Kernel boot messages go to the [[RPi_Serial_Connection|UART]] at 115200&nbsp;bit/s.<br />
<br />
'''R-Pi PCB Revision 2 UPDATE:''' According to Eben at [http://www.raspberrypi.org/archives/1929#comments] the R-Pi Rev.2 board being rolled out starting in September 2012 adds 4 more GPIO on a new connector called P5, and changes some of the existing P1 GPIO pinouts. On Rev2, GPIO_GEN2 [BCM2835/GPIO27] is routed to P1 pin 13, and changes what was SCL0/SDA0 to SCL1/SDA1: SCL1 [BCM2835/GPIO3] is routed to P1 pin 5, SDA1 [BCM2835/GPIO2] is routed to P1 pin 3. Also the power and ground connections previously marked "Do Not Connect" on P1 will remain as connected, specifically:<br />
P1-04: +5V0<br />
P1-09: GND<br />
P1-14: GND<br />
P1-17: +3V3<br />
P1-20: GND<br />
P1-25: GND<br />
<br />
'''Header Pinout, top row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-02 || bgcolor="red" | <span style="color:white">5V0</span> || bgcolor="red" | <span style="color:white">5V0</span> || Supply through input poly fuse<br />
|-<br />
| P1-04 || DNC<br />
|-<br />
| P1-06 || bgcolor="black" | <span style="color:white">GND</span> || bgcolor="black" | <span style="color:white">GND</span> <br />
|-<br />
|-<br />
| P1-08 || bgcolor="lime" | GPIO 14 || bgcolor="lime" | GPIO 14 || Boot to Alt 0 -> || bgcolor="yellow" | UART0_TXD || ALT5 = UART1_TXD<br />
|-<br />
| P1-10 || bgcolor="lime" | GPIO 15 ||bgcolor="lime" | GPIO 15 || Boot to Alt 0 -> ||bgcolor="yellow" | UART0_RXD || ALT5 = UART1_RXD<br />
|-<br />
| P1-12 || bgcolor="lime" | GPIO 18 ||bgcolor="lime" | GPIO 18 || || || ALT4 SPI1_CE0_N ALT5 = PWM0<br />
|-<br />
| P1-14 || DNC<br />
|-<br />
| P1-16 || bgcolor="lime" | GPIO23 ||bgcolor="lime" | GPIO23 || || || ALT3 = SD1_CMD ALT4 = ARM_RTCK<br />
|-<br />
| P1-18 || bgcolor="lime" | GPIO24 ||bgcolor="lime" | GPIO24 || || || ALT3 = SD1_DATA0 ALT4 = ARM_TDO<br />
|-<br />
| P1-20 || DNC<br />
|-<br />
| P1-22 || bgcolor="lime" | GPIO25 ||bgcolor="lime" | GPIO25 || || || ALT4 = ARM_TCK<br />
|-<br />
| P1-24 || bgcolor="lime" | GPIO08 ||bgcolor="lime" | GPIO08 || || bgcolor="purple" | <span style="color:white">SPI0_CE0_N</span> ||<br />
|-<br />
| P1-26 || bgcolor="lime" | GPIO07 ||bgcolor="lime" | GPIO07 || || bgcolor="purple" | <span style="color:white">SPI0_CE1_N</span> || <br />
|}<br />
<br />
<br />
'''Header Pinout, bottom row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-01 || bgcolor="orange" | 3.3&nbsp;V ||bgcolor="orange" | 3.3&nbsp;V || 50&nbsp;mA max current draw<br />
|-<br />
| P1-03 || bgcolor="lime" | GPIO 0 ||bgcolor="lime" | GPIO 2|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SDA || I2C0_SDA / I2C1_SDA<br />
|-<br />
| P1-05 || bgcolor="lime" | GPIO 1 ||bgcolor="lime" | GPIO 3|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SCL || I2C0_SCL / I2C1_SCL <br />
|-<br />
| P1-07 || bgcolor="lime" | GPIO 4 ||bgcolor="lime" | GPIO 4 || || || bgcolor="lime" | GPCLK0<br />
|-<br />
| P1-09 || DNC<br />
|-<br />
| P1-11 || bgcolor="lime" | GPIO17 || bgcolor="lime" | GPIO17 || || ||| ALT3 = UART0_RTS, ALT5 = UART1_RTS<br />
|-<br />
| P1-13 || bgcolor="lime" | GPIO21 || bgcolor="lime" | GPIO27 || || PCM_DIN || ALT5 = GPCLK1<br />
|-<br />
| P1-15 || bgcolor="lime" | GPIO22 || bgcolor="lime" | GPIO22 || || || ALT3 = SD1_CLK ALT4 = ARM_TRST<br />
|-<br />
| P1-17 || DNC<br />
|-<br />
| P1-19 || bgcolor="lime" | GPIO10 || bgcolor="lime" | GPIO10 || || bgcolor="purple" | <span style="color:white">SPI0_MOSI</span> || <br />
|-<br />
| P1-21 || bgcolor="lime" | GPIO9 || bgcolor="lime" | GPIO9 || || bgcolor="purple" | <span style="color:white">SPI0_MISO</span> ||<br />
|-<br />
| P1-23 || bgcolor="lime" | GPIO11 || bgcolor="lime" | GPIO11 || || bgcolor="purple" | <span style="color:white">SPI0_SCLK</span> || <br />
|-<br />
| P1-25 || DNC<br />
|}<br />
<br />
<br />
{| border="1"<br />
! Colour legend<br />
|-<br />
| bgcolor="red" | <span style="color:white">+5&nbsp;V</span><br />
|-<br />
| bgcolor="orange" | +3.3&nbsp;V<br />
|-<br />
| bgcolor="black" | <span style="color:white">Ground, 0V</span> <br />
|-<br />
| Do not connect<br />
|-<br />
| bgcolor="yellow" | UART<br />
|-<br />
| bgcolor="lime" | GPIO<br />
|-<br />
| bgcolor="purple" | <span style="color:white">SPI</span><br />
|-<br />
| bgcolor="cyan" | I²C<br />
|}<br />
<br />
KiCad symbol: [[File:Conn-raspberry.lib]]<br />
<br />
<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/gpio-header-pinout-clarification/page-2</ref><br />
<br />
Pin 3 (SDA0) and Pin 5 (SCL0) are preset to be used as an I²C interface. So there are 1.8&nbsp;kilohm pulls up resistors on the board for these pins.<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-6/#p56480</ref><br />
<br />
Pin 12 supports PWM.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-7, 15, 16, 18, 22 (chipset GPIOs 4 and 22 to 25) to provide an ARM JTAG interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.1</ref> However ARM_TMS isn't available on the GPIO connector (chipset pin 12 or 27 is needed). Chipset pin 27 is available on S5, the CSI camera interface however.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-12 and 13 (chipset GPIO 18 and 21) to provide an I2S (a hardware modification may be required<ref name="I2S">[http://www.raspberrypi.org/forum/features-and-requests/sad-about-removal-of-i2s-why-was-this-change-made Forum:Sad about removal of I2S. Why was this change made?]</ref>) or PCM interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.2</ref> However, PCM_FS and PCM_DIN (chipset pins 19 and 20) are needed for I2S or PCM.<br />
<br />
A second I²C interface (GPIO02_ALT0 is SDA1 and GPIO03_ALT0 is SCL1) and two further GPIOs (GPIO05_ALT0 is GPCLK1, and GPIO27) are available on S5, the CSI camera interface.<br />
<br />
===A note about GPIO vs the schematic===<br />
<br />
You may notice that the GPIO connector as documented in the schematic does NOT match with what is on this wiki page. Do NOT update this wiki page. The pins which are marked as DNC should not be used in order to be compatible with possible future designs. The plan is that if a new design comes along and if the layout permits it we will connect additional GPIO pins to those DNC pins. (Gert's first vote is for GPIO 19 and 20. That gives us the second PWM, second SPI, I2S/PCM, slave I²C and slave SPI.)<br />
<br />
===Referring to pins on the Expansion header===<br />
<br />
The header is referred to as "The GPIO Connector (P1)". To avoid nomenclature confusion between Broadcom signal names on the SoC and pin names on the expansion header, the following naming is highly recommended.<br />
<br />
* The expansion header is referred to as "Expansion Header" or "GPIO Connector (P1)"<br />
* Pins on the GPIO connector (P1) are referred to as P1-01, etc.<br />
* Names GPIO0, GPIO1, GPIOx-ALTy, etc. refer to the signal names on the SoC as enumerated in the Broadcom datasheet, where "x" matches BCM2835 number (without leading zero) and "y" is the alternate number column 0 to 5 on page 102-103 of the Broadcom document. For example, depending on what you are describing, use either "GPIO7" to refer to a row of the table, and "GPIO7-ALT0" would refer to a specific cell of the table.<br />
* When refering to signal names, you should modify the Broadcom name slightly to minimize confusion. The Broadcom SPI bus pin names are fine, such as "SPI0_*" and "SPI1_*", but they didn't do the same on the I²C and UART pins. Instead of using "SDA0" and "SCL0", you should use "I2C0_SDA" and "I2C0_SCL"; and instead of "TX" or "TXD" and "RX" or "RXD", you should use "UART0_TXD" and "UART0_RXD".<br />
<br />
===Power pins===<br />
The maximum permitted current draw from the 3.3&nbsp;V pin is 50&nbsp;mA.<br />
<br />
Maximum permitted current draw from the 5&nbsp;V pin is the USB input current (usually 1&nbsp;A) minus any current draw from the rest of the board.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1536#postid-21841</ref><br />
*Model A: 1000&nbsp;mA - 500&nbsp;mA -> max current draw: 500&nbsp;mA<br />
*Model B: 1000&nbsp;mA - 700&nbsp;mA -> max current draw: 300&nbsp;mA<br />
Be very careful with the 5&nbsp;V pin, because if you short it to any other P1 pin you may permanently damage your RasPi. Before probing P1, it's a good idea to strip a short piece of insulation off a wire and push it over the 5&nbsp;V pin so you don't accidentally touch it with a probe.<br />
<br />
=== GPIO hardware hacking ===<br />
<br />
The complete list of [[RPi_BCM2835_GPIOs|chipset GPIO pins]] which are available on the GPIO connector is: <blockquote>[[RPi_BCM2835_GPIOs#GPIO0|0]], [[RPi_BCM2835_GPIOs#GPIO1|1]], [[RPi_BCM2835_GPIOs#GPIO4|4]], [[RPi_BCM2835_GPIOs#GPIO7|7]], [[RPi_BCM2835_GPIOs#GPIO8|8]], [[RPi_BCM2835_GPIOs#GPIO9|9]], [[RPi_BCM2835_GPIOs#GPIO10|10]], [[RPi_BCM2835_GPIOs#GPIO11|11]], [[RPi_BCM2835_GPIOs#GPIO14|14]], [[RPi_BCM2835_GPIOs#GPIO15|15]], [[RPi_BCM2835_GPIOs#GPIO17|17]], [[RPi_BCM2835_GPIOs#GPIO18|18]], [[RPi_BCM2835_GPIOs#GPIO21|21]], [[RPi_BCM2835_GPIOs#GPIO22|22]], [[RPi_BCM2835_GPIOs#GPIO23|23]], [[RPi_BCM2835_GPIOs#GPIO24|24]], [[RPi_BCM2835_GPIOs#GPIO25|25]]</blockquote><br />
<br />
As noted above, GPIO00 and 01 (SDA0 and SCL0) have 1.8&nbsp;kilohm pull-up resistors to 3.3&nbsp;V.<br />
<br />
If 17 GPIOs aren't sufficient for your project, there are a few other signals potentially available, with varying levels of software and hardware (soldering iron) hackery skills:<br />
<br />
GPIO02, 03, 05 and 27 are available on S5 (the CSI interface) when a camera peripheral is not connected to that socket, and are configured by default to provide the functions SDA1, SCL1, CAM_CLK and CAM_GPIO respectively. SDA1 and SCL1 have 1K6 pull-up resistors to 3.3&nbsp;V.<br />
<br />
GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function.<br />
<br />
There are a few other chipset GPIO pins accessible on the PCB but are in use:<br />
<br />
* GPIO16 drives status LED D5 (usually SD card access indicator)<br />
* GPIO28-31 are used by the board ID and are connected to resistors R3 to R10.<br />
* GPIO40 and 45 are used by analogue audio and support PWM. They connect to the analogue audio circuitry via R21 and R27 respectively.<br />
* GPIO46 is HDMI hotplug detect (goes to pin 6 of IC1).<br />
* GPIO47 to 53 are used by the SD card interface. In particular, GPIO47 is SD card detect (this would seem to be a good candidate for re-use). GPIO47 is connected to the SD card interface card detect switch; GPIO48 to 53 are connected to the SD card interface via resistors R45 to R50.<br />
<br />
=== P2 header ===<br />
<br />
The P2 header is the VideoCore JTAG and used only during the production of the board. It cannot be used as the ARM JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>. This connector is unpopulated in Rev 2.0 boards. <br />
<br />
Useful P2 pins:<br />
<br />
* Pin 1 - 3.3V (same as P1-01, 50 mA max current draw across both of them)<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
=== P3 header ===<br />
<br />
The P3 header, unpopulated, is the LAN9512 JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>.<br />
<br />
=== P5 header ===<br />
<br />
The P5 header was added with the release of the Revision 2.0 PCB design.<br />
<br />
* Pin 1 - 5V<br />
* Pin 2 - 3V3<br />
* Pin 3 - GPIO28<br />
* Pin 4 - GPIO29<br />
* Pin 5 - GPIO30<br />
* Pin 6 - GPIO31<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
Note that the connector is intended to be mounted on the bottom of the PCB, so that for those who put the connector on the top side, the pin numbers are swapped. Pin 1 and pin 2 are swapped, pin 3 and 4, etc. <br />
<br />
Note that the connector is placed JUST off-grid with respect to the P1 connector.<br />
<br />
===Driver support===<br />
<br />
The Foundation will not include a GPIO driver in the initial release, standard Linux GPIO drivers should work with minimal modification.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1278.0</ref><br />
<br />
The community implemented SPI and I²C drivers <ref>http://www.bootc.net/projects/raspberry-pi-kernel/</ref>, which will be integrated with the new Linux pinctrl concept in a later version of the kernel. A first compiled version as Linux modules is available to install on the 19/04/2012 Debian image, including 1-wire support<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?p=86172#p86172</ref>. The I²C and SPI driver uses the hardware modules of the microcontroller and interrupts for low CPU usage, the 1-wire support uses bitbanging on the GPIO ports, which results in higher CPU usage.<br />
<br />
GordonH<ref>http://www.raspberrypi.org/forum/general-discussion/wiring-for-the-raspberry-pis-gpio</ref> wrote a (mostly) Arduino compatible/style [https://projects.drogon.net/raspberry-pi/wiringpi/ WiringPi library] in C for controlling the GPIO pins.<br />
<br />
A useful tutorial on setting up I²C driver support can be found at [http://www.robot-electronics.co.uk/htm/raspberry_pi_examples.htm Robot Electronics] - look for the downloadable document rpi_i2c_setup.doc<br />
<br />
===Graphical User Interfaces===<br />
====WebIOPi====<br />
[http://code.google.com/p/webiopi/ WebIOPi] allows you to control each GPIO with a simple web interface that you can use with any browser. Available in PHP and Python, they both require root access, but Python version serves HTTP itself. You can setup each GPIO as input or output and change their states (LOW/HIGH). WebIOPi is fully customizable, so you can use it for home remote control. It also work over Internet. UART/SPI/I2C support will be added later. If you need some computing for your GPIO go to code examples below.<br />
<br />
===Code examples===<br />
====GPIO Driving Example (C)====<br />
[http://www.raspberrypi.org/forum/educational-applications/gertboard/page-4/#p31555 Gert van Loo & Dom, has provided] some tested code which accesses the GPIO pins through direct GPIO register manipulation in C-code.<br />
(Thanks to Dom for doing the difficult work of finding and testing the mapping.)<br />
Example GPIO code:<br />
<br />
<pre><br />
//<br />
// How to access GPIO registers from C-code on the Raspberry-Pi<br />
// Example program<br />
// 15-January-2012<br />
// Dom and Gert<br />
//<br />
<br />
<br />
// Access from ARM Running Linux<br />
<br />
#define BCM2708_PERI_BASE 0x20000000<br />
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */<br />
<br />
<br />
#include <stdio.h><br />
#include <string.h><br />
#include <stdlib.h><br />
#include <dirent.h><br />
#include <fcntl.h><br />
#include <assert.h><br />
#include <sys/mman.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
<br />
#include <unistd.h><br />
<br />
#define PAGE_SIZE (4*1024)<br />
#define BLOCK_SIZE (4*1024)<br />
<br />
int mem_fd;<br />
char *gpio_mem, *gpio_map;<br />
char *spi0_mem, *spi0_map;<br />
<br />
<br />
// I/O access<br />
volatile unsigned *gpio;<br />
<br />
<br />
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)<br />
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))<br />
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))<br />
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))<br />
<br />
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0<br />
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0<br />
<br />
void setup_io();<br />
<br />
int main(int argc, char **argv)<br />
{ <br />
int g,rep;<br />
<br />
// Set up gpi pointer for direct register access<br />
setup_io();<br />
<br />
// Switch GPIO 7..11 to output mode<br />
<br />
/************************************************************************\<br />
* You are about to change the GPIO settings of your computer. *<br />
* Mess this up and it will stop working! *<br />
* It might be a good idea to 'sync' before running this program *<br />
* so at least you still have your code changes written to the SD-card! *<br />
\************************************************************************/<br />
<br />
// Set GPIO pins 7-11 to output<br />
for (g=7; g<=11; g++)<br />
{<br />
INP_GPIO(g); // must use INP_GPIO before we can use OUT_GPIO<br />
OUT_GPIO(g);<br />
}<br />
<br />
for (rep=0; rep<10; rep++)<br />
{<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_SET = 1<<g;<br />
sleep(1);<br />
}<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_CLR = 1<<g;<br />
sleep(1);<br />
}<br />
}<br />
<br />
return 0;<br />
<br />
} // main<br />
<br />
<br />
//<br />
// Set up a memory regions to access GPIO<br />
//<br />
void setup_io()<br />
{<br />
/* open /dev/mem */<br />
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {<br />
printf("can't open /dev/mem \n");<br />
exit (-1);<br />
}<br />
<br />
/* mmap GPIO */<br />
<br />
// Allocate MAP block<br />
if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {<br />
printf("allocation error \n");<br />
exit (-1);<br />
}<br />
<br />
// Make sure pointer is on 4K boundary<br />
if ((unsigned long)gpio_mem % PAGE_SIZE)<br />
gpio_mem += PAGE_SIZE - ((unsigned long)gpio_mem % PAGE_SIZE);<br />
<br />
// Now map it<br />
gpio_map = (unsigned char *)mmap(<br />
(caddr_t)gpio_mem,<br />
BLOCK_SIZE,<br />
PROT_READ|PROT_WRITE,<br />
MAP_SHARED|MAP_FIXED,<br />
mem_fd,<br />
GPIO_BASE<br />
);<br />
<br />
if ((long)gpio_map < 0) {<br />
printf("mmap error %d\n", (int)gpio_map);<br />
exit (-1);<br />
}<br />
<br />
// Always use volatile pointer!<br />
gpio = (volatile unsigned *)gpio_map;<br />
<br />
<br />
} // setup_io<br />
<br />
</pre><br />
<br />
====GPIO Pull Up/Pull Down Register Example====<br />
<pre><br />
// enable pull-up on GPIO24&25<br />
GPIO_PULL = 2;<br />
short_wait();<br />
// clock on GPIO 24 & 25 (bit 24 & 25 set)<br />
GPIO_PULLCLK0 = 0x03000000;<br />
short_wait();<br />
GPIO_PULL = 0;<br />
GPIO_PULLCLK0 = 0;<br />
</pre><br />
<br />
====GPIO Driving Example (Python)====<br />
This uses the Python module available at http://pypi.python.org/pypi/RPi.GPIO<br />
Any Python script that controls GPIO must be run as root.<br />
<pre>import RPi.GPIO as GPIO<br />
<br />
# Set up the GPIO channels - one input and one output<br />
GPIO.setup(11, GPIO.IN)<br />
GPIO.setup(12, GPIO.OUT)<br />
<br />
# Input from pin 11<br />
input_value = GPIO.input(11)<br />
<br />
# Output to pin 12<br />
GPIO.output(12, True)<br />
<br />
# The same script as above but using BCM GPIO 00..nn numbers<br />
GPIO.setmode(GPIO.BCM)<br />
GPIO.setup(17, GPIO.IN)<br />
GPIO.setup(18, GPIO.OUT)<br />
input_value = GPIO.input(17)<br />
GPIO.output(18, True)</pre><br />
<br />
====GPIO Driving Example (Java)====<br />
This uses the Java library available at http://code.google.com/p/rpi-gpio-java/. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
public static void main(String[] args) {<br />
GpioGateway gpio = new GpioGatewayImpl();<br />
<br />
//set up the GPIO channels - one input and one output<br />
gpio.setup(Boardpin.PIN11_GPIO17, Direction.IN);<br />
gpio.setup(Boardpin.PIN12_GPIO18, Direction.OUT);<br />
<br />
// input from pin 11<br />
boolean input_value = gpio.getValue(Boardpin.PIN11_GPIO17);<br />
<br />
// output to pin 12<br />
gpio.setValue(Boardpin.PIN12_GPIO18, true); <br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Java webapp via http)====<br />
This uses the Java webapp available at https://bitbucket.org/sbub/rpi-gpio-webapp. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
host:~ sb$ curl 'http://raspberrypi:8080/handle?g0=1&g1=0'<br />
{"g1":0,"g0":1}<br />
<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
<pre><br />
#!/bin/sh<br />
<br />
# GPIO numbers should be from this list<br />
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25<br />
<br />
# Note that the GPIO numbers that you program here refer to the pins<br />
# of the BCM2835 and *not* the numbers on the pin header. <br />
# So, if you want to activate GPIO7 on the header you should be <br />
# using GPIO4 in this script. Likewise if you want to activate GPIO0<br />
# on the header you should be using GPIO17 here.<br />
<br />
# Set up GPIO 4 and set to output<br />
echo "4" > /sys/class/gpio/export<br />
echo "out" > /sys/class/gpio/gpio4/direction<br />
<br />
# Set up GPIO 7 and set to input<br />
echo "7" > /sys/class/gpio/export<br />
echo "in" > /sys/class/gpio/gpio7/direction<br />
<br />
# Write output<br />
echo "1" > /sys/class/gpio/gpio4/value<br />
<br />
# Read from input<br />
cat /sys/class/gpio/gpio7/value <br />
<br />
# Clean up<br />
echo "4" > /sys/class/gpio/unexport<br />
echo "7" > /sys/class/gpio/unexport<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script - take 2)====<br />
You need the wiringPi library from<br />
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/<br />
once installed there is a new command '''gpio''' which can be used<br />
as a '''non-root''' user to control the GPIO pins.<br />
<br />
The man page <pre>man gpio</pre> has full details, but briefly:<br />
<br />
<pre><br />
gpio -g mode 17 out<br />
gpio -g mode 18 pwm<br />
<br />
gpio -g write 17 1<br />
gpio -g pwm 18 512<br />
</pre><br />
<br />
the '''-g''' flag tells the '''gpio''' program to use the BCM GPIO pin numbering<br />
scheme (otherwise it will use the wiringPi numbering scheme by default)<br />
<br />
The gpio command can also control the internal pull-up and pull-down<br />
resistors:<br />
<br />
<pre><br />
gpio -g mode 17 up<br />
</pre><br />
<br />
This sets the pull-up ressitor - however any change of mode, even<br />
setting a pin that's already set as an input to an input will remove<br />
the pull-up/pull-down resistors, so they may need to be reset.<br />
<br />
Additionally, it can export/un-export the GPIO devices for use by<br />
other non-root programms - e.g. Python scripts. (Although you<br />
may need to drop the calls to GPIO.Setup() in the Python scripts, and<br />
do the setup separately in a little shell script, or call the '''gpio''' program<br />
from inside Python).<br />
<br />
<pre><br />
gpio export 17 out<br />
gpio export 18 in<br />
</pre><br />
<br />
These exports GPIO-17 and sets it to output, and exports GPIO-18<br />
and sets it to input. <br />
<br />
and when done:<br />
<br />
<pre><br />
gpio unexport 17<br />
</pre><br />
<br />
The export/unexport commands always use the BCM GPIO pin numbers regardless of the<br />
presence of the '''-g''' flag or not.<br />
<br />
If you want to use the internal pull-up/down's with the /sys/class/gpio mechanisms,<br />
then you can set them after exporting them. So:<br />
<br />
<pre><br />
gpio -g export 4 in<br />
gpio -g mode 4 up<br />
</pre><br />
<br />
You can then use GPIO-4 as an input in your Python, Shell, Java, etc. programs without the use<br />
of an external resistor to pull the pin high. (If that's what you were after - e.g. a simple push<br />
button switch taking the pin to ground)<br />
<br />
A fully working example of a shell script using the GPIO pins<br />
can be found here:<br />
http://project-downloads.drogon.net/files/gpioExamples/tuxx.sh<br />
<br />
====GPIO Driving Example (C)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
You must also get and install the bcm2835 library, which supports<br />
GPIO and SPI interfaces. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
<br />
<pre><br />
<br />
// blink.c<br />
//<br />
// Example program for bcm2835 library<br />
// Blinks a pin on an off every 0.5 secs<br />
//<br />
// After installing bcm2835, you can build this <br />
// with something like:<br />
// gcc -o blink blink.c -l bcm2835<br />
// sudo ./blink<br />
//<br />
// Or you can test it before installing with:<br />
// gcc -o blink -I ../../src ../../src/bcm2835.c blink.c<br />
// sudo ./blink<br />
//<br />
// Author: Mike McCauley (mikem@open.com.au)<br />
// Copyright (C) 2011 Mike McCauley<br />
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $<br />
<br />
#include <bcm2835.h><br />
<br />
// Blinks on RPi pin GPIO 11<br />
#define PIN RPI_GPIO_P1_11<br />
<br />
int main(int argc, char **argv)<br />
{<br />
// If you call this, it will not actually access the GPIO<br />
// Use for testing<br />
// bcm2835_set_debug(1);<br />
<br />
if (!bcm2835_init())<br />
return 1;<br />
<br />
// Set the pin to be an output<br />
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);<br />
<br />
// Blink<br />
while (1)<br />
{<br />
// Turn it on<br />
bcm2835_gpio_write(PIN, HIGH);<br />
<br />
// wait a bit<br />
delay(500);<br />
<br />
// turn it off<br />
bcm2835_gpio_write(PIN, LOW);<br />
<br />
// wait a bit<br />
delay(500);<br />
}<br />
<br />
return 0;<br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Perl)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo su -</pre><br />
Supports GPIO and SPI interfaces.<br />
You must also get and install the bcm2835 library. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
You must then get and install the Device::BCM2835 perl library from CPAN <br />
http://search.cpan.org/~mikem/Device-BCM2835-1.0/lib/Device/BCM2835.pm<br />
<pre><br />
use Device::BCM2835;<br />
use strict;<br />
<br />
# call set_debug(1) to do a non-destructive test on non-RPi hardware<br />
#Device::BCM2835::set_debug(1);<br />
Device::BCM2835::init() <br />
|| die "Could not init library";<br />
<br />
# Blink pin 11:<br />
# Set RPi pin 11 to be an output<br />
Device::BCM2835::gpio_fsel(&Device::BCM2835::RPI_GPIO_P1_11, <br />
&Device::BCM2835::BCM2835_GPIO_FSEL_OUTP);<br />
<br />
while (1)<br />
{<br />
# Turn it on<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 1);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
# Turn it off<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 0);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
}<br />
<br />
<br />
</pre><br />
<br />
<br />
==== GPIO Driving Example (C#) ====<br />
RaspberryPiDotNet library is available at https://github.com/cypherkey/RaspberryPi.Net/.<br />
The library includes a GPIOFile and GPIOMem class. The GPIOMem requires compiling Mike McCauley's bcm2835 library above in to a shared object.<br />
<br />
<pre><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using RaspberryPiDotNet;<br />
using System.Threading;<br />
<br />
namespace RaspPi<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
// Access the GPIO pin using a static method<br />
GPIOFile.Write(GPIO.GPIOPins.GPIO00, true);<br />
<br />
// Create a new GPIO object<br />
GPIOMem gpio = new GPIOMem(GPIO.GPIOPins.GPIO01);<br />
gpio.Write(false);<br />
}<br />
}<br />
}<br />
</pre><br />
<br />
<br />
====GPIO Driving Example (Ruby)====<br />
<br />
This example uses the WiringPi Ruby Gem: http://pi.gadgetoid.co.uk/post/015-wiringpi-now-with-serial which you can install on your Pi with "gem install wiringpi"<br />
<br />
<pre><br />
MY_PIN = 1<br />
<br />
require 'wiringpi'<br />
io = WiringPi::GPIO.new<br />
io.mode(MY_PIN,OUTPUT)<br />
io.write(MY_PIN,HIGH)<br />
io.read(MY_PIN)<br />
</pre><br />
<br />
==MIPI CSI-2==<br />
<br />
On the production board<ref>http://www.raspberrypi.org/wp-content/uploads/2012/04/Raspberry-Pi-Schematics-R1.0.pdf</ref>, the Raspberry Pi Foundation design brings out the MIPI CSI-2 (Camera Serial Interface<ref>http://www.mipi.org/specifications/camera-interface</ref>) to a 15-way flat flex connector S5, between the Ethernet and HDMI connectors. A compatible camera has been discussed as working in tests and is planned for release at a later date.<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/complex-camera-peripherials#p72602</ref>.<br />
<!-- This is misleading as it implies that cheap cameras from other devices can be used. CSI appears to be a generic interface with secret device-specific requirements so these devices must have drivers to be relevant (and currently only the VideoCore has access to the CSI hardware).<br />
<br />
is Sony sub-LVDS same as MIPI CSI-2? Sony IMX020 5Mbip module is available for $5-7 (SE K850i replacement camera).<br />
<br />
Looks like Nokia N95 uses CSI-2 5Mpix camera module with autofocus. ~$15 replacement part.<br />
--><br />
<br />
==DSI==<br />
<br />
On the production board, the Raspberry Pi Foundation design brings out the DSI (Display Serial Interface<ref>http://www.mipi.org/specifications/display-interface</ref>) to a 15-way flat flex connector labelled S2, next to Raspberry Pi logo. It has two data lanes and a clock lane, to drive a possible future LCD screen device. Some smart phone screens use DSI<ref>http://en.wikipedia.org/wiki/Display_Serial_Interface</ref>.<br />
<br />
==CEC==<br />
<br />
[[CEC (Consumer Electronics Control) over HDMI|HDMI-CEC (Consumer Electronics Control for HDMI)]] is supported by hardware but some driver work will be needed and currently isn't exposed into Linux userland.<br />
Eben notes that he has seen CEC demos on the Broadcom SoC they are using. <br />
<br />
libCEC with Raspberry Pi support has been included in OpenELEC and will be included in Raspbmc RC4.<ref>http://blog.pulse-eight.com/2012/08/01/libcec-1-8-0-a-firmware-upgrade-and-raspberry-pi-support/</ref><br />
<br />
For more information about HDMI-CEC and what you could do with it on the Raspberry Pi please see the [[CEC (Consumer Electronics Control) over HDMI]] article.<br />
<br />
== References ==<br />
<references/><br />
<br />
<br />
{{Template:Raspberry Pi}}</div>MattHawkinsUKhttps://elinux.org/index.php?title=RPi_Low-level_peripherals&diff=168572RPi Low-level peripherals2012-09-10T18:25:21Z<p>MattHawkinsUK: </p>
<hr />
<div>[[Category: RaspberryPi]]<br />
{{Template:RPi_Hardware}}<br />
<br />
<br />
==Introduction==<br />
In addition to the familiar USB, Ethernet and HDMI ports, the R-Pi offers lower-level interfaces intended to connect more directly with chips and subsystem modules. These GPIO (general purpose I/O) signals on the 2x13 header pins include SPI, I2C, serial UART, 3V3 and 5V power. These interfaces are not "plug and play" but require care to avoid miswiring. The pins use a 3V3 logic level and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. Not yet software-enabled are the flex cable connectors with CSI (camera serial interface) and DSI (display serial interface), and a serial link inside the HDMI connector called CEC (consumer electronics control).<br />
<br />
==General Purpose Input/Output (GPIO)==<br />
[[File:GPIOs.png|thumb|254px|right|The layout of the Raspberry Pi GPIOs, colour coded to the table. [https://sites.google.com/site/burngatehouse/home/drawings/GPIOs2.gif Source] ]]<br />
<br />
General Purpose Input/Output (a.k.a. GPIO) is a generic pin on a chip whose behavior (including whether it is an input or output pin) can be controlled (programmed) through software.<br />
<br />
The Raspberry Pi allows peripherals and expansion boards (such as the [[Rpi Gertboard]]) to access the CPU by exposing the inputs and outputs.<br />
<br />
For further general information about GPIOs, see:[http://en.wikipedia.org/wiki/GPIO the wikipedia article].<br />
<br />
The production Raspberry Pi board has a 26-pin 2.54&nbsp;mm (100&nbsp;mil)<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-3/#p31907</ref> expansion header, marked as P1, arranged in a 2x13 strip. They provide 8 GPIO pins plus access to I²C, SPI, UART), as well as +3.3&nbsp;V, +5&nbsp;V and GND supply lines. Pin one is the pin in the first column and on the bottom row. <ref>http://www.raspberrypi.org/archives/384</ref><br />
<br />
'''GPIO voltage levels are 3.3&nbsp;V and are not 5&nbsp;V tolerant. There is no over-voltage protection on the board''' - the intention is that people interested in serious interfacing will use an external board with buffers, level conversion and analog I/O rather than soldering directly onto the main board.<br />
<br />
All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so. At reset only pins GPIO 14 & 15 are assigned to the alternate function UART, these two can be switched back to GPIO to provide a total of 17 GPIO pins<ref>http://www.raspberrypi.org/archives/384</ref>. Each of their functions and full details of how to access are detailed in the chipset datasheet <ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref>.<br />
<br />
Each GPIO can interrupt, high/low/rise/fall/change.<ref>http://www.raspberrypi.org/archives/384#comment-5217</ref><ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref> There is currently no support for GPIO interrupts in the official kernel, howewer a patch exists, requiring compilation of modified source tree.<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=7509</ref><br />
<br />
GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited, and source and sink current is configurable from 2&nbsp;mA up to 16&nbsp;mA. Note that chipset GPIO pins 0-27 are in the same block and these properties are set per block, not per pin. See [http://www.scribd.com/doc/101830961/GPIO-Pads-Control2 GPIO Datasheet Addendum - GPIO Pads Control]. Particular attention should be applied to the note regarding SSO (Simultaneous Switching Outputs): to avoid interference, driving currents should be kept as low as possible.<br />
<br />
The available [[RPi_BCM2835_GPIOs|alternative functions]] and their corresponding pins are detailed below. These numbers are in reference to the chipset documentation and may not match the numbers exposed in Linux. Only fully usable functions are detailed, for some alternative functions not all the necessary pins are available for the funtionality to be actually used.<br />
<br />
There is also some information on the [[RPi Tutorial Easy GPIO Hardware & Software|Tutorial on Easy GPIO Hardware & Software]].<br />
<br />
Kernel boot messages go to the [[RPi_Serial_Connection|UART]] at 115200&nbsp;bit/s.<br />
<br />
'''R-Pi PCB Revision 2 UPDATE:''' According to Eben at [http://www.raspberrypi.org/archives/1929#comments] the R-Pi Rev.2 board being rolled out starting in September 2012 adds 4 more GPIO on a new connector called P5, and changes some of the existing P1 GPIO pinouts. On Rev2, GPIO_GEN2 [BCM2835/GPIO27] is routed to P1 pin 13, and changes what was SCL0/SDA0 to SCL1/SDA1: SCL1 [BCM2835/GPIO3] is routed to P1 pin 5, SDA1 [BCM2835/GPIO2] is routed to P1 pin 3. Also the power and ground connections previously marked "Do Not Connect" on P1 will remain as connected, specifically:<br />
P1-04: +5V0<br />
P1-09: GND<br />
P1-14: GND<br />
P1-17: +3V3<br />
P1-20: GND<br />
P1-25: GND<br />
<br />
'''Header Pinout, top row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-02 || bgcolor="red" | <span style="color:white">5V0</span> || bgcolor="red" | <span style="color:white">5V0</span> || Supply through input poly fuse<br />
|-<br />
| P1-04 || DNC<br />
|-<br />
| P1-06 || bgcolor="black" | <span style="color:white">GND</span> || bgcolor="black" | <span style="color:white">GND</span> <br />
|-<br />
|-<br />
| P1-08 || bgcolor="lime" | GPIO 14 || bgcolor="lime" | GPIO 14 || Boot to Alt 0 -> || bgcolor="yellow" | UART0_TXD || ALT5 = UART1_TXD<br />
|-<br />
| P1-10 || bgcolor="lime" | GPIO 15 ||bgcolor="lime" | GPIO 15 || Boot to Alt 0 -> ||bgcolor="yellow" | UART0_RXD || ALT5 = UART1_RXD<br />
|-<br />
| P1-12 || bgcolor="lime" | GPIO 18 ||bgcolor="lime" | GPIO 18 || || || ALT4 SPI1_CE0_N ALT5 = PWM0<br />
|-<br />
| P1-14 || DNC<br />
|-<br />
| P1-16 || bgcolor="lime" | GPIO23 ||bgcolor="lime" | GPIO23 || || || ALT3 = SD1_CMD ALT4 = ARM_RTCK<br />
|-<br />
| P1-18 || bgcolor="lime" | GPIO24 ||bgcolor="lime" | GPIO24 || || || ALT3 = SD1_DATA0 ALT4 = ARM_TDO<br />
|-<br />
| P1-20 || DNC<br />
|-<br />
| P1-22 || bgcolor="lime" | GPIO25 ||bgcolor="lime" | GPIO25 || || || ALT4 = ARM_TCK<br />
|-<br />
| P1-24 || bgcolor="lime" | GPIO08 ||bgcolor="lime" | GPIO08 || || bgcolor="purple" | <span style="color:white">SPI0_CE0_N</span> ||<br />
|-<br />
| P1-26 || bgcolor="lime" | GPIO07 ||bgcolor="lime" | GPIO07 || || bgcolor="purple" | <span style="color:white">SPI0_CE1_N</span> || <br />
|}<br />
<br />
<br />
'''Header Pinout, bottom row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-01 || bgcolor="orange" | 3.3&nbsp;V ||bgcolor="orange" | 3.3&nbsp;V || 50&nbsp;mA max current draw<br />
|-<br />
| P1-03 || bgcolor="lime" | GPIO 0 ||bgcolor="lime" | GPIO 2|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SDA || I2C0_SDA / I2C1_SDA<br />
|-<br />
| P1-05 || bgcolor="lime" | GPIO 1 ||bgcolor="lime" | GPIO 3|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SCL || I2C0_SCL / I2C1_SCL <br />
|-<br />
| P1-07 || bgcolor="lime" | GPIO 4 ||bgcolor="lime" | GPIO 4 || || || bgcolor="lime" | GPCLK0<br />
|-<br />
| P1-09 || DNC<br />
|-<br />
| P1-11 || bgcolor="lime" | GPIO17 || bgcolor="lime" | GPIO17 || || ||| ALT3 = UART0_RTS, ALT5 = UART1_RTS<br />
|-<br />
| P1-13 || bgcolor="lime" | GPIO21 || bgcolor="lime" | GPIO27 || || PCM_DIN || ALT5 = GPCLK1<br />
|-<br />
| P1-15 || bgcolor="lime" | GPIO22 || bgcolor="lime" | GPIO22 || || || ALT3 = SD1_CLK ALT4 = ARM_TRST<br />
|-<br />
| P1-17 || DNC<br />
|-<br />
| P1-19 || bgcolor="lime" | GPIO10 || bgcolor="lime" | GPIO10 || || bgcolor="purple" | <span style="color:white">SPI0_MOSI</span> || <br />
|-<br />
| P1-21 || bgcolor="lime" | GPIO9 || bgcolor="lime" | GPIO9 || || bgcolor="purple" | <span style="color:white">SPI0_MISO</span> ||<br />
|-<br />
| P1-23 || bgcolor="lime" | GPIO11 || bgcolor="lime" | GPIO11 || || bgcolor="purple" | <span style="color:white">SPI0_SCLK</span> || <br />
|-<br />
| P1-25 || DNC<br />
|}<br />
<br />
<br />
{| border="1"<br />
! Colour legend<br />
|-<br />
| bgcolor="red" | <span style="color:white">+5&nbsp;V</span><br />
|-<br />
| bgcolor="orange" | +3.3&nbsp;V<br />
|-<br />
| bgcolor="black" | <span style="color:white">Ground, 0V</span> <br />
|-<br />
| Do not connect<br />
|-<br />
| bgcolor="yellow" | UART<br />
|-<br />
| bgcolor="lime" | GPIO<br />
|-<br />
| bgcolor="purple" | <span style="color:white">SPI</span><br />
|-<br />
| bgcolor="cyan" | I²C<br />
|}<br />
<br />
KiCad symbol: [[File:Conn-raspberry.lib]]<br />
<br />
<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/gpio-header-pinout-clarification/page-2</ref><br />
<br />
Pin 3 (SDA0) and Pin 5 (SCL0) are preset to be used as an I²C interface. So there are 1.8&nbsp;kilohm pulls up resistors on the board for these pins.<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-6/#p56480</ref><br />
<br />
Pin 12 supports PWM.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-7, 15, 16, 18, 22 (chipset GPIOs 4 and 22 to 25) to provide an ARM JTAG interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.1</ref> However ARM_TMS isn't available on the GPIO connector (chipset pin 12 or 27 is needed). Chipset pin 27 is available on S5, the CSI camera interface however.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-12 and 13 (chipset GPIO 18 and 21) to provide an I2S (a hardware modification may be required<ref name="I2S">[http://www.raspberrypi.org/forum/features-and-requests/sad-about-removal-of-i2s-why-was-this-change-made Forum:Sad about removal of I2S. Why was this change made?]</ref>) or PCM interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.2</ref> However, PCM_FS and PCM_DIN (chipset pins 19 and 20) are needed for I2S or PCM.<br />
<br />
A second I²C interface (GPIO02_ALT0 is SDA1 and GPIO03_ALT0 is SCL1) and two further GPIOs (GPIO05_ALT0 is GPCLK1, and GPIO27) are available on S5, the CSI camera interface.<br />
<br />
===A note about GPIO vs the schematic===<br />
<br />
You may notice that the GPIO connector as documented in the schematic does NOT match with what is on this wiki page. Do NOT update this wiki page. The pins which are marked as DNC should not be used in order to be compatible with possible future designs. The plan is that if a new design comes along and if the layout permits it we will connect additional GPIO pins to those DNC pins. (Gert's first vote is for GPIO 19 and 20. That gives us the second PWM, second SPI, I2S/PCM, slave I²C and slave SPI.)<br />
<br />
===Referring to pins on the Expansion header===<br />
<br />
The header is referred to as "The GPIO Connector (P1)". To avoid nomenclature confusion between Broadcom signal names on the SoC and pin names on the expansion header, the following naming is highly recommended.<br />
<br />
* The expansion header is referred to as "Expansion Header" or "GPIO Connector (P1)"<br />
* Pins on the GPIO connector (P1) are referred to as P1-01, etc.<br />
* Names GPIO0, GPIO1, GPIOx-ALTy, etc. refer to the signal names on the SoC as enumerated in the Broadcom datasheet, where "x" matches BCM2835 number (without leading zero) and "y" is the alternate number column 0 to 5 on page 102-103 of the Broadcom document. For example, depending on what you are describing, use either "GPIO7" to refer to a row of the table, and "GPIO7-ALT0" would refer to a specific cell of the table.<br />
* When refering to signal names, you should modify the Broadcom name slightly to minimize confusion. The Broadcom SPI bus pin names are fine, such as "SPI0_*" and "SPI1_*", but they didn't do the same on the I²C and UART pins. Instead of using "SDA0" and "SCL0", you should use "I2C0_SDA" and "I2C0_SCL"; and instead of "TX" or "TXD" and "RX" or "RXD", you should use "UART0_TXD" and "UART0_RXD".<br />
<br />
===Power pins===<br />
The maximum permitted current draw from the 3.3&nbsp;V pin is 50&nbsp;mA.<br />
<br />
Maximum permitted current draw from the 5&nbsp;V pin is the USB input current (usually 1&nbsp;A) minus any current draw from the rest of the board.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1536#postid-21841</ref><br />
*Model A: 1000&nbsp;mA - 500&nbsp;mA -> max current draw: 500&nbsp;mA<br />
*Model B: 1000&nbsp;mA - 700&nbsp;mA -> max current draw: 300&nbsp;mA<br />
Be very careful with the 5&nbsp;V pin, because if you short it to any other P1 pin you may permanently damage your RasPi. Before probing P1, it's a good idea to strip a short piece of insulation off a wire and push it over the 5&nbsp;V pin so you don't accidentally touch it with a probe.<br />
<br />
=== GPIO hardware hacking ===<br />
<br />
The complete list of [[RPi_BCM2835_GPIOs|chipset GPIO pins]] which are available on the GPIO connector is: <blockquote>[[RPi_BCM2835_GPIOs#GPIO0|0]], [[RPi_BCM2835_GPIOs#GPIO1|1]], [[RPi_BCM2835_GPIOs#GPIO4|4]], [[RPi_BCM2835_GPIOs#GPIO7|7]], [[RPi_BCM2835_GPIOs#GPIO8|8]], [[RPi_BCM2835_GPIOs#GPIO9|9]], [[RPi_BCM2835_GPIOs#GPIO10|10]], [[RPi_BCM2835_GPIOs#GPIO11|11]], [[RPi_BCM2835_GPIOs#GPIO14|14]], [[RPi_BCM2835_GPIOs#GPIO15|15]], [[RPi_BCM2835_GPIOs#GPIO17|17]], [[RPi_BCM2835_GPIOs#GPIO18|18]], [[RPi_BCM2835_GPIOs#GPIO21|21]], [[RPi_BCM2835_GPIOs#GPIO22|22]], [[RPi_BCM2835_GPIOs#GPIO23|23]], [[RPi_BCM2835_GPIOs#GPIO24|24]], [[RPi_BCM2835_GPIOs#GPIO25|25]]</blockquote><br />
<br />
As noted above, GPIO00 and 01 (SDA0 and SCL0) have 1.8&nbsp;kilohm pull-up resistors to 3.3&nbsp;V.<br />
<br />
If 17 GPIOs aren't sufficient for your project, there are a few other signals potentially available, with varying levels of software and hardware (soldering iron) hackery skills:<br />
<br />
GPIO02, 03, 05 and 27 are available on S5 (the CSI interface) when a camera peripheral is not connected to that socket, and are configured by default to provide the functions SDA1, SCL1, CAM_CLK and CAM_GPIO respectively. SDA1 and SCL1 have 1K6 pull-up resistors to 3.3&nbsp;V.<br />
<br />
GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function.<br />
<br />
There are a few other chipset GPIO pins accessible on the PCB but are in use:<br />
<br />
* GPIO16 drives status LED D5 (usually SD card access indicator)<br />
* GPIO28-31 are used by the board ID and are connected to resistors R3 to R10.<br />
* GPIO40 and 45 are used by analogue audio and support PWM. They connect to the analogue audio circuitry via R21 and R27 respectively.<br />
* GPIO46 is HDMI hotplug detect (goes to pin 6 of IC1).<br />
* GPIO47 to 53 are used by the SD card interface. In particular, GPIO47 is SD card detect (this would seem to be a good candidate for re-use). GPIO47 is connected to the SD card interface card detect switch; GPIO48 to 53 are connected to the SD card interface via resistors R45 to R50.<br />
<br />
=== P2 header ===<br />
<br />
The P2 header is the VideoCore JTAG and used only during the production of the board. It cannot be used as the ARM JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>.<br />
<br />
Useful P2 pins:<br />
<br />
* Pin 1 - 3.3V (same as P1-01, 50 mA max current draw across both of them)<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
=== P3 header ===<br />
<br />
The P3 header, unpopulated, is the LAN9512 JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>.<br />
<br />
=== P5 header ===<br />
<br />
The P5 header was added with the release of the Revision 2.0 PCB design.<br />
<br />
* Pin 1 - 5V<br />
* Pin 2 - 3V3<br />
* Pin 3 - GPIO (TBA)<br />
* Pin 4 - GPIO (TBA)<br />
* Pin 5 - GPIO (TBA)<br />
* Pin 6 - GPIO (TBA)<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
===Driver support===<br />
<br />
The Foundation will not include a GPIO driver in the initial release, standard Linux GPIO drivers should work with minimal modification.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1278.0</ref><br />
<br />
The community implemented SPI and I²C drivers <ref>http://www.bootc.net/projects/raspberry-pi-kernel/</ref>, which will be integrated with the new Linux pinctrl concept in a later version of the kernel. A first compiled version as Linux modules is available to install on the 19/04/2012 Debian image, including 1-wire support<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?p=86172#p86172</ref>. The I²C and SPI driver uses the hardware modules of the microcontroller and interrupts for low CPU usage, the 1-wire support uses bitbanging on the GPIO ports, which results in higher CPU usage.<br />
<br />
GordonH<ref>http://www.raspberrypi.org/forum/general-discussion/wiring-for-the-raspberry-pis-gpio</ref> wrote a (mostly) Arduino compatible/style [https://projects.drogon.net/raspberry-pi/wiringpi/ WiringPi library] in C for controlling the GPIO pins.<br />
<br />
A useful tutorial on setting up I²C driver support can be found at [http://www.robot-electronics.co.uk/htm/raspberry_pi_examples.htm Robot Electronics] - look for the downloadable document rpi_i2c_setup.doc<br />
<br />
===Graphical User Interfaces===<br />
====WebIOPi====<br />
[http://code.google.com/p/webiopi/ WebIOPi] allows you to control each GPIO with a simple web interface that you can use with any browser. Available in PHP and Python, they both require root access, but Python version serves HTTP itself. You can setup each GPIO as input or output and change their states (LOW/HIGH). WebIOPi is fully customizable, so you can use it for home remote control. It also work over Internet. UART/SPI/I2C support will be added later. If you need some computing for your GPIO go to code examples below.<br />
<br />
===Code examples===<br />
====GPIO Driving Example (C)====<br />
[http://www.raspberrypi.org/forum/educational-applications/gertboard/page-4/#p31555 Gert van Loo & Dom, has provided] some tested code which accesses the GPIO pins through direct GPIO register manipulation in C-code.<br />
(Thanks to Dom for doing the difficult work of finding and testing the mapping.)<br />
Example GPIO code:<br />
<br />
<pre><br />
//<br />
// How to access GPIO registers from C-code on the Raspberry-Pi<br />
// Example program<br />
// 15-January-2012<br />
// Dom and Gert<br />
//<br />
<br />
<br />
// Access from ARM Running Linux<br />
<br />
#define BCM2708_PERI_BASE 0x20000000<br />
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */<br />
<br />
<br />
#include <stdio.h><br />
#include <string.h><br />
#include <stdlib.h><br />
#include <dirent.h><br />
#include <fcntl.h><br />
#include <assert.h><br />
#include <sys/mman.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
<br />
#include <unistd.h><br />
<br />
#define PAGE_SIZE (4*1024)<br />
#define BLOCK_SIZE (4*1024)<br />
<br />
int mem_fd;<br />
char *gpio_mem, *gpio_map;<br />
char *spi0_mem, *spi0_map;<br />
<br />
<br />
// I/O access<br />
volatile unsigned *gpio;<br />
<br />
<br />
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)<br />
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))<br />
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))<br />
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))<br />
<br />
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0<br />
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0<br />
<br />
void setup_io();<br />
<br />
int main(int argc, char **argv)<br />
{ <br />
int g,rep;<br />
<br />
// Set up gpi pointer for direct register access<br />
setup_io();<br />
<br />
// Switch GPIO 7..11 to output mode<br />
<br />
/************************************************************************\<br />
* You are about to change the GPIO settings of your computer. *<br />
* Mess this up and it will stop working! *<br />
* It might be a good idea to 'sync' before running this program *<br />
* so at least you still have your code changes written to the SD-card! *<br />
\************************************************************************/<br />
<br />
// Set GPIO pins 7-11 to output<br />
for (g=7; g<=11; g++)<br />
{<br />
INP_GPIO(g); // must use INP_GPIO before we can use OUT_GPIO<br />
OUT_GPIO(g);<br />
}<br />
<br />
for (rep=0; rep<10; rep++)<br />
{<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_SET = 1<<g;<br />
sleep(1);<br />
}<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_CLR = 1<<g;<br />
sleep(1);<br />
}<br />
}<br />
<br />
return 0;<br />
<br />
} // main<br />
<br />
<br />
//<br />
// Set up a memory regions to access GPIO<br />
//<br />
void setup_io()<br />
{<br />
/* open /dev/mem */<br />
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {<br />
printf("can't open /dev/mem \n");<br />
exit (-1);<br />
}<br />
<br />
/* mmap GPIO */<br />
<br />
// Allocate MAP block<br />
if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {<br />
printf("allocation error \n");<br />
exit (-1);<br />
}<br />
<br />
// Make sure pointer is on 4K boundary<br />
if ((unsigned long)gpio_mem % PAGE_SIZE)<br />
gpio_mem += PAGE_SIZE - ((unsigned long)gpio_mem % PAGE_SIZE);<br />
<br />
// Now map it<br />
gpio_map = (unsigned char *)mmap(<br />
(caddr_t)gpio_mem,<br />
BLOCK_SIZE,<br />
PROT_READ|PROT_WRITE,<br />
MAP_SHARED|MAP_FIXED,<br />
mem_fd,<br />
GPIO_BASE<br />
);<br />
<br />
if ((long)gpio_map < 0) {<br />
printf("mmap error %d\n", (int)gpio_map);<br />
exit (-1);<br />
}<br />
<br />
// Always use volatile pointer!<br />
gpio = (volatile unsigned *)gpio_map;<br />
<br />
<br />
} // setup_io<br />
<br />
</pre><br />
<br />
====GPIO Pull Up/Pull Down Register Example====<br />
<pre><br />
// enable pull-up on GPIO24&25<br />
GPIO_PULL = 2;<br />
short_wait();<br />
// clock on GPIO 24 & 25 (bit 24 & 25 set)<br />
GPIO_PULLCLK0 = 0x03000000;<br />
short_wait();<br />
GPIO_PULL = 0;<br />
GPIO_PULLCLK0 = 0;<br />
</pre><br />
<br />
====GPIO Driving Example (Python)====<br />
This uses the Python module available at http://pypi.python.org/pypi/RPi.GPIO<br />
Any Python script that controls GPIO must be run as root.<br />
<pre>import RPi.GPIO as GPIO<br />
<br />
# Set up the GPIO channels - one input and one output<br />
GPIO.setup(11, GPIO.IN)<br />
GPIO.setup(12, GPIO.OUT)<br />
<br />
# Input from pin 11<br />
input_value = GPIO.input(11)<br />
<br />
# Output to pin 12<br />
GPIO.output(12, True)<br />
<br />
# The same script as above but using BCM GPIO 00..nn numbers<br />
GPIO.setmode(GPIO.BCM)<br />
GPIO.setup(17, GPIO.IN)<br />
GPIO.setup(18, GPIO.OUT)<br />
input_value = GPIO.input(17)<br />
GPIO.output(18, True)</pre><br />
<br />
====GPIO Driving Example (Java)====<br />
This uses the Java library available at http://code.google.com/p/rpi-gpio-java/. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
public static void main(String[] args) {<br />
GpioGateway gpio = new GpioGatewayImpl();<br />
<br />
//set up the GPIO channels - one input and one output<br />
gpio.setup(Boardpin.PIN11_GPIO17, Direction.IN);<br />
gpio.setup(Boardpin.PIN12_GPIO18, Direction.OUT);<br />
<br />
// input from pin 11<br />
boolean input_value = gpio.getValue(Boardpin.PIN11_GPIO17);<br />
<br />
// output to pin 12<br />
gpio.setValue(Boardpin.PIN12_GPIO18, true); <br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Java webapp via http)====<br />
This uses the Java webapp available at https://bitbucket.org/sbub/rpi-gpio-webapp. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
host:~ sb$ curl 'http://raspberrypi:8080/handle?g0=1&g1=0'<br />
{"g1":0,"g0":1}<br />
<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
<pre><br />
#!/bin/sh<br />
<br />
# GPIO numbers should be from this list<br />
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25<br />
<br />
# Note that the GPIO numbers that you program here refer to the pins<br />
# of the BCM2835 and *not* the numbers on the pin header. <br />
# So, if you want to activate GPIO7 on the header you should be <br />
# using GPIO4 in this script. Likewise if you want to activate GPIO0<br />
# on the header you should be using GPIO17 here.<br />
<br />
# Set up GPIO 4 and set to output<br />
echo "4" > /sys/class/gpio/export<br />
echo "out" > /sys/class/gpio/gpio4/direction<br />
<br />
# Set up GPIO 7 and set to input<br />
echo "7" > /sys/class/gpio/export<br />
echo "in" > /sys/class/gpio/gpio7/direction<br />
<br />
# Write output<br />
echo "1" > /sys/class/gpio/gpio4/value<br />
<br />
# Read from input<br />
cat /sys/class/gpio/gpio7/value <br />
<br />
# Clean up<br />
echo "4" > /sys/class/gpio/unexport<br />
echo "7" > /sys/class/gpio/unexport<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script - take 2)====<br />
You need the wiringPi library from<br />
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/<br />
once installed there is a new command '''gpio''' which can be used<br />
as a '''non-root''' user to control the GPIO pins.<br />
<br />
The man page <pre>man gpio</pre> has full details, but briefly:<br />
<br />
<pre><br />
gpio -g mode 17 out<br />
gpio -g mode 18 pwm<br />
<br />
gpio -g write 17 1<br />
gpio -g pwm 18 512<br />
</pre><br />
<br />
the '''-g''' flag tells the '''gpio''' program to use the BCM GPIO pin numbering<br />
scheme (otherwise it will use the wiringPi numbering scheme by default)<br />
<br />
The gpio command can also control the internal pull-up and pull-down<br />
resistors:<br />
<br />
<pre><br />
gpio -g mode 17 up<br />
</pre><br />
<br />
This sets the pull-up ressitor - however any change of mode, even<br />
setting a pin that's already set as an input to an input will remove<br />
the pull-up/pull-down resistors, so they may need to be reset.<br />
<br />
Additionally, it can export/un-export the GPIO devices for use by<br />
other non-root programms - e.g. Python scripts. (Although you<br />
may need to drop the calls to GPIO.Setup() in the Python scripts, and<br />
do the setup separately in a little shell script, or call the '''gpio''' program<br />
from inside Python).<br />
<br />
<pre><br />
gpio export 17 out<br />
gpio export 18 in<br />
</pre><br />
<br />
These exports GPIO-17 and sets it to output, and exports GPIO-18<br />
and sets it to input. <br />
<br />
and when done:<br />
<br />
<pre><br />
gpio unexport 17<br />
</pre><br />
<br />
The export/unexport commands always use the BCM GPIO pin numbers regardless of the<br />
presence of the '''-g''' flag or not.<br />
<br />
If you want to use the internal pull-up/down's with the /sys/class/gpio mechanisms,<br />
then you can set them after exporting them. So:<br />
<br />
<pre><br />
gpio -g export 4 in<br />
gpio -g mode 4 up<br />
</pre><br />
<br />
You can then use GPIO-4 as an input in your Python, Shell, Java, etc. programs without the use<br />
of an external resistor to pull the pin high. (If that's what you were after - e.g. a simple push<br />
button switch taking the pin to ground)<br />
<br />
A fully working example of a shell script using the GPIO pins<br />
can be found here:<br />
http://project-downloads.drogon.net/files/gpioExamples/tuxx.sh<br />
<br />
====GPIO Driving Example (C)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
You must also get and install the bcm2835 library, which supports<br />
GPIO and SPI interfaces. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
<br />
<pre><br />
<br />
// blink.c<br />
//<br />
// Example program for bcm2835 library<br />
// Blinks a pin on an off every 0.5 secs<br />
//<br />
// After installing bcm2835, you can build this <br />
// with something like:<br />
// gcc -o blink blink.c -l bcm2835<br />
// sudo ./blink<br />
//<br />
// Or you can test it before installing with:<br />
// gcc -o blink -I ../../src ../../src/bcm2835.c blink.c<br />
// sudo ./blink<br />
//<br />
// Author: Mike McCauley (mikem@open.com.au)<br />
// Copyright (C) 2011 Mike McCauley<br />
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $<br />
<br />
#include <bcm2835.h><br />
<br />
// Blinks on RPi pin GPIO 11<br />
#define PIN RPI_GPIO_P1_11<br />
<br />
int main(int argc, char **argv)<br />
{<br />
// If you call this, it will not actually access the GPIO<br />
// Use for testing<br />
// bcm2835_set_debug(1);<br />
<br />
if (!bcm2835_init())<br />
return 1;<br />
<br />
// Set the pin to be an output<br />
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);<br />
<br />
// Blink<br />
while (1)<br />
{<br />
// Turn it on<br />
bcm2835_gpio_write(PIN, HIGH);<br />
<br />
// wait a bit<br />
delay(500);<br />
<br />
// turn it off<br />
bcm2835_gpio_write(PIN, LOW);<br />
<br />
// wait a bit<br />
delay(500);<br />
}<br />
<br />
return 0;<br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Perl)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo su -</pre><br />
Supports GPIO and SPI interfaces.<br />
You must also get and install the bcm2835 library. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
You must then get and install the Device::BCM2835 perl library from CPAN <br />
http://search.cpan.org/~mikem/Device-BCM2835-1.0/lib/Device/BCM2835.pm<br />
<pre><br />
use Device::BCM2835;<br />
use strict;<br />
<br />
# call set_debug(1) to do a non-destructive test on non-RPi hardware<br />
#Device::BCM2835::set_debug(1);<br />
Device::BCM2835::init() <br />
|| die "Could not init library";<br />
<br />
# Blink pin 11:<br />
# Set RPi pin 11 to be an output<br />
Device::BCM2835::gpio_fsel(&Device::BCM2835::RPI_GPIO_P1_11, <br />
&Device::BCM2835::BCM2835_GPIO_FSEL_OUTP);<br />
<br />
while (1)<br />
{<br />
# Turn it on<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 1);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
# Turn it off<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 0);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
}<br />
<br />
<br />
</pre><br />
<br />
<br />
==== GPIO Driving Example (C#) ====<br />
RaspberryPiDotNet library is available at https://github.com/cypherkey/RaspberryPi.Net/.<br />
The library includes a GPIOFile and GPIOMem class. The GPIOMem requires compiling Mike McCauley's bcm2835 library above in to a shared object.<br />
<br />
<pre><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using RaspberryPiDotNet;<br />
using System.Threading;<br />
<br />
namespace RaspPi<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
// Access the GPIO pin using a static method<br />
GPIOFile.Write(GPIO.GPIOPins.GPIO00, true);<br />
<br />
// Create a new GPIO object<br />
GPIOMem gpio = new GPIOMem(GPIO.GPIOPins.GPIO01);<br />
gpio.Write(false);<br />
}<br />
}<br />
}<br />
</pre><br />
<br />
<br />
====GPIO Driving Example (Ruby)====<br />
<br />
This example uses the WiringPi Ruby Gem: http://pi.gadgetoid.co.uk/post/015-wiringpi-now-with-serial which you can install on your Pi with "gem install wiringpi"<br />
<br />
<pre><br />
MY_PIN = 1<br />
<br />
require 'wiringpi'<br />
io = WiringPi::GPIO.new<br />
io.mode(MY_PIN,OUTPUT)<br />
io.write(MY_PIN,HIGH)<br />
io.read(MY_PIN)<br />
</pre><br />
<br />
==MIPI CSI-2==<br />
<br />
On the production board<ref>http://www.raspberrypi.org/wp-content/uploads/2012/04/Raspberry-Pi-Schematics-R1.0.pdf</ref>, the Raspberry Pi Foundation design brings out the MIPI CSI-2 (Camera Serial Interface<ref>http://www.mipi.org/specifications/camera-interface</ref>) to a 15-way flat flex connector S5, between the Ethernet and HDMI connectors. A compatible camera has been discussed as working in tests and is planned for release at a later date.<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/complex-camera-peripherials#p72602</ref>.<br />
<!-- This is misleading as it implies that cheap cameras from other devices can be used. CSI appears to be a generic interface with secret device-specific requirements so these devices must have drivers to be relevant (and currently only the VideoCore has access to the CSI hardware).<br />
<br />
is Sony sub-LVDS same as MIPI CSI-2? Sony IMX020 5Mbip module is available for $5-7 (SE K850i replacement camera).<br />
<br />
Looks like Nokia N95 uses CSI-2 5Mpix camera module with autofocus. ~$15 replacement part.<br />
--><br />
<br />
==DSI==<br />
<br />
On the production board, the Raspberry Pi Foundation design brings out the DSI (Display Serial Interface<ref>http://www.mipi.org/specifications/display-interface</ref>) to a 15-way flat flex connector labelled S2, next to Raspberry Pi logo. It has two data lanes and a clock lane, to drive a possible future LCD screen device. Some smart phone screens use DSI<ref>http://en.wikipedia.org/wiki/Display_Serial_Interface</ref>.<br />
<br />
==CEC==<br />
<br />
[[CEC (Consumer Electronics Control) over HDMI|HDMI-CEC (Consumer Electronics Control for HDMI)]] is supported by hardware but some driver work will be needed and currently isn't exposed into Linux userland.<br />
Eben notes that he has seen CEC demos on the Broadcom SoC they are using. <br />
<br />
libCEC with Raspberry Pi support has been included in OpenELEC and will be included in Raspbmc RC4.<ref>http://blog.pulse-eight.com/2012/08/01/libcec-1-8-0-a-firmware-upgrade-and-raspberry-pi-support/</ref><br />
<br />
For more information about HDMI-CEC and what you could do with it on the Raspberry Pi please see the [[CEC (Consumer Electronics Control) over HDMI]] article.<br />
<br />
== References ==<br />
<references/><br />
<br />
<br />
{{Template:Raspberry Pi}}</div>MattHawkinsUKhttps://elinux.org/index.php?title=RPi_Low-level_peripherals&diff=168566RPi Low-level peripherals2012-09-10T18:25:01Z<p>MattHawkinsUK: Added section for new P5 header</p>
<hr />
<div>[[Category: RaspberryPi]]<br />
{{Template:RPi_Hardware}}<br />
<br />
<br />
==Introduction==<br />
In addition to the familiar USB, Ethernet and HDMI ports, the R-Pi offers lower-level interfaces intended to connect more directly with chips and subsystem modules. These GPIO (general purpose I/O) signals on the 2x13 header pins include SPI, I2C, serial UART, 3V3 and 5V power. These interfaces are not "plug and play" but require care to avoid miswiring. The pins use a 3V3 logic level and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. Not yet software-enabled are the flex cable connectors with CSI (camera serial interface) and DSI (display serial interface), and a serial link inside the HDMI connector called CEC (consumer electronics control).<br />
<br />
==General Purpose Input/Output (GPIO)==<br />
[[File:GPIOs.png|thumb|254px|right|The layout of the Raspberry Pi GPIOs, colour coded to the table. [https://sites.google.com/site/burngatehouse/home/drawings/GPIOs2.gif Source] ]]<br />
<br />
General Purpose Input/Output (a.k.a. GPIO) is a generic pin on a chip whose behavior (including whether it is an input or output pin) can be controlled (programmed) through software.<br />
<br />
The Raspberry Pi allows peripherals and expansion boards (such as the [[Rpi Gertboard]]) to access the CPU by exposing the inputs and outputs.<br />
<br />
For further general information about GPIOs, see:[http://en.wikipedia.org/wiki/GPIO the wikipedia article].<br />
<br />
The production Raspberry Pi board has a 26-pin 2.54&nbsp;mm (100&nbsp;mil)<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-3/#p31907</ref> expansion header, marked as P1, arranged in a 2x13 strip. They provide 8 GPIO pins plus access to I²C, SPI, UART), as well as +3.3&nbsp;V, +5&nbsp;V and GND supply lines. Pin one is the pin in the first column and on the bottom row. <ref>http://www.raspberrypi.org/archives/384</ref><br />
<br />
'''GPIO voltage levels are 3.3&nbsp;V and are not 5&nbsp;V tolerant. There is no over-voltage protection on the board''' - the intention is that people interested in serious interfacing will use an external board with buffers, level conversion and analog I/O rather than soldering directly onto the main board.<br />
<br />
All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so. At reset only pins GPIO 14 & 15 are assigned to the alternate function UART, these two can be switched back to GPIO to provide a total of 17 GPIO pins<ref>http://www.raspberrypi.org/archives/384</ref>. Each of their functions and full details of how to access are detailed in the chipset datasheet <ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref>.<br />
<br />
Each GPIO can interrupt, high/low/rise/fall/change.<ref>http://www.raspberrypi.org/archives/384#comment-5217</ref><ref>http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</ref> There is currently no support for GPIO interrupts in the official kernel, howewer a patch exists, requiring compilation of modified source tree.<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=7509</ref><br />
<br />
GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited, and source and sink current is configurable from 2&nbsp;mA up to 16&nbsp;mA. Note that chipset GPIO pins 0-27 are in the same block and these properties are set per block, not per pin. See [http://www.scribd.com/doc/101830961/GPIO-Pads-Control2 GPIO Datasheet Addendum - GPIO Pads Control]. Particular attention should be applied to the note regarding SSO (Simultaneous Switching Outputs): to avoid interference, driving currents should be kept as low as possible.<br />
<br />
The available [[RPi_BCM2835_GPIOs|alternative functions]] and their corresponding pins are detailed below. These numbers are in reference to the chipset documentation and may not match the numbers exposed in Linux. Only fully usable functions are detailed, for some alternative functions not all the necessary pins are available for the funtionality to be actually used.<br />
<br />
There is also some information on the [[RPi Tutorial Easy GPIO Hardware & Software|Tutorial on Easy GPIO Hardware & Software]].<br />
<br />
Kernel boot messages go to the [[RPi_Serial_Connection|UART]] at 115200&nbsp;bit/s.<br />
<br />
'''R-Pi PCB Revision 2 UPDATE:''' According to Eben at [http://www.raspberrypi.org/archives/1929#comments] the R-Pi Rev.2 board being rolled out starting in September 2012 adds 4 more GPIO on a new connector called P5, and changes some of the existing P1 GPIO pinouts. On Rev2, GPIO_GEN2 [BCM2835/GPIO27] is routed to P1 pin 13, and changes what was SCL0/SDA0 to SCL1/SDA1: SCL1 [BCM2835/GPIO3] is routed to P1 pin 5, SDA1 [BCM2835/GPIO2] is routed to P1 pin 3. Also the power and ground connections previously marked "Do Not Connect" on P1 will remain as connected, specifically:<br />
P1-04: +5V0<br />
P1-09: GND<br />
P1-14: GND<br />
P1-17: +3V3<br />
P1-20: GND<br />
P1-25: GND<br />
<br />
'''Header Pinout, top row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-02 || bgcolor="red" | <span style="color:white">5V0</span> || bgcolor="red" | <span style="color:white">5V0</span> || Supply through input poly fuse<br />
|-<br />
| P1-04 || DNC<br />
|-<br />
| P1-06 || bgcolor="black" | <span style="color:white">GND</span> || bgcolor="black" | <span style="color:white">GND</span> <br />
|-<br />
|-<br />
| P1-08 || bgcolor="lime" | GPIO 14 || bgcolor="lime" | GPIO 14 || Boot to Alt 0 -> || bgcolor="yellow" | UART0_TXD || ALT5 = UART1_TXD<br />
|-<br />
| P1-10 || bgcolor="lime" | GPIO 15 ||bgcolor="lime" | GPIO 15 || Boot to Alt 0 -> ||bgcolor="yellow" | UART0_RXD || ALT5 = UART1_RXD<br />
|-<br />
| P1-12 || bgcolor="lime" | GPIO 18 ||bgcolor="lime" | GPIO 18 || || || ALT4 SPI1_CE0_N ALT5 = PWM0<br />
|-<br />
| P1-14 || DNC<br />
|-<br />
| P1-16 || bgcolor="lime" | GPIO23 ||bgcolor="lime" | GPIO23 || || || ALT3 = SD1_CMD ALT4 = ARM_RTCK<br />
|-<br />
| P1-18 || bgcolor="lime" | GPIO24 ||bgcolor="lime" | GPIO24 || || || ALT3 = SD1_DATA0 ALT4 = ARM_TDO<br />
|-<br />
| P1-20 || DNC<br />
|-<br />
| P1-22 || bgcolor="lime" | GPIO25 ||bgcolor="lime" | GPIO25 || || || ALT4 = ARM_TCK<br />
|-<br />
| P1-24 || bgcolor="lime" | GPIO08 ||bgcolor="lime" | GPIO08 || || bgcolor="purple" | <span style="color:white">SPI0_CE0_N</span> ||<br />
|-<br />
| P1-26 || bgcolor="lime" | GPIO07 ||bgcolor="lime" | GPIO07 || || bgcolor="purple" | <span style="color:white">SPI0_CE1_N</span> || <br />
|}<br />
<br />
<br />
'''Header Pinout, bottom row:'''<br />
{| border="1" style="text-align:center;"<br />
| '''Pin Number''' || '''Pin Name Rev1''' || '''Pin Name Rev2''' || '''Hardware Notes''' || '''Alt 0 Function''' || '''Other Alternative Functions'''<br />
|-<br />
| P1-01 || bgcolor="orange" | 3.3&nbsp;V ||bgcolor="orange" | 3.3&nbsp;V || 50&nbsp;mA max current draw<br />
|-<br />
| P1-03 || bgcolor="lime" | GPIO 0 ||bgcolor="lime" | GPIO 2|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SDA || I2C0_SDA / I2C1_SDA<br />
|-<br />
| P1-05 || bgcolor="lime" | GPIO 1 ||bgcolor="lime" | GPIO 3|| 1K8 pull up resistor || bgcolor="cyan" | I2C0_SCL || I2C0_SCL / I2C1_SCL <br />
|-<br />
| P1-07 || bgcolor="lime" | GPIO 4 ||bgcolor="lime" | GPIO 4 || || || bgcolor="lime" | GPCLK0<br />
|-<br />
| P1-09 || DNC<br />
|-<br />
| P1-11 || bgcolor="lime" | GPIO17 || bgcolor="lime" | GPIO17 || || ||| ALT3 = UART0_RTS, ALT5 = UART1_RTS<br />
|-<br />
| P1-13 || bgcolor="lime" | GPIO21 || bgcolor="lime" | GPIO27 || || PCM_DIN || ALT5 = GPCLK1<br />
|-<br />
| P1-15 || bgcolor="lime" | GPIO22 || bgcolor="lime" | GPIO22 || || || ALT3 = SD1_CLK ALT4 = ARM_TRST<br />
|-<br />
| P1-17 || DNC<br />
|-<br />
| P1-19 || bgcolor="lime" | GPIO10 || bgcolor="lime" | GPIO10 || || bgcolor="purple" | <span style="color:white">SPI0_MOSI</span> || <br />
|-<br />
| P1-21 || bgcolor="lime" | GPIO9 || bgcolor="lime" | GPIO9 || || bgcolor="purple" | <span style="color:white">SPI0_MISO</span> ||<br />
|-<br />
| P1-23 || bgcolor="lime" | GPIO11 || bgcolor="lime" | GPIO11 || || bgcolor="purple" | <span style="color:white">SPI0_SCLK</span> || <br />
|-<br />
| P1-25 || DNC<br />
|}<br />
<br />
<br />
{| border="1"<br />
! Colour legend<br />
|-<br />
| bgcolor="red" | <span style="color:white">+5&nbsp;V</span><br />
|-<br />
| bgcolor="orange" | +3.3&nbsp;V<br />
|-<br />
| bgcolor="black" | <span style="color:white">Ground, 0V</span> <br />
|-<br />
| Do not connect<br />
|-<br />
| bgcolor="yellow" | UART<br />
|-<br />
| bgcolor="lime" | GPIO<br />
|-<br />
| bgcolor="purple" | <span style="color:white">SPI</span><br />
|-<br />
| bgcolor="cyan" | I²C<br />
|}<br />
<br />
KiCad symbol: [[File:Conn-raspberry.lib]]<br />
<br />
<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/gpio-header-pinout-clarification/page-2</ref><br />
<br />
Pin 3 (SDA0) and Pin 5 (SCL0) are preset to be used as an I²C interface. So there are 1.8&nbsp;kilohm pulls up resistors on the board for these pins.<ref>http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software/page-6/#p56480</ref><br />
<br />
Pin 12 supports PWM.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-7, 15, 16, 18, 22 (chipset GPIOs 4 and 22 to 25) to provide an ARM JTAG interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.1</ref> However ARM_TMS isn't available on the GPIO connector (chipset pin 12 or 27 is needed). Chipset pin 27 is available on S5, the CSI camera interface however.<br />
<br />
It is also possible to reconfigure GPIO connector pins P1-12 and 13 (chipset GPIO 18 and 21) to provide an I2S (a hardware modification may be required<ref name="I2S">[http://www.raspberrypi.org/forum/features-and-requests/sad-about-removal-of-i2s-why-was-this-change-made Forum:Sad about removal of I2S. Why was this change made?]</ref>) or PCM interface.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1288.2</ref> However, PCM_FS and PCM_DIN (chipset pins 19 and 20) are needed for I2S or PCM.<br />
<br />
A second I²C interface (GPIO02_ALT0 is SDA1 and GPIO03_ALT0 is SCL1) and two further GPIOs (GPIO05_ALT0 is GPCLK1, and GPIO27) are available on S5, the CSI camera interface.<br />
<br />
===A note about GPIO vs the schematic===<br />
<br />
You may notice that the GPIO connector as documented in the schematic does NOT match with what is on this wiki page. Do NOT update this wiki page. The pins which are marked as DNC should not be used in order to be compatible with possible future designs. The plan is that if a new design comes along and if the layout permits it we will connect additional GPIO pins to those DNC pins. (Gert's first vote is for GPIO 19 and 20. That gives us the second PWM, second SPI, I2S/PCM, slave I²C and slave SPI.)<br />
<br />
===Referring to pins on the Expansion header===<br />
<br />
The header is referred to as "The GPIO Connector (P1)". To avoid nomenclature confusion between Broadcom signal names on the SoC and pin names on the expansion header, the following naming is highly recommended.<br />
<br />
* The expansion header is referred to as "Expansion Header" or "GPIO Connector (P1)"<br />
* Pins on the GPIO connector (P1) are referred to as P1-01, etc.<br />
* Names GPIO0, GPIO1, GPIOx-ALTy, etc. refer to the signal names on the SoC as enumerated in the Broadcom datasheet, where "x" matches BCM2835 number (without leading zero) and "y" is the alternate number column 0 to 5 on page 102-103 of the Broadcom document. For example, depending on what you are describing, use either "GPIO7" to refer to a row of the table, and "GPIO7-ALT0" would refer to a specific cell of the table.<br />
* When refering to signal names, you should modify the Broadcom name slightly to minimize confusion. The Broadcom SPI bus pin names are fine, such as "SPI0_*" and "SPI1_*", but they didn't do the same on the I²C and UART pins. Instead of using "SDA0" and "SCL0", you should use "I2C0_SDA" and "I2C0_SCL"; and instead of "TX" or "TXD" and "RX" or "RXD", you should use "UART0_TXD" and "UART0_RXD".<br />
<br />
===Power pins===<br />
The maximum permitted current draw from the 3.3&nbsp;V pin is 50&nbsp;mA.<br />
<br />
Maximum permitted current draw from the 5&nbsp;V pin is the USB input current (usually 1&nbsp;A) minus any current draw from the rest of the board.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1536#postid-21841</ref><br />
*Model A: 1000&nbsp;mA - 500&nbsp;mA -> max current draw: 500&nbsp;mA<br />
*Model B: 1000&nbsp;mA - 700&nbsp;mA -> max current draw: 300&nbsp;mA<br />
Be very careful with the 5&nbsp;V pin, because if you short it to any other P1 pin you may permanently damage your RasPi. Before probing P1, it's a good idea to strip a short piece of insulation off a wire and push it over the 5&nbsp;V pin so you don't accidentally touch it with a probe.<br />
<br />
=== GPIO hardware hacking ===<br />
<br />
The complete list of [[RPi_BCM2835_GPIOs|chipset GPIO pins]] which are available on the GPIO connector is: <blockquote>[[RPi_BCM2835_GPIOs#GPIO0|0]], [[RPi_BCM2835_GPIOs#GPIO1|1]], [[RPi_BCM2835_GPIOs#GPIO4|4]], [[RPi_BCM2835_GPIOs#GPIO7|7]], [[RPi_BCM2835_GPIOs#GPIO8|8]], [[RPi_BCM2835_GPIOs#GPIO9|9]], [[RPi_BCM2835_GPIOs#GPIO10|10]], [[RPi_BCM2835_GPIOs#GPIO11|11]], [[RPi_BCM2835_GPIOs#GPIO14|14]], [[RPi_BCM2835_GPIOs#GPIO15|15]], [[RPi_BCM2835_GPIOs#GPIO17|17]], [[RPi_BCM2835_GPIOs#GPIO18|18]], [[RPi_BCM2835_GPIOs#GPIO21|21]], [[RPi_BCM2835_GPIOs#GPIO22|22]], [[RPi_BCM2835_GPIOs#GPIO23|23]], [[RPi_BCM2835_GPIOs#GPIO24|24]], [[RPi_BCM2835_GPIOs#GPIO25|25]]</blockquote><br />
<br />
As noted above, GPIO00 and 01 (SDA0 and SCL0) have 1.8&nbsp;kilohm pull-up resistors to 3.3&nbsp;V.<br />
<br />
If 17 GPIOs aren't sufficient for your project, there are a few other signals potentially available, with varying levels of software and hardware (soldering iron) hackery skills:<br />
<br />
GPIO02, 03, 05 and 27 are available on S5 (the CSI interface) when a camera peripheral is not connected to that socket, and are configured by default to provide the functions SDA1, SCL1, CAM_CLK and CAM_GPIO respectively. SDA1 and SCL1 have 1K6 pull-up resistors to 3.3&nbsp;V.<br />
<br />
GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function.<br />
<br />
There are a few other chipset GPIO pins accessible on the PCB but are in use:<br />
<br />
* GPIO16 drives status LED D5 (usually SD card access indicator)<br />
* GPIO28-31 are used by the board ID and are connected to resistors R3 to R10.<br />
* GPIO40 and 45 are used by analogue audio and support PWM. They connect to the analogue audio circuitry via R21 and R27 respectively.<br />
* GPIO46 is HDMI hotplug detect (goes to pin 6 of IC1).<br />
* GPIO47 to 53 are used by the SD card interface. In particular, GPIO47 is SD card detect (this would seem to be a good candidate for re-use). GPIO47 is connected to the SD card interface card detect switch; GPIO48 to 53 are connected to the SD card interface via resistors R45 to R50.<br />
<br />
=== P2 header ===<br />
<br />
The P2 header is the VideoCore JTAG and used only during the production of the board. It cannot be used as the ARM JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>.<br />
<br />
Useful P2 pins:<br />
<br />
* Pin 1 - 3.3V (same as P1-01, 50 mA max current draw across both of them)<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
=== P3 header ===<br />
<br />
The P3 header, unpopulated, is the LAN9512 JTAG <ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5894</ref>.<br />
<br />
=== P5 header ===<br />
<br />
The p5 header was added with the release of the Revision 2.0 PCB design.<br />
<br />
* Pin 1 - 5V<br />
* Pin 2 - 3V3<br />
* Pin 3 - GPIO (TBA)<br />
* Pin 4 - GPIO (TBA)<br />
* Pin 5 - GPIO (TBA)<br />
* Pin 6 - GPIO (TBA)<br />
* Pin 7 - GND<br />
* Pin 8 - GND<br />
<br />
===Driver support===<br />
<br />
The Foundation will not include a GPIO driver in the initial release, standard Linux GPIO drivers should work with minimal modification.<ref>http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1278.0</ref><br />
<br />
The community implemented SPI and I²C drivers <ref>http://www.bootc.net/projects/raspberry-pi-kernel/</ref>, which will be integrated with the new Linux pinctrl concept in a later version of the kernel. A first compiled version as Linux modules is available to install on the 19/04/2012 Debian image, including 1-wire support<ref>http://www.raspberrypi.org/phpBB3/viewtopic.php?p=86172#p86172</ref>. The I²C and SPI driver uses the hardware modules of the microcontroller and interrupts for low CPU usage, the 1-wire support uses bitbanging on the GPIO ports, which results in higher CPU usage.<br />
<br />
GordonH<ref>http://www.raspberrypi.org/forum/general-discussion/wiring-for-the-raspberry-pis-gpio</ref> wrote a (mostly) Arduino compatible/style [https://projects.drogon.net/raspberry-pi/wiringpi/ WiringPi library] in C for controlling the GPIO pins.<br />
<br />
A useful tutorial on setting up I²C driver support can be found at [http://www.robot-electronics.co.uk/htm/raspberry_pi_examples.htm Robot Electronics] - look for the downloadable document rpi_i2c_setup.doc<br />
<br />
===Graphical User Interfaces===<br />
====WebIOPi====<br />
[http://code.google.com/p/webiopi/ WebIOPi] allows you to control each GPIO with a simple web interface that you can use with any browser. Available in PHP and Python, they both require root access, but Python version serves HTTP itself. You can setup each GPIO as input or output and change their states (LOW/HIGH). WebIOPi is fully customizable, so you can use it for home remote control. It also work over Internet. UART/SPI/I2C support will be added later. If you need some computing for your GPIO go to code examples below.<br />
<br />
===Code examples===<br />
====GPIO Driving Example (C)====<br />
[http://www.raspberrypi.org/forum/educational-applications/gertboard/page-4/#p31555 Gert van Loo & Dom, has provided] some tested code which accesses the GPIO pins through direct GPIO register manipulation in C-code.<br />
(Thanks to Dom for doing the difficult work of finding and testing the mapping.)<br />
Example GPIO code:<br />
<br />
<pre><br />
//<br />
// How to access GPIO registers from C-code on the Raspberry-Pi<br />
// Example program<br />
// 15-January-2012<br />
// Dom and Gert<br />
//<br />
<br />
<br />
// Access from ARM Running Linux<br />
<br />
#define BCM2708_PERI_BASE 0x20000000<br />
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */<br />
<br />
<br />
#include <stdio.h><br />
#include <string.h><br />
#include <stdlib.h><br />
#include <dirent.h><br />
#include <fcntl.h><br />
#include <assert.h><br />
#include <sys/mman.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
<br />
#include <unistd.h><br />
<br />
#define PAGE_SIZE (4*1024)<br />
#define BLOCK_SIZE (4*1024)<br />
<br />
int mem_fd;<br />
char *gpio_mem, *gpio_map;<br />
char *spi0_mem, *spi0_map;<br />
<br />
<br />
// I/O access<br />
volatile unsigned *gpio;<br />
<br />
<br />
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)<br />
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))<br />
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))<br />
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))<br />
<br />
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0<br />
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0<br />
<br />
void setup_io();<br />
<br />
int main(int argc, char **argv)<br />
{ <br />
int g,rep;<br />
<br />
// Set up gpi pointer for direct register access<br />
setup_io();<br />
<br />
// Switch GPIO 7..11 to output mode<br />
<br />
/************************************************************************\<br />
* You are about to change the GPIO settings of your computer. *<br />
* Mess this up and it will stop working! *<br />
* It might be a good idea to 'sync' before running this program *<br />
* so at least you still have your code changes written to the SD-card! *<br />
\************************************************************************/<br />
<br />
// Set GPIO pins 7-11 to output<br />
for (g=7; g<=11; g++)<br />
{<br />
INP_GPIO(g); // must use INP_GPIO before we can use OUT_GPIO<br />
OUT_GPIO(g);<br />
}<br />
<br />
for (rep=0; rep<10; rep++)<br />
{<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_SET = 1<<g;<br />
sleep(1);<br />
}<br />
for (g=7; g<=11; g++)<br />
{<br />
GPIO_CLR = 1<<g;<br />
sleep(1);<br />
}<br />
}<br />
<br />
return 0;<br />
<br />
} // main<br />
<br />
<br />
//<br />
// Set up a memory regions to access GPIO<br />
//<br />
void setup_io()<br />
{<br />
/* open /dev/mem */<br />
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {<br />
printf("can't open /dev/mem \n");<br />
exit (-1);<br />
}<br />
<br />
/* mmap GPIO */<br />
<br />
// Allocate MAP block<br />
if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {<br />
printf("allocation error \n");<br />
exit (-1);<br />
}<br />
<br />
// Make sure pointer is on 4K boundary<br />
if ((unsigned long)gpio_mem % PAGE_SIZE)<br />
gpio_mem += PAGE_SIZE - ((unsigned long)gpio_mem % PAGE_SIZE);<br />
<br />
// Now map it<br />
gpio_map = (unsigned char *)mmap(<br />
(caddr_t)gpio_mem,<br />
BLOCK_SIZE,<br />
PROT_READ|PROT_WRITE,<br />
MAP_SHARED|MAP_FIXED,<br />
mem_fd,<br />
GPIO_BASE<br />
);<br />
<br />
if ((long)gpio_map < 0) {<br />
printf("mmap error %d\n", (int)gpio_map);<br />
exit (-1);<br />
}<br />
<br />
// Always use volatile pointer!<br />
gpio = (volatile unsigned *)gpio_map;<br />
<br />
<br />
} // setup_io<br />
<br />
</pre><br />
<br />
====GPIO Pull Up/Pull Down Register Example====<br />
<pre><br />
// enable pull-up on GPIO24&25<br />
GPIO_PULL = 2;<br />
short_wait();<br />
// clock on GPIO 24 & 25 (bit 24 & 25 set)<br />
GPIO_PULLCLK0 = 0x03000000;<br />
short_wait();<br />
GPIO_PULL = 0;<br />
GPIO_PULLCLK0 = 0;<br />
</pre><br />
<br />
====GPIO Driving Example (Python)====<br />
This uses the Python module available at http://pypi.python.org/pypi/RPi.GPIO<br />
Any Python script that controls GPIO must be run as root.<br />
<pre>import RPi.GPIO as GPIO<br />
<br />
# Set up the GPIO channels - one input and one output<br />
GPIO.setup(11, GPIO.IN)<br />
GPIO.setup(12, GPIO.OUT)<br />
<br />
# Input from pin 11<br />
input_value = GPIO.input(11)<br />
<br />
# Output to pin 12<br />
GPIO.output(12, True)<br />
<br />
# The same script as above but using BCM GPIO 00..nn numbers<br />
GPIO.setmode(GPIO.BCM)<br />
GPIO.setup(17, GPIO.IN)<br />
GPIO.setup(18, GPIO.OUT)<br />
input_value = GPIO.input(17)<br />
GPIO.output(18, True)</pre><br />
<br />
====GPIO Driving Example (Java)====<br />
This uses the Java library available at http://code.google.com/p/rpi-gpio-java/. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
public static void main(String[] args) {<br />
GpioGateway gpio = new GpioGatewayImpl();<br />
<br />
//set up the GPIO channels - one input and one output<br />
gpio.setup(Boardpin.PIN11_GPIO17, Direction.IN);<br />
gpio.setup(Boardpin.PIN12_GPIO18, Direction.OUT);<br />
<br />
// input from pin 11<br />
boolean input_value = gpio.getValue(Boardpin.PIN11_GPIO17);<br />
<br />
// output to pin 12<br />
gpio.setValue(Boardpin.PIN12_GPIO18, true); <br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Java webapp via http)====<br />
This uses the Java webapp available at https://bitbucket.org/sbub/rpi-gpio-webapp. Any Java application that controls GPIO must be run as root.<br />
<pre><br />
<br />
host:~ sb$ curl 'http://raspberrypi:8080/handle?g0=1&g1=0'<br />
{"g1":0,"g0":1}<br />
<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
<pre><br />
#!/bin/sh<br />
<br />
# GPIO numbers should be from this list<br />
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25<br />
<br />
# Note that the GPIO numbers that you program here refer to the pins<br />
# of the BCM2835 and *not* the numbers on the pin header. <br />
# So, if you want to activate GPIO7 on the header you should be <br />
# using GPIO4 in this script. Likewise if you want to activate GPIO0<br />
# on the header you should be using GPIO17 here.<br />
<br />
# Set up GPIO 4 and set to output<br />
echo "4" > /sys/class/gpio/export<br />
echo "out" > /sys/class/gpio/gpio4/direction<br />
<br />
# Set up GPIO 7 and set to input<br />
echo "7" > /sys/class/gpio/export<br />
echo "in" > /sys/class/gpio/gpio7/direction<br />
<br />
# Write output<br />
echo "1" > /sys/class/gpio/gpio4/value<br />
<br />
# Read from input<br />
cat /sys/class/gpio/gpio7/value <br />
<br />
# Clean up<br />
echo "4" > /sys/class/gpio/unexport<br />
echo "7" > /sys/class/gpio/unexport<br />
</pre><br />
<br />
====GPIO Driving Example (Shell script - take 2)====<br />
You need the wiringPi library from<br />
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/<br />
once installed there is a new command '''gpio''' which can be used<br />
as a '''non-root''' user to control the GPIO pins.<br />
<br />
The man page <pre>man gpio</pre> has full details, but briefly:<br />
<br />
<pre><br />
gpio -g mode 17 out<br />
gpio -g mode 18 pwm<br />
<br />
gpio -g write 17 1<br />
gpio -g pwm 18 512<br />
</pre><br />
<br />
the '''-g''' flag tells the '''gpio''' program to use the BCM GPIO pin numbering<br />
scheme (otherwise it will use the wiringPi numbering scheme by default)<br />
<br />
The gpio command can also control the internal pull-up and pull-down<br />
resistors:<br />
<br />
<pre><br />
gpio -g mode 17 up<br />
</pre><br />
<br />
This sets the pull-up ressitor - however any change of mode, even<br />
setting a pin that's already set as an input to an input will remove<br />
the pull-up/pull-down resistors, so they may need to be reset.<br />
<br />
Additionally, it can export/un-export the GPIO devices for use by<br />
other non-root programms - e.g. Python scripts. (Although you<br />
may need to drop the calls to GPIO.Setup() in the Python scripts, and<br />
do the setup separately in a little shell script, or call the '''gpio''' program<br />
from inside Python).<br />
<br />
<pre><br />
gpio export 17 out<br />
gpio export 18 in<br />
</pre><br />
<br />
These exports GPIO-17 and sets it to output, and exports GPIO-18<br />
and sets it to input. <br />
<br />
and when done:<br />
<br />
<pre><br />
gpio unexport 17<br />
</pre><br />
<br />
The export/unexport commands always use the BCM GPIO pin numbers regardless of the<br />
presence of the '''-g''' flag or not.<br />
<br />
If you want to use the internal pull-up/down's with the /sys/class/gpio mechanisms,<br />
then you can set them after exporting them. So:<br />
<br />
<pre><br />
gpio -g export 4 in<br />
gpio -g mode 4 up<br />
</pre><br />
<br />
You can then use GPIO-4 as an input in your Python, Shell, Java, etc. programs without the use<br />
of an external resistor to pull the pin high. (If that's what you were after - e.g. a simple push<br />
button switch taking the pin to ground)<br />
<br />
A fully working example of a shell script using the GPIO pins<br />
can be found here:<br />
http://project-downloads.drogon.net/files/gpioExamples/tuxx.sh<br />
<br />
====GPIO Driving Example (C)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo -i</pre><br />
You must also get and install the bcm2835 library, which supports<br />
GPIO and SPI interfaces. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
<br />
<pre><br />
<br />
// blink.c<br />
//<br />
// Example program for bcm2835 library<br />
// Blinks a pin on an off every 0.5 secs<br />
//<br />
// After installing bcm2835, you can build this <br />
// with something like:<br />
// gcc -o blink blink.c -l bcm2835<br />
// sudo ./blink<br />
//<br />
// Or you can test it before installing with:<br />
// gcc -o blink -I ../../src ../../src/bcm2835.c blink.c<br />
// sudo ./blink<br />
//<br />
// Author: Mike McCauley (mikem@open.com.au)<br />
// Copyright (C) 2011 Mike McCauley<br />
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $<br />
<br />
#include <bcm2835.h><br />
<br />
// Blinks on RPi pin GPIO 11<br />
#define PIN RPI_GPIO_P1_11<br />
<br />
int main(int argc, char **argv)<br />
{<br />
// If you call this, it will not actually access the GPIO<br />
// Use for testing<br />
// bcm2835_set_debug(1);<br />
<br />
if (!bcm2835_init())<br />
return 1;<br />
<br />
// Set the pin to be an output<br />
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);<br />
<br />
// Blink<br />
while (1)<br />
{<br />
// Turn it on<br />
bcm2835_gpio_write(PIN, HIGH);<br />
<br />
// wait a bit<br />
delay(500);<br />
<br />
// turn it off<br />
bcm2835_gpio_write(PIN, LOW);<br />
<br />
// wait a bit<br />
delay(500);<br />
}<br />
<br />
return 0;<br />
}<br />
</pre><br />
<br />
====GPIO Driving Example (Perl)====<br />
This must be done as root. To change to the root user:<br />
<pre>sudo su -</pre><br />
Supports GPIO and SPI interfaces.<br />
You must also get and install the bcm2835 library. Details and downloads <br />
from http://www.open.com.au/mikem/bcm2835<br />
You must then get and install the Device::BCM2835 perl library from CPAN <br />
http://search.cpan.org/~mikem/Device-BCM2835-1.0/lib/Device/BCM2835.pm<br />
<pre><br />
use Device::BCM2835;<br />
use strict;<br />
<br />
# call set_debug(1) to do a non-destructive test on non-RPi hardware<br />
#Device::BCM2835::set_debug(1);<br />
Device::BCM2835::init() <br />
|| die "Could not init library";<br />
<br />
# Blink pin 11:<br />
# Set RPi pin 11 to be an output<br />
Device::BCM2835::gpio_fsel(&Device::BCM2835::RPI_GPIO_P1_11, <br />
&Device::BCM2835::BCM2835_GPIO_FSEL_OUTP);<br />
<br />
while (1)<br />
{<br />
# Turn it on<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 1);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
# Turn it off<br />
Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 0);<br />
Device::BCM2835::delay(500); # Milliseconds<br />
}<br />
<br />
<br />
</pre><br />
<br />
<br />
==== GPIO Driving Example (C#) ====<br />
RaspberryPiDotNet library is available at https://github.com/cypherkey/RaspberryPi.Net/.<br />
The library includes a GPIOFile and GPIOMem class. The GPIOMem requires compiling Mike McCauley's bcm2835 library above in to a shared object.<br />
<br />
<pre><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using RaspberryPiDotNet;<br />
using System.Threading;<br />
<br />
namespace RaspPi<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
// Access the GPIO pin using a static method<br />
GPIOFile.Write(GPIO.GPIOPins.GPIO00, true);<br />
<br />
// Create a new GPIO object<br />
GPIOMem gpio = new GPIOMem(GPIO.GPIOPins.GPIO01);<br />
gpio.Write(false);<br />
}<br />
}<br />
}<br />
</pre><br />
<br />
<br />
====GPIO Driving Example (Ruby)====<br />
<br />
This example uses the WiringPi Ruby Gem: http://pi.gadgetoid.co.uk/post/015-wiringpi-now-with-serial which you can install on your Pi with "gem install wiringpi"<br />
<br />
<pre><br />
MY_PIN = 1<br />
<br />
require 'wiringpi'<br />
io = WiringPi::GPIO.new<br />
io.mode(MY_PIN,OUTPUT)<br />
io.write(MY_PIN,HIGH)<br />
io.read(MY_PIN)<br />
</pre><br />
<br />
==MIPI CSI-2==<br />
<br />
On the production board<ref>http://www.raspberrypi.org/wp-content/uploads/2012/04/Raspberry-Pi-Schematics-R1.0.pdf</ref>, the Raspberry Pi Foundation design brings out the MIPI CSI-2 (Camera Serial Interface<ref>http://www.mipi.org/specifications/camera-interface</ref>) to a 15-way flat flex connector S5, between the Ethernet and HDMI connectors. A compatible camera has been discussed as working in tests and is planned for release at a later date.<ref>http://www.raspberrypi.org/forum/projects-and-collaboration-general/complex-camera-peripherials#p72602</ref>.<br />
<!-- This is misleading as it implies that cheap cameras from other devices can be used. CSI appears to be a generic interface with secret device-specific requirements so these devices must have drivers to be relevant (and currently only the VideoCore has access to the CSI hardware).<br />
<br />
is Sony sub-LVDS same as MIPI CSI-2? Sony IMX020 5Mbip module is available for $5-7 (SE K850i replacement camera).<br />
<br />
Looks like Nokia N95 uses CSI-2 5Mpix camera module with autofocus. ~$15 replacement part.<br />
--><br />
<br />
==DSI==<br />
<br />
On the production board, the Raspberry Pi Foundation design brings out the DSI (Display Serial Interface<ref>http://www.mipi.org/specifications/display-interface</ref>) to a 15-way flat flex connector labelled S2, next to Raspberry Pi logo. It has two data lanes and a clock lane, to drive a possible future LCD screen device. Some smart phone screens use DSI<ref>http://en.wikipedia.org/wiki/Display_Serial_Interface</ref>.<br />
<br />
==CEC==<br />
<br />
[[CEC (Consumer Electronics Control) over HDMI|HDMI-CEC (Consumer Electronics Control for HDMI)]] is supported by hardware but some driver work will be needed and currently isn't exposed into Linux userland.<br />
Eben notes that he has seen CEC demos on the Broadcom SoC they are using. <br />
<br />
libCEC with Raspberry Pi support has been included in OpenELEC and will be included in Raspbmc RC4.<ref>http://blog.pulse-eight.com/2012/08/01/libcec-1-8-0-a-firmware-upgrade-and-raspberry-pi-support/</ref><br />
<br />
For more information about HDMI-CEC and what you could do with it on the Raspberry Pi please see the [[CEC (Consumer Electronics Control) over HDMI]] article.<br />
<br />
== References ==<br />
<references/><br />
<br />
<br />
{{Template:Raspberry Pi}}</div>MattHawkinsUK