Chapter A The Raspberry Pi Computer Credit Cardsize
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, I 2 C, and UART interfaces • Two hardware Pulse-Width Modulation PWM channels • No analog inputs-- we use an MCP 3008, an 8 channel, 10 bit A/D converter for analog data
Specifications https: //www. raspberrypi. org/magpi/raspberry-pi-3 -specs-benchmarks/ So. C: Broadcom BCM 2837 CPU: 4× ARM Cortex-A 53, 1. 2 GHz GPU: Broadcom Video. Core IV RAM: 1 GB LPDDR 2 (900 MHz) Networking: 10/100 Ethernet, 2. 4 GHz 802. 11 n wireless Bluetooth: Bluetooth 4. 1 Classic, Bluetooth Low Energy Storage: micro. SD GPIO: 40 -pin header, populated Ports: HDMI, 3. 5 mm 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 5 V & two 3. 3 V. Ø High current applications require external source Ø Eight Grounds Ø 13 digital I/O pins Ø Several communication protocols available: ØOne I 2 C Ø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 <bcm 2835. h> Ø Requires a change to the build command: Øgcc program. c -o program -lbcm 2835 Ø 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 bcm 2835 library // Blinks a pin on an off every 0. 5 secs // Author: Mike Mc. Cauley Copyright (C) 2011 Mike Mc. Cauley // #include <bcm 2835. h> // Blinks on RPi Plug P 1 pin 13(which is GPIO pin 27) #define PIN RPI_BPLUS_GPIO_J 8_13 int main(int argc, char **argv) { if (!bcm 2835_init()) return 1; //start using GPIO; indicate if error // Set the pin to be an output bcm 2835_gpio_fsel(PIN, BCM 2835_GPIO_FSEL_OUTP);
The blink. c program continued // Blink forever while (1) { bcm 2835_gpio_write(PIN, HIGH); // Turn pin/LED on bcm 2835_delay(500); // wait ½ second bcm 2835_gpio_write(PIN, LOW); // turn pin/LED off bcm 2835_delay(500); // wait ½ second } bcm 2835_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. c -l bcm 2835 • For execute (need more authority to access GPIO): sudo. /blink (sudo - execute a command as another user)
Testing the code
Analyzing the circuit
Common errors Ø Putting the diode in backwards ØNo harm done – simply doesn’t light up Ø Forgetting the resistor ØVery bright diode, then diode death Ø Connecting to wrong GPIO pin or Ø Connecting to 5 V instead of ground Ø No harm done – simply doesn’t 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
- Slides: 15