1 of 21

Raspberry PI

GPIO

2 of 21

What is GPIO

  • General Purpose Input Output
  • Input
    • Reading Button
    • Reading Keypad
    • Receiving Data
  • Output
    • Turning on LED
    • Turning on Motor
    • Sending Data

3 of 21

Buttons and LEDs

  • Simple Input: Pushbutton
    • 10k pullup
  • Simple Output: Light Emitting Diode
    • 100-300 Ohm current-limitting Resistor

4 of 21

5 of 21

Active High

Active Low

6 of 21

Active High

Active Low

7 of 21

All together

8 of 21

With Raspberry

9 of 21

10 of 21

Inside the Raspberry Pi

  • How can the same pin be an input or output?
  • How can a pin be made 3.3V or 0V (GND)?

11 of 21

From Shiju Abraham, MS thesis ECE, U of Texas, Arlington, 2014

If PAD voltage is high enough, top transistor is conducting

(connecting VDD to internal circuitry)

If PAD voltage is low enough, bottom transistor is conducting

(connecting VSS to internal circuitry)

If “From internal circuit” is high, PAD is connected to VDD

If “From internal circuit” is low, PAD is connected to VSS

INPUT

OUTPUT

PAD = Pin

VDD = 3.3V

VSS = 0V or GND

Diode,

protects circuit

PNP Transistor

NPN Transistor

12 of 21

Python Turning on LED

13 of 21

Python Reading Button

14 of 21

Reading many Buttons

https://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-devices/read-4x4-matrix-keypad

INPUT:

Will read 0 if no button is pushed

Will read 3.3V if corresponding row was set

Scan row by row, e.g.:

3.3V on P7:

want to read this row

0V on P6..P4:

don’t want to read these rows

Reading 16 Buttons with 8 PINs

Output and Inputs work together

15 of 21

Lighting up many LEDs

Energizing 64 LEDs with 16 Pins

Putting pin 9 on HIGH=3.3V &

Putting pin 13 on LOW=0V

Turns on top left LED

You can energize one row or one colum at a time

Output and Inputs work together

16 of 21

LED Matrix

How about a really big LED displays?

Use an LED matrix driver IC and talk to it

17 of 21

Talking to another Device: Serial Communication

18 of 21

Transmitting Signals Digitally

LSB

MSB

b01010011

0x53

83

“S”

19 of 21

I2C Bus

  • NXP Semiconductors (Phillips), 1982
  • Open Collector Design (multiple devices on same line)
  • Half Duplex
  • Synchronous
  • 7bit address space
  • Standard 100kbit/s,
  • Fast 400kbit/s
  • High Speed 3.4Mbit/s
  • 0.5 - 100 meters

20 of 21

I2C Schematic

21 of 21

Sound

Sending Value:

0 1 2 3 4

Original 1-bit Digital Encoding Output Filtering