Difference between revisions of "RPi Tutorial Easy GPIO Hardware & Software"

From eLinux.org
Jump to: navigation, search
m (Aims)
(Fixed broken description)
 
(37 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Template:RPi_Learning}}
+
{{Template:RPi_Tutorials}}
 +
 
 +
 
 +
==Warnings==
 +
While most of these circuits may interface directly to the RPi, the use of a buffered interface (such as the one supplied by the [[RPi Gertboard | Gertboard]]) is recommended which will help protect against damage.  Alternatively, experiment with one of the [[#Alternative Test Platforms]].
 +
 
 +
The GPIO pins connect directly into the core of the ARM processer, and are static-sensitive, so you should avoid touching the pins wherever possible. If you are carrying a static charge, for example by taking off an acrylic pullover, or walking across a nylon carpet, touching the GPIO pins could destroy your R-Pi, so always earth yourself before touching the pins or anything connected to them.
 +
 
 +
'''Extreme caution should be exercised when interfacing hardware at a low level, you may damage your RPi, your equipment and potentially yourself and others.  Doing so is at your own risk!'''
 +
 
 
==Aims==
 
==Aims==
The aim of this tutorial is to introduce the basic circuits which can be used to interface with the RPi's GPIO.
+
This tutorial is based on [http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software this thread] and aims to introduce basic circuits which can be used with the RPi's [[RPi Low-level peripherals#General Purpose Input/Output (GPIO) | General Purpose Input/Output (GPIO)]].
 +
Basic electronics knowledge will be required (i.e. familiarity with typical discrete components such as transistors, diodes and resistors).
 +
 
 +
It is highly recommended that additional [[RPi Tutorial EGHS:GPIO Protection Circuits|GPIO Protection Circuits]] are used to protect the delicate GPIO pins if interfacing to RPi hardware.
 +
 
 +
==Useful Links/Resources==
 +
*[http://log.liminastudio.com/writing/tutorials/tutorial-how-to-use-your-raspberry-pi-like-an-arduino Tutorial: How to use your RPi like an Arduino] - Thorough guide to utilizing the GPIO pins in Python, Bash and C.
  
Basic electronics knowledge will be required (i.e. familiar with typical discrete components such as transistors, diodes and resistors).
+
*[http://www.circuitlab.com Online Circuit Lab - Circuit Design and Simulation] - Excellent tool for experimenting with circuits (also used for the circuit diagrams used here)
  
 +
*[http://www.scriptoriumdesigns.com/embedded/index.php Introduction To Embedded Programming - GPIO] - In particular there is lots of detailed information about GPIO inputs and outputs for beginners to understand the principles behind the circuits.
  
This is based on the following forum thread: [http://www.raspberrypi.org/forum/features-and-requests/easy-gpio-hardware-software Easy GPIO Hardware & Software].
+
*[http://ww1.microchip.com/downloads/en/devicedoc/40040b.pdf Microchip's PIC Tips and Tricks PDF]<ref> http://www.raspberrypi.org/forum/projects-and-collaboration-general/gpios-suitable-for-microswitches-joysticks/#p35307 </ref> - Contains lots of useful example circuits for use with PIC micro-controllers, can be adapted for use with the RPi (3.3V GPIO).
  
 +
*[http://www.kpsec.freeuk.com/ The Electronics Club] - An excellent resource for beginner electronics, explains many basic circuits.
  
While most of these circuits may interface directly to the RPi, the use of a buffered interface (such as the one supplied by the [[RPi Gertboard | Gertboard]]) is recommended which will help protect against damage.  Alternatively, experiment with one of the [[#Alternative Test Platforms]].
+
*[http://raspberrywebserver.com/gpio/ Raspberry Web Server - GPIO] - A series of articles about basic GPIO programming on a Raspberry Pi.
 +
 
 +
*[http://raspberry.tips/raspberrypi-tutorials/raspberry-pi-modell-b-plus-gpio-pins-worksheet/ Raspberry Pi B+ GPIO PIN Worksheet] - Raspberry Pi Model B+ GPIO Pin Worksheet as Excel, PDF and Jpeg for your Content / Projects
  
 +
==Protection Circuits==
 +
In order to protect the Raspberry Pi hardware, it is highly recommended that the GPIO pins are protected in some form to avoid damage.
  
'''Extreme caution should be exercised when interfacing hardware at a low level, you may damage your RPi, your equipment and potentially yourself and others.  Doing so is at your own risk!'''
+
The following link will introduce some of the ways to do this:
  
==Useful Links/Resources==
+
[[RPi Tutorial EGHS:GPIO Protection Circuits|GPIO Protection Circuits]]
[http://www.scriptoriumdesigns.com/embedded/gpio_in.php Introduction To Embedded Programming - GPIO]
 
  
 
==Alternative Test Platforms==
 
==Alternative Test Platforms==
 
Until you have a RPi to test with, there are many alternative platforms available which will allow the testing of basic circuits.  In addition, they may be interfaced with directly using the RPi in the future.
 
Until you have a RPi to test with, there are many alternative platforms available which will allow the testing of basic circuits.  In addition, they may be interfaced with directly using the RPi in the future.
  
 +
* [http://www.ti.com/tool/msp-exp430g2 TI LaunchPad] - A low cost development platform ($4.30 including free world shipping). Includes programmer/debug board, two processors (with 16 GPIO including I2C/SPI/UART, 8ch 10bit ADC etc).
  
[http://www.ti.com/tool/msp-exp430g2 TI LaunchPad] - A low cost development platform ($4.30 including free world shipping)
+
*[http://arduino.cc/en/ Arduino] - Common hobbyist development platform. Excellent community support and additional hardware.
  
Includes programmer/debug board, two processors (with 16 GPIO including I2C/SPI/UART, 8ch 10bit ADC etc).
+
*[http://www.picaxe.com/ PICAXE]<ref> http://www.raspberrypi.org/forum/projects-and-collaboration-general/gpios-suitable-for-microswitches-joysticks/#p35309 </ref>
  
 +
*[http://www.stm32circle.com/hom/index.php STM32 Primer/EvoPrimer] - Self-contained development platform. Mentioned since I may use one at some point (I bought the original Primer a long time ago). It includes a battery, acceleration sensors and built in display screen.
  
[http://arduino.cc/en/ Arduino] - Common hobbyist development platform
+
=Completed Tutorials=
 
+
Note:
Excellent community support and additional hardware.
+
Until RPi devices are available, I can not confirm this will work on a real RPi.
 +
For now, I shall be using the TI LaunchPad (see [[RPi Tutorial Easy GPIO Hardware & Software#Alternative Test Platforms | Alternative Test Platforms]]
 +
for details) to test the hardware on (as it is cheap and the logic levels similar).
  
 +
===Basic Circuits===
 +
1. [[RPi Tutorial EGHS:LED output | LED output]]
  
 +
Directly driven (will need very low powered LED) or driven via transistor (allowing higher current).  Includes example 8xLED Test Module.
  
[http://www.stm32circle.com/hom/index.php STM32 Primer/EvoPrimer] - Self Contained development platform
+
3. [[RPi Tutorial EGHS:Switch Input| Simple on/off switch input]]
  
Mentioned since I may use one at some point (brought the original Primer a long time ago), includes battery, acceleration sensors and built in display screen.
+
With or without de-bouncing, protection resistors etc.  Includes example 8xSwitch Test Module.
  
 +
4. [[RPi Tutorial EGHS:12V relay driver| 12V relay driver circuit]]
  
==General GPIO Information==
+
12V relay driver circiut with opto-decoupler. Includes schema.
See [[RPi Low-level peripherals#General Purpose Input/Output (GPIO) | General Purpose Input/Output (GPIO)]] page for details.
 
  
==Planned Tutorials==
+
=Planned Tutorials=
 
===Basic Circuits===
 
===Basic Circuits===
 
1. LED output
 
1. LED output
  
Directly driven (will need very low powered LED) or driven via transistor (allowing higher current).
+
''Completed see above.''
  
  
2. Small DC motor drive
+
2. [[RPi Tutorial EGHS:DC Motor | Small DC motor drive]]
  
 
MOSFET or Darlington Pair to provide high power drive and reverse bias diode to protect from motor coils.
 
MOSFET or Darlington Pair to provide high power drive and reverse bias diode to protect from motor coils.
  
  
3. Simple on/off switch input
+
3. [[RPi Tutorial EGHS:Switch Input| Simple on/off switch input]]
  
With or without de-bouncing.
+
''Completed see above.''
  
  
4. Analogue resistive sensor sampled as a digital input
+
4. [[RPi Tutorial EGHS:Analogue Sensor| Analogue resistive sensor sampled as a digital input]]
  
 
Using a basic transistor switch circuit.
 
Using a basic transistor switch circuit.
  
 
===Intermediate Circuits===
 
===Intermediate Circuits===
1. Analogue to Digital Circuit
+
1. [[RPi Tutorial EGHS:Shift Registers| Shift Registers - Multiplexing Data]]
 +
 
 +
An introduction to using additional ICs.  In this case, using a parallel to serial 8-bit shift register to read 8 digital inputs using two GPIO pins.
 +
 
 +
 
 +
2. [[RPi Tutorial EGHS:Analogue to Digital| Analogue to Digital Circuit]]
  
 
Use of a ADC chip to sample inputs.
 
Use of a ADC chip to sample inputs.
  
  
2. PWM Driving Circuit
+
3. [[RPi Tutorial EGHS:Driving Circuit| PWM Driving Circuit]]
  
 
For example motor speed control.
 
For example motor speed control.
  
  
3. Alpha-numeric 2x16 LCD Display
+
4. [[RPi Tutorial EGHS:Alpha-Numeric Display| Alpha-numeric 2x16 LCD Display]]
 +
 
 +
'''(IN-PROGRESS)''' Control via 4-wire data (total 6 GPIO) and also alternative 2-wire interface circuit.
 +
 
 +
 
 +
5. [[RPi Tutorial EGHS:I2C Interfacing| Interfacing to I2C Devices]]
  
Control via 4-wire data (total 6 GPIO) and also alternative 2-wire interface circuit.
+
Interfacing to an I2C device connected to one of the Pi's I2C buses.
  
 
===Advanced Circuits===
 
===Advanced Circuits===
1. Control Hardware Over The Internet
+
1. [[RPi Tutorial EGHS:Control Hardware Over Internet| Control Hardware Over The Internet]]
  
 
Implement web control and monitoring of GPIO connected components.
 
Implement web control and monitoring of GPIO connected components.
  
 +
2. [[RPi Tutorial EGHS:Communicating With Other Micro-controllers | Communicating With Other Micro-controllers ]]
 +
 +
Communicate with other micro-controllers so that features such as ADCs can be used.
  
 
==Contributing to this tutorial==
 
==Contributing to this tutorial==
Line 86: Line 126:
  
 
Please see the [[Talk:RPi Tutorial Easy GPIO Hardware & Software]] page to discuss this page.
 
Please see the [[Talk:RPi Tutorial Easy GPIO Hardware & Software]] page to discuss this page.
 +
 +
<references/>
  
 
{{Template:Raspberry Pi}}
 
{{Template:Raspberry Pi}}

Latest revision as of 07:17, 31 August 2014

Back to the Hub, or the Tutorials page.


GPIO Hardware & Software Tutorials:


Warnings

While most of these circuits may interface directly to the RPi, the use of a buffered interface (such as the one supplied by the Gertboard) is recommended which will help protect against damage. Alternatively, experiment with one of the #Alternative Test Platforms.

The GPIO pins connect directly into the core of the ARM processer, and are static-sensitive, so you should avoid touching the pins wherever possible. If you are carrying a static charge, for example by taking off an acrylic pullover, or walking across a nylon carpet, touching the GPIO pins could destroy your R-Pi, so always earth yourself before touching the pins or anything connected to them.

Extreme caution should be exercised when interfacing hardware at a low level, you may damage your RPi, your equipment and potentially yourself and others. Doing so is at your own risk!

Aims

This tutorial is based on this thread and aims to introduce basic circuits which can be used with the RPi's General Purpose Input/Output (GPIO). Basic electronics knowledge will be required (i.e. familiarity with typical discrete components such as transistors, diodes and resistors).

It is highly recommended that additional GPIO Protection Circuits are used to protect the delicate GPIO pins if interfacing to RPi hardware.

Useful Links/Resources

  • The Electronics Club - An excellent resource for beginner electronics, explains many basic circuits.

Protection Circuits

In order to protect the Raspberry Pi hardware, it is highly recommended that the GPIO pins are protected in some form to avoid damage.

The following link will introduce some of the ways to do this:

GPIO Protection Circuits

Alternative Test Platforms

Until you have a RPi to test with, there are many alternative platforms available which will allow the testing of basic circuits. In addition, they may be interfaced with directly using the RPi in the future.

  • TI LaunchPad - A low cost development platform ($4.30 including free world shipping). Includes programmer/debug board, two processors (with 16 GPIO including I2C/SPI/UART, 8ch 10bit ADC etc).
  • Arduino - Common hobbyist development platform. Excellent community support and additional hardware.
  • STM32 Primer/EvoPrimer - Self-contained development platform. Mentioned since I may use one at some point (I bought the original Primer a long time ago). It includes a battery, acceleration sensors and built in display screen.

Completed Tutorials

Note:
Until RPi devices are available, I can not confirm this will work on a real RPi.
For now, I shall be using the TI LaunchPad (see  Alternative Test Platforms
for details) to test the hardware on (as it is cheap and the logic levels similar).

Basic Circuits

1. LED output

Directly driven (will need very low powered LED) or driven via transistor (allowing higher current). Includes example 8xLED Test Module.

3. Simple on/off switch input

With or without de-bouncing, protection resistors etc. Includes example 8xSwitch Test Module.

4. 12V relay driver circuit

12V relay driver circiut with opto-decoupler. Includes schema.

Planned Tutorials

Basic Circuits

1. LED output

Completed see above.


2. Small DC motor drive

MOSFET or Darlington Pair to provide high power drive and reverse bias diode to protect from motor coils.


3. Simple on/off switch input

Completed see above.


4. Analogue resistive sensor sampled as a digital input

Using a basic transistor switch circuit.

Intermediate Circuits

1. Shift Registers - Multiplexing Data

An introduction to using additional ICs. In this case, using a parallel to serial 8-bit shift register to read 8 digital inputs using two GPIO pins.


2. Analogue to Digital Circuit

Use of a ADC chip to sample inputs.


3. PWM Driving Circuit

For example motor speed control.


4. Alpha-numeric 2x16 LCD Display

(IN-PROGRESS) Control via 4-wire data (total 6 GPIO) and also alternative 2-wire interface circuit.


5. Interfacing to I2C Devices

Interfacing to an I2C device connected to one of the Pi's I2C buses.

Advanced Circuits

1. Control Hardware Over The Internet

Implement web control and monitoring of GPIO connected components.

2. Communicating With Other Micro-controllers

Communicate with other micro-controllers so that features such as ADCs can be used.

Contributing to this tutorial

This is an open project so please feel welcome to add your own sections and improve its content.

Please see the Talk:RPi Tutorial Easy GPIO Hardware & Software page to discuss this page.