Chapter B - The Raspberrry Pi GPIO

Chapter B - The Raspberrry Pi GPIO

Chapter A - The Raspberry Pi Computer Credit Card-size computer introduced in 2012 LINUX operating system Large number of reconfigurable General Purpose Input/Output digital pins (GPIO) Communication via SPI, I2C, and UART interfaces Two hardware Pulse-Width Modulation PWM channels No analog inputs-- we use an MCP3008, an 8channel, 10 bit A/D converter for analog data Specifications https://www.raspberrypi.org/magpi/raspberry-pi-3-specs-benchmarks/ SoC: Broadcom BCM2837

CPU: 4 ARM Cortex-A53, 1.2GHz GPU: Broadcom VideoCore IV RAM: 1GB LPDDR2 (900 MHz) Networking: 10/100 Ethernet, 2.4GHz 802.11n wireless Bluetooth: Bluetooth 4.1 Classic, Bluetooth Low Energy Storage: microSD GPIO: 40-pin header, populated Ports: HDMI, 3.5mm analogue audio-video jack, 4 USB 2.0, Ethernet, Camera Serial Interface (CSI), Display Serial Interface (DSI) The Raspberrry Pi Another Rpi view

GPIO Pinout for the RPi 3 GPIO Pinout for the RPi 3 40 unbuffered pins An incorrect connection may destroy RPi Two 5V & two 3.3V. High current applications require external source

Eight Grounds 13 digital I/O pins Several communication protocols available: One I2C Two SPI One UART Two PWM Accessing the GPIO Requires a special library

Will be included on your SD card Requires a directive for your code: #include Requires a change to the build command: gcc program.c -o program -lbcm2835 Requires a change to your execution: sudo program (sudo stands for super user do ) Sample code the blink.c program // blink.c // Example program for bcm2835 library // Blinks a pin on an off every 0.5 secs

// Author: Mike McCauley Copyright (C) 2011 Mike McCauley // #include // Blinks on RPi Plug P1 pin 13(which is GPIO pin 27) #define PIN RPI_BPLUS_GPIO_J8_13 int main(int argc, char **argv) { if (!bcm2835_init()) return 1; //start using GPIO; indicate if error // Set the pin to be an output bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP); The blink.c program continued // Blink forever

while (1) { bcm2835_gpio_write(PIN, HIGH); // Turn pin/LED on bcm2835_delay(500); // wait second bcm2835_gpio_write(PIN, LOW); // turn pin/LED off bcm2835_delay(500); // wait second } bcm2835_close(); // signals end to use of GPIO return 0; } Changes to compilation and

execution First, library must be installed (this is already on your SD cards!) For build (need to link library): gcc -o blink blink.c -l bcm2835 For execute (need more authority to access GPIO): sudo ./blink (sudo - execute a command as another user) Testing the code 330W LED

Resistors convert electrical energy into heat. Their characteristics are determined by Ohms Law: v(t) = i(t)R, where v(t) is the voltage across the resistor, i(t) is the current through the resistor, and R is the resistance. Diodes are semiconductor devices that only allow current to flow in one direction (the direction of the arrow). An LED, or Light-emitti ng diode gives offlight when

currents of 5-30 mA flow . The voltage across them is around 1.5-2.2V Analyzing the circuit Pin HIGH circuit 5V 330W 9 mA + 2V

+ 3V - Voltage: energy change per unit charge from one location to another (units = Volts (V)) Current: the rate that charge moves through a circuit component (units = Amperes (A)) Common multipliers : 1000 mA = 1A 1000 W = 1kW

Pin LOW circuit 330W 0A + 0V + 0V - KVL: Around a closed path / loop, the sum of voltage drops equals the sum of voltage rises.

KCL: The sum of currents entering a node equals the sum of currents leaving the node. Common errors Putting the diode in backwards No harm done simply doesnt light up Forgetting the resistor Very bright diode, then diode death Connecting to wrong GPIO pin or Connecting to 5V instead of ground No harm done simply doesnt light up

Connecting to any other pin ???? Laboratory Assignment #2 This lab lasts two weeks!!! Generate and run the program blink. Generate and run a program that allows you to type in an integer k (0 to quit) and then

have the led blink k times. Generate and run a program that allows you to type in a sentence and then have the led blink that word in Morse code (no input loop). International Morse Code table

Recently Viewed Presentations

  • Bildungsroman - Manasquan Public Schools

    Bildungsroman - Manasquan Public Schools

    Definition: A novel depicting someone's growth from childhood to maturity. A protagonist grows, learns, and changes in order to take his or her place in the world. IT is a German term that translates to " a novel of formation"...
  • Slides for Precomm Level TSP

    Slides for Precomm Level TSP

    The Army's Sexual Harassment/Assault Response & Prevention (SHARP) program exists so the Army can preventsexual harassment and sexual assaults before they occur. Our . goal is to eliminate sexual harassment and sexual assaults by creating a climate that respects the...
  • Week 6 - Welcome to 6th Grade!

    Week 6 - Welcome to 6th Grade!

    2.) You will move to the Reflection Corner to work on a different task and reflect on your behavior. 3.) If you do not follow expectations in the reflection corner (talking or leaving the seat) you will lose the privilege...
  • Fundamental of Programming (C)

    Fundamental of Programming (C)

    Input and Output in C. C has no built-in statements for IO. The I/O library functions are in <stdio.h> All input and output is performed with streams. A stream is a sequence of characters organized into lines. Standard types of...
  • Stagewise Operations

    Stagewise Operations

    HASIL DAN PEMBAHASAN Struktur rangka Mordenit Na8(AlO2)40(SiO2). 24H2O Secondary building block, Chains of 4-membered oxygen rings or T atoms Secondary building block, Chains of 5-membered oxygen rings or T atoms The pore channel 12-membered oxygen ring structure 0.67 x 7.0...
  • Project Scheduling - ntpu

    Project Scheduling - ntpu

    Project Scheduling Models 5.1 Introduction A project is a collection of tasks that must be completed in minimum time or at minimal cost. Objectives of Project Scheduling Completing the project as early as possible by determining the earliest start and...
  • Welcomes you to Seville, Spain

    Welcomes you to Seville, Spain

    Music 111: Music Appreciation with Dr. Jon Breman This course is an introduction to American, World and Western Classical music. The course introduces students to oral and written traditions and focuses on social milieu and the basic elements of music.
  • Overview of ARARs and CERCLA

    Overview of ARARs and CERCLA

    Orders are neither ARARs nor TBCs DOE must comply with Orders If the CERCLA process meets the requirement in the Order, then the Order as well is satisfied Orders included in RODs are enforceable When the Order is part of...