Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Controlling the World with Raspberry Pi J Dean Brock, Rebecca Bruce, and Marietta E. Cameron.

Slides:



Advertisements
Similar presentations
Hardware and Python Steve Granda. Why would I want to do this? You want to make something interactive. You want to recreate sputnik. You want to measure.
Advertisements

Lab7: Introduction to Arduino
Operating Systems High Level View Chapter 1,2. Who is the User? End Users Application Programmers System Programmers Administrators.
1 Web Server Administration Chapter 3 Installing the Server.
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.
Aztec PC Oscilloscope Michael Mason Jed Brown Josh Price Andrew Youngs.
CCNA 2 v3.1 Module 2.
UNIX chapter 03 Getting Started Mr. Mohammad Smirat.
Embedded Programming and Robotics Lesson 12 Introducing the Raspberry Pi Intro to Raspberry Pi1.
Microprocessor Block Diagram
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
Raspberry Pi Training Truman College Goals of our Training Today Unbox and boot up the Raspberry Pi (RPi) Learn how to access the desktop graphical.
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,
EEE305 Microcontroller Systems
One to One instructions Installing and configuring samba on Ubuntu Linux to enable Linux to share files and documents with Windows XP.
Chapter 8 Input/Output. Busses l Group of electrical conductors suitable for carrying computer signals from one location to another l Each conductor in.
Raspberry Pi GPIO Pin naming conventions Using sysfs
Controlling the World with Raspberry Pi
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
Ballooning Bundle. What is a Microcontroller? Small computer with a processor core, memory and programmable input/output Continuously repeats software.
RC CAR CONTROLLER BASED ON INTEL GALILEO SOC PLATFORM Nadav Shiloach Sagi Sabag Supervisor: Idan Shmuel Spring 2014 One Semester Project PROJECT’S ENDING.
MOBILE OPERATING ROBOT ON EMBEDDED SYSTEM
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.
Booting Ubuntu Linux Live CSCI 130 – Fall 2008 Action Lab Dr. W. Jones.
Development Environments Raspberry Pi ® Saman Amighi 04/2014 ® Raspberry Pi Foundation.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Logic Analyzer ECE-4220 Real-Time Embedded Systems Final Project Dallas Fletchall.
Basic Systems and Software. Were we left off Computers are programmable (formal) machines. Digital information is stored as a series of two states (1.
Introduction to Routers
Introduction :  In the beginning, the calculator is the basic idea of computers out, then that arrived at the large computers.  in1980 or late seventies.
Intro to Raspberry Pi A Southwest Florida Hackerspace Workshop Presented by: Russell Benzing & Eric Schiffli.
Microcontrollers, Microcomputers, and Microprocessors
Firmware (CLP-310 Series).
بسم الله الرحمن الرحيم MEMORY AND I/O.
Embedded Software Design Week I Class Introduction Course Coverage Hardware Platforms * Some of this slides are inspired/copied from Dr. Mark Brehob’s.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
Raspberry Pi Project Control Your Home Lights with a Raspberry Pi.
Embedded Software Design Week II Linux Intro Linux Kernel.
Raspberry PI 2 Installation & Demo App By Wayne Keadle.
Embedded Linux By Gus Wirth. What makes it embedded? ● Rather nebulous, line has blurred over the years ● Limited purpose ● Small resources compared to.
RaspberryPi.
Arduino.
Workshop on Raspberry Pi 3
RASPBERRY PI WORKSHOP.
Implementation of Embedded OS
Computer System Laboratory
Embedded Software Development with Python and the Raspberry Pi
Chapter A - The Raspberry Pi Computer
Running your own web server
Linux Kernel Module Programming
UTA010 : Engineering Design – II
An Arduino Workshop A Microcontroller.
Welcome to Arduino A Microcontroller.
A microcontroller Raspberry Pi 2 Model B V1.1 RPi
Computer System Laboratory
Lighting LEDs with a RASPBERRY PI
Microsoft Ignite NZ October 2016 SKYCITY, Auckland.
Building an Internet of Things Device
CSCI1600: Embedded and Real Time Software
Class Projects and Environment
CSCI1600: Embedded and Real Time Software
Implementation of Embedded OS
Lecture9: Embedded Network Operating System: cisco IOS
Workshop GPIO I2C SPI Panic1 woensdag 10 april 2019.
Beginning Raspberry Pi
Introduction to Single Board Computer
Presented By,  Mamata Yadav (BE Elex & Comm.) Vice R&D Coordinator(HW), PCRT  Payal Shah (BE Elex & Comm.)  Ananta Das (BE Elex & Comm.) R&D Team,PCRT.
Lecture9: Embedded Network Operating System: cisco IOS
Raspberry Pi Hardware By: Mike Kwiatkowski.
Presentation transcript:

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Controlling the World with Raspberry Pi J Dean Brock, Rebecca Bruce, and Marietta E. Cameron IEEE Southeast Conference 2014

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Rapberry Pi Model B Picture from Wikimedia

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Raspberry Pi history  A computer to inspire children  to put the fun back into learning computing  provide computers to the poor  guided by Raspberry Pi foundation  Early support from academia and industry  University of Cambridge Computer Laboratory University of Cambridge Computer Laboratory  Broadcom Broadcom  Raspberry Pi model B launched in early 2012  Model A is $10 cheaper

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE A Headless Connection  Fine for embedded systems applications, web server, home router, network and sensors (monitoring), etc.  Requires personal computer setup  Install a terminal emulator or ssh client for Windows MobaXterm PuTTY or something else

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Raspberry Pi Quick start From Raspberry Pi Quick start guideRaspberry Pi Quick start guide

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Raspberry Pi hardware  Broadcom BCM2835 SoC (system on chip)  700 MHz ARM1176JZF-S CPU ARM11 microarchitecture with ARMv6A ISA  Video Core IV GPU (1080p, 24GFLOPS)  Peripherals: UART, USB, I 2 C, GPIO  LAN9512 USB hub and Ethernet controller  512 Mbytes RAM  Connectors: USB, Ethernet, HDMI, camera  SD-card

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Very detailed references  Schematics for Rasberry Pi board Schematics for Rasberry Pi board  BCM2835 ARM peripherals data sheet BCM2835 ARM peripherals data sheet  LAN9512 data sheet LAN9512 data sheet  ARMv6 architecture reference manual  Available with ARM login id Or search using google  Almost 400 pages

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Connecting  With a monitor  Nothing to it  Headless  Secure Shell (ssh) IP assigned by DHCP Use your router administrative page Run tail on /var/log/messages  Serial-Connection Use a serial cable connection and connect like you did in 1988

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Physical Serial Connection The colored wire-must connect to pin 1 on the Pi Connect ground to ground and RX to TX in both directions: 1.Connect FTDI yellow to Pi TX 2.Connect FTDI orange to Pi RX 3.Connect Gnd to Gnd via the power rail DETAIL:

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Login to the Pi  Account name: pi  Password: creative Hit the enter key a couple of times to initiate the prompt

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Linux Try it out:

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Raspberry Pi GPIO A subset of the BCM2835 GPIO pins

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE RPi General Purpose IO (GPIO) Pins 17 GPIO pins on 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

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Diagram includes BCM GPIO references (GPIO.BCM), common functions, WiringPi pin references, and Pin numbers (GPIO.BOARD ) The Bigger Picture

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Using the GPIO Pins  There are two methods to read or write these pins  File-type access in userspace accessed through the device (/dev) interface  Write/read memory addresses allocated to the GPIO peripheral of the SoC Memory locations can be found in the datasheet for the BCM2835 datasheet for the BCM2835  You can use the WiringPi library to help with both

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Blinking LED: Physical Connection  Connect an LED to GPIO 17 (P1-11)  The LED will initially be off because the GPIO pins are initialized as inputs at power-on (except for TXD).

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Blinking LED: Software Solution 1  Using a file-type access  Run shell script blink.sh cd examples sudo./blink.sh  “Close” the /sys/class/gpio/gpio17 directory:  echo 17 > /sys/class/gpio/unexport #!/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

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE More Details  Create a shell script using 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

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Understanding /sys/class/gpio/  In Linux, everything is a file: /dev/ttyUSB0, /sys/class/net/eth0/address, /dev/mmcblk0p2,…  sysfs is a kernel module providing a virtual file system for device access at /sys/class  provides a way for users (or code in user-space) to interact with devices at the system (kernel) level  A demo A demo  Advantages / Disadvantage  Allows conventional access to pins from userspace  Always involves mode switch to kernel, action in kernel, mode switch back to user, and could have a context switch  Slower than digitalWrite()/digitalRead() of Arduino with less predictable response times

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE A C program to do the same thing  GPIO with sysfs on Raspberry Pi (Part 2) GPIO with sysfs on Raspberry Pi (Part 2)  Code on Github Code on Github  Beware: the code assumes a Rev1 pinout

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Input Example  Physical Connection: Add a push-button switch to GPIO 22

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Input Example Software  Look in examples directory for button.c  Compile and run the button program gcc -Wall -o button button.c -lwiringPi  compile sudo./button  run  The push-button controls the LED  Runs forever  kill with ctrl-c ctrl-c

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE button.c #include // LED Pin - wiringPi pin 0 is BCM_GPIO 17 #define LED 0 // LED Pin - wiringPi pin 3 is BCM_GPIO 22 #define BUTTON 3 int main (void) { printf ("Raspberry Pi Push-Button Controlled LED\n"); wiringPiSetup (); pinMode (LED, OUTPUT); pinMode (BUTTON, INPUT); pullUpDnControl (BUTTON, PUD_UP); //  using a pull-up resistor for(;;) { if ( digitalRead (BUTTON) == HIGH ) { digitalWrite (LED, LOW); } else { digitalWrite (LED, HIGH); } delay (1); }

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE I 2 C – Inter-Integrated Circuit  Invented by Phillips in 1982  I 2 C specification I 2 C specification  A tradeoff between speed and area  Less spaces devoted to wires  Fewer wires can decrease throughput  A good idea for sensors  But not for disk drives  Adopted by Intel for personal computers  Under the name SMBus  00:1f.3 SMBus: Intel Corporation 82801JD/DO (ICH10 Family) SMBus Controller (rev 02)

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE I2CI2CI2CI2C  Understanding I 2 C  The physical I 2 C bus  Masters and Slaves  The physical protocol  I 2 C device addressing  The software protocol  I 2 C support in Linux kernel And Windows and Arduino And Microcontrollers and …  A good Tutorial at Robot ElectronicsTutorial Image credit:

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE The physical I 2 C bus  Two wires: SCL and SDA  SCL is the clock line: used to synchronize all data transfers  SDA is the data line  Both SCL and SDA lines are "open drain" drivers  Can only be driven low  For the line to go high provide a pull-up resistors to Vcc The value of Vcc is an example of something SMBus restricts Image credit: m/questions/70312/n-ch-fet-with- open-drain-output Image credit:

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE It might look like this

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Getting the Pi ready  Stop the “blacklisting” of I2C  In /etc/modprobe.d/raspi-blacklist.conf Comment out the blacklist of i2c-bcm2708  Add the appropriate modules  By adding the following lines to /etc/modules i2c-bcm2708 i2c-dev  Install a couple of packages i2c-tools libi2c-dev  Add user pi to group i2c  Reboot

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Linux i2c device interface  Device files are /dev/i2c-*  Major number is 89  Minor number is bus number  Linux device documentation for “userspace” Linux device documentation  The usual read and write are supported  but ioctl is the preferred interface  especially with smbus protocol macrossmbus protocol

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE The i2c utilities  Before programming, try the i2c utilities  i2cdetect  i2cdump  i2cget  i2cset  On Rev1 versions of the Raspberry Pi, the i2c devices on a bus 0

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Using the I 2 C utilities Using the I 2 C utilities finding the bus Using the I 2 C utilities  ls -l /dev/i2c-*  lsmod | grep i2c  id  i2cdetect –l  i2cdetect -y 1 Use 0 with Rev1

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Using the I 2 C utilities Using the I 2 C utilities finding the temperature Using the I 2 C utilities  i2cget -y 1 0x77 0xD0 b  Make sure you have a BMP180  i2cdump -r 0xAA-0xBF -y 1 0x77  Examine mysterious EEPROM registers  i2cdump -y -r 0xF4-0xF7 1 0x77  Examine measurement register  i2cset -y 1 0x77 0xF4 0x2E  Tell device to read temperature  i2cdump -y -r 0xF4-0xF7 1 0x77

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Programming examples  Read the temperature on BMP180  C program using device interface  C program with block read operation  Python program using SMBus module Which is really a Pythonized-C interface  Read acceleration using a LSM303  In Python using SMBus  And use i2c utilities from the shell  Which really isn’t programming

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Trying out the device interface  Take a look at the bmp180 programbmp180 program  Which should be in the examples directory  Note the usual structures  Lots of register definitions  Routines to interpret the data  Actions Open the device Read and write to the device

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE But what about the hard part?  Where does this come from x1 = (ut-ac6)*ac5/32768 ; x2 = mc * 2048 / (x1 + md) ; b5 = x1 + x2 ; t = (b5 + 8) / 16 ;  the BMP180 datasheetBMP180 datasheet  See page 15 for the details and don’t expect to understand why

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Secrets of the I2C sensor  Read the datasheet  Find an application note  Find example programs  Search for device drivers for the manufacturer  It should contain a lot of DEFINE  Try I 2 CdevlibI 2 Cdevlib

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Time to test it out  Compile the programs  Test it out  It should get warmer when touched  And colder when using an ice cube  The program has no filtering  So sometimes odd results are returned

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Running the simpler program  Compile it gcc -o bmp180json -DDEBUG bmp180json.c Or simply use make  Run it./bmp180json  Changing it?  Display the pressure

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Why Python?  A good “first” programming language  Especially if you don’t like the following public static void main(String[] args) int main(int argc, char *argv[])  Lots of good packages  Fun interfaces for kids  See Python for KidsPython for Kids  Generally easy to get something running  Mispelled varyabals can hide for months

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Python?

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Why the JSON?  Pretty to easy to read  Has a formal schema for validationformal schema for validation  Works well with web applications  JavaScript  HTML5  Will please the New Media students in CSCI 185  Supported in all common programming languages  is running on a Raspberry Pi Model B Rev MBtyes of RAM  Once it could tell you how hot it is over the web

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE Reading the temperature  No need to compile  Run it python bmp180json.py  Changing it?  Display the pressure

Dean Brock, Rebecca Bruce, and Marietta Cameron COMPUTER SCIENCE What about those interrupts?  Some I 2 C sensors do have interrupt lines  To “handle” an interrupt  Connect the interrupt line to a GPIO pin  Write to /sys/class/gpio/N/edge none, rising, falling, both  Use poll on /sys/class/gpio/N/value Waits for I/O activity with optional time-out  A hard system call to use  But there are many examples because of its frequent use in networking applications