Raspberry Pi GPIO Pin naming conventions Using sysfs

Slides:



Advertisements
Similar presentations
Lab7: Introduction to Arduino
Advertisements

Internet of Things with Intel Edison GPIO on Edison
The Operating System. What is an Operating System? The program that is loaded first and manages the hardware resources like main memory, backing storage.
Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Controlling the World with Raspberry Pi J Dean Brock, Rebecca Bruce, and Marietta E. Cameron.
Living with the Lab Using Your Arduino, Breadboard and Multimeter EAS 199A Fall 2011 Work in teams of two!
Intro to Arduino with LilyPad Make a MakerSpace, Artisan’s Asylum Linz Craig, Chris Taylor, Mike Hord & Joel Bartlett.
Systems Programming Course Gustavo Rodriguez-Rivera.
1 Introduction Chapter What is an operating system 1.2 History of operating systems 1.3 The operating system zoo 1.4 Computer hardware review 1.5.
Introduction to the Raspberry Pi ® Saman Amighi 10/2013 ® Raspberry Pi Foundation.
Embedded Programming and Robotics Lesson 19 Raspberry Pi Programming in C 1.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Embedded Programming and Robotics Lesson 12 Introducing the Raspberry Pi Intro to Raspberry Pi1.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Microprocessor Block Diagram
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
SINGLE BOARD COMPUTERS -KEVIN JOSE. WHY DO WE USE THEM? Good performance at low price GPIO capability to interact with the outside world Small form factor,
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
EEE305 Microcontroller Systems
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Controlling the World with Raspberry Pi
IMU Guidance Servoblaster Code for the IMU Going mobile.
Ch Review1 Review Chapter Microcomputer Systems Hardware, Software, and the Operating System.
RC CAR CONTROLLER BASED ON INTEL GALILEO SOC PLATFORM Nadav Shiloach Sagi Sabag Supervisor: Idan Shmuel Spring 2014 One Semester Project PROJECT’S ENDING.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
BBBK Programming Notes Rudra Dutta CSC , Fall, 2013.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Basic Systems and Software. Were we left off Computers are programmable (formal) machines. Digital information is stored as a series of two states (1.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
Getting Started With the Arduino Uno
DPNM Lab., POSTECH 1/8 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH
Introduction :  In the beginning, the calculator is the basic idea of computers out, then that arrived at the large computers.  in1980 or late seventies.
Microcontrollers, Microcomputers, and Microprocessors
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Embedded Software Design Week I Class Introduction Course Coverage Hardware Platforms * Some of this slides are inspired/copied from Dr. Mark Brehob’s.
Raspberry Pi Project Control Your Home Lights with a Raspberry Pi.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Embedded Software Design Week II Linux Intro Linux Kernel.
Istituto Tecnico Industriale A.Monaco EURLAB Control a Servo Motor If you want to swing an robot arm or … steer a robot you need a special motor (Servo).
Introduction to Operating Systems Concepts
Arduino.
RASPBERRY PI WORKSHOP.
Implementation of Embedded OS
IoT 101 with Raspberry Pi and Azure
Microcontrollers, Basics Fundamentals of Designing with Microcontrollers 16 January 2012 Jonathan A. Titus.
Computer System Laboratory
Microcontroller basics
Raspberry Pi Hands-on Seminars
Chapter A - The Raspberry Pi Computer
An Arduino Workshop A Microcontroller.
Welcome to Arduino A Microcontroller.
A microcontroller Raspberry Pi 2 Model B V1.1 RPi
Computer System Laboratory
CS 3305 System Calls Lecture 7.
Programming with Arduinos and Rapsberry Pi
Introduction to Arduino Microcontrollers
Lighting LEDs with a RASPBERRY PI
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
CENG2400 Revision Q1a A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module. Two on/off switches are connected to bit-3.
Internet-of-Things (IoT)
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Journey: Introduction to Embedded Systems
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Implementation of Embedded OS
Workshop GPIO I2C SPI Panic1 woensdag 10 april 2019.
Embedded XINU and WRT54GL
Chapter-1 Computer is an advanced electronic device that takes raw data as an input from the user and processes it under the control of a set of instructions.
Raspberry Pi Hardware By: Mike Kwiatkowski.
Robot and Crickit HAT © Copyright 2019 by Dr. Elizabeth I. Horvath and Dr. Eva A. Horvath 1.
Presentation transcript:

Raspberry Pi GPIO Pin naming conventions Using sysfs Using the Wiring library Git and Github

Pi Overview So far we have tried to setup a “headless” connection to your Pi in this classroom. Serial with the FTDI cable Ethernet on the CS LAN WiFi in Rhodes-Robinson Hall a hidden network managed by ITS You must demonstrate your ability to connect to your Pi using at least two of these three methods in order to receive a passing grade in this class. This can be done at any point through out the remainder of the semester---I will keep a list on Moodle There are now over ten workstations configured in the CS lab (RRO 223) to support a monitor, keyboard, and mouse connection. This is an easier to get things working properly try it out, but put all the cables back!

Pi Overview We’ve learned a little about the Pi BCM 2835 processor, 3.3V (3V3) power on pins, SD card is like the hard drive,… We’ve learned a little about Linux The root directory: / , the super user designation: sudo, change permissions: chmod ugo+x filename, … We’ve learned a little about networking ssh pi@yourLastName-pi.cs.unca.edu ifconfig The contents of the file: /etc/network/interfaces Today, our focus is on using the Pi as an embedded system controller

Pi Setup for Today Will also need a WiFi or an Ethernet connection Connect to power adapter not the USB port of your computer Pin 1 is the colored wire-must connect to pin 1 on the Pi Because the cobbler connector has a notch, you can only put the cable in the right way But, it is possible to put the cable in upside down on the Raspberry Pi

RPi General Purpose IO (GPIO) Pins 17 GPIO pins brought out onto the P1 header most have alternated functions two pins for UART; two for I2C; six for SPI All 17 pins can be GPIO (i.e., INPUT or OUTPUT) all support interrupts internal pull-ups & pull-downs for each pin I2C pins have onboard pull-ups using them for GPIO may not work Pins are 3.3V not 5V like on the Arduino They are connected directly to the Broadcom chip Sending 5V to a pin may kill the Pi Maximum permitted current draw from a 3.3V pin is 50mA Image credit: http://elinux.org/RPi_Low-level_peripherals

The Bigger Picture (image credit: http://pihw.wordpress.com/2013/01/30/sometimes-it-can-be-simple) Diagram includes BCM GPIO references (GPIO.BCM), common functions, WiringPi pin references, and Pin numbers (GPIO.BOARD). A cheat nice sheet

Using the GPIO Pins There are two different methods to read or write these pins using Linux Creating a file-type access in the file system Write/read memory addresses allocated to the GPIO peripheral of the SoC using pointers Memory locations can be found in the datasheet for the BCM2835  We can use the Wiring library to help with both

Connect an LED using a resistor between GPIO 17 (P1-11) and GND The LED will initially be off because the GPIO pins are initialized as inputs at power-on (except for TXD).

Using the File System Create and run the following shell script (blink.sh) using sudo: sudo ./blink.sh #!/bin/sh echo 17 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio17/direction while true do         echo 1 > /sys/class/gpio/gpio17/value sleep 1         echo 0 > /sys/class/gpio/gpio17/value sleep 1 done Make the pin available for other applications using with the command: echo 17 > /sys/class/gpio/unexport

More Detail Create a shell script using nano: nano blink.sh Cut and paste the previous slide to nano window Ctrl-w to save then Ctrl-x to exit nano Change the permissions on blink.sh: chmod 755 blink.sh Run blink.sh: sudo ./blink.sh (in directory where blink.sh is stored) After running the script your LED should be blinking endlessly. Give the command: Ctrl-c Ctrl-c to abort the script All of the commands in the script can be issued one at a time on the command line; beginning by giving the commands: sudo -i to run a root shell---notice the change in the prompt Look at the files and their contents in directory /sys/class/gpio/ and its subdirectories --- see next slide

Understanding /sys/class/gpio/ In Linux everything is a file: /dev/ttyUSB0, /sys/class/net/eth0/address, /dev/mmcblk0p2,… sysfs in a kernel module providing a virtual file system for device access at /sys/class provides a way for users (or code in the user-space) to interact with devices at the system (kernel) level A demo Advantages / Disadvantage Allows conventional access to pins from userspace Always involves mode switch to kernel, action in kernel, mode switch to use, and could have a context switch Much slower the digitalWrite()/digitalRead() of Arduino

A C program to do the same thing GPIO with sysfs on Raspberry Pi (Part 2) Code on Github Beware: the code assumes a Rev1 pinout

Github The heart of GitHub is Git, an open source project started by Linux creator Linus Torvalds Git manages and stores revisions of projects Think of it as a filing system for every draft of a document Git is a command line tool GitHub provides a Web-based graphical interface Basic functionality

Introducing the WiringPi library A GPIO access library written in C for the BCM2835 Writes/reads the base address of the memory allocated to the GPIO Similar to the Wiring library in the Arduino used to make common IO operations easier Features: command-line utility gpio supports analog reading and writing More Install the Wiring Pi library following these instructions

Wiring Pin Numbers Image credit: https://projects.drogon.net/raspberry-pi/wiringpi/pins/

Blinking lights with Wiring #include <stdio.h> #include <wiringPi.h> // LED Pin - wiringPi pin 0 is BCM_GPIO 17. #define LED 0 int main (void) { printf ("Raspberry Pi blink\n") ; wiringPiSetup () ; //  note the setup method chosen pinMode (LED, OUTPUT) ; for (;;) { digitalWrite (LED, HIGH) ; // On delay (500) ; // mS digitalWrite (LED, LOW) ; // Off delay (500) ; } return 0 ;

Running blink Compile and run the blink program gcc -Wall -o blink blink.c -lwiringPi  compile sudo ./blink  run Runs forever---kill with the command ctrl-c ctrl-c Note: One of the four wiring setup functions must be called at the start of your program or your program will not work correctly

Accessing memory allocated to the GPIO /dev/mem provides user-level access to SoC memory Offset 0x20000000 is a address of BCM peripherals wiringPi.c writes to that area of memory to control the pins

Controlling a Servo with the Pi Controlling the servos requires PWM, aka Pulse Width Modulation The Arduino does this very well, the Raspberry Pi does it less well The Arduino program has complete control of the microcontroller when it is running loop() nothing else can use the CPU Except for interrupt handlers written as part of the Arduino program On the Raspberry Pi, your program runs within a Linux OS The Linux OS may switch to running another program! But you can change your program’s scheduling priority Some ways of getting the Pi to give the impression that it is a real time system and to do PWM ‘properly’: Gordon Henderson has written about an improvement to the WiringPi library to allow threaded PWM on every GPIO pin taking up 0.1% of the CPU each Rahul Kar has blogged about using the WiringPi library and PWM WiringPi recommends ServoBlaster

Connect a Parallax Servo Servo Connector: Black – Pi’s ground Red – Pi’s 5V White – signal on GPIO 17 Image credit: http://www.parallax.com/ NOTE: For a single small servo you can take the 5 volts for it from the Pi header, but doing anything non-trivial with four servos connected pulls the 5 volts down far enough to crash the Pi

Using WiringPi’s servo example #include <stdio.h> #include <errno.h> #include <string.h> #include <wiringPi.h> #include <softServo.h> int main () { if (wiringPiSetup () == -1) { // setup to use Wiring pin numbers fprintf (stdout, "oops: %s\n", strerror (errno)) ; return 1 ; } softServoSetup (0, 1, 2, 3, 4, 5, 6, 7) ; // wiringPi pin numbers for (;;) { softServoWrite (0, 0) ; // wiringPi pin 0 is BCM_GPIO 17 delay (1000) ; softServoWrite (0, 500) ; delay (1000); softServoWrite (0, 1000) ;

Running servo.c To compile: gcc -Wall -o servo servo.c wiringPi/wiringPi/softServo.c  compile softServo.c -IwiringPi/wiringPi  path to softServo.c -lwiringPi  include wiring library To run: sudo ./servo Calling softServoWrite () ; The 1st input is the pin number The 2nd input should be from 0 (hard left) to 1000 (hard right). The 2nd input refers to the number of microseconds of the pulse. An input of 0 produces a 1000uSec (1mSec) pulse (hard left) An input of 1000 produces a 2000uSec (2mSec) pulse (hard right) An input of 500 produces a 1500uSec (1.5 mSec) pulse (stop)

Using the gpio utility The program gpio can be used in scripts to manipulate the GPIO pins The gpio command is designed to be called by a normal user without using the sudo command or logging in as root Try at the command line: gpio mode 0 out gpio write 0 1 Sets pin 0 as output and then sets the pin to high More info on the gpio utility

And There’s more WiringPi provides support for C programming There’s a lot of support for programming in Python: http://openmicros.org/index.php/articles/94-ciseco-product-documentation/raspberry-pi/217-getting-started-with-raspberry-pi-gpio-and-python http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/install-python-module-rpi-dot-gpio