Hardware Meets Software CPSC 120 Principles of Computer Science February 15, 2012.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Advertisements

Lab7: Introduction to Arduino
Boe-bots and STEM Boe-bots and STEM – This sectional will introduce participants to a programmable robot that is useful for engaging students in building.
MICROCONTROLLERS MODULE 2 Programming, Controlling and Monitoring.
Using the Board of Education Breadboard and Your Multimeter ENGR 120 Work in teams of two!
1 Boe-Bot Parts BOE-BOT Lecture #1b DE - Digital Electronics.
1 Lecture 1: Your Boe-Bot's Servo Motors Presentation based on: "Robotics with the Boe-Bot" By Andy Lindsay Parallax, Inc Presentation developed by: Martin.
Servos The material presented is taken from a variety of sources including:
Basic Stamp II is kinda cool Bytes of EEPROM(non-volatile) - Clock speed of 20 MHz. - Holds 600 lines of code in EEPROM - executes an average of.
University of Pennsylvania 1 The BASIC Stamp 2. University of Pennsylvania 2 The BASIC Stamp 2 Serial Signal Conditioning Conditions voltage signals between.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
ENGR 101: Robotics Lecture 2 – Text Programming Outline  Introduction to PBASIC  Variables, I/O, Arithmetic  Controlling the LEDs References 
1 Chapter Overview Computer Communication The Computer Bus Objectives  Understand how a computer transmits and receives information.  Explain the principles.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Digital I/O Connecting to the Outside World
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
LSU 06/04/2007BASIC Stamp Editor1 The BASIC Stamp Editor Programming Unit, Lecture 3.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Basic Stamp Quick Start. Basic Stamp II Self contained computer –“Micro-controller” Specialized for “embedded” computing (sensing and controlling things)
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
COMPONENTS OF THE SYSTEM UNIT
Microcontrollers Module 4: Motion Control. Module Objectives Upon successful completion of this module, students will be able to: Give examples of microcontroller.
MICROCONTROLLERS MODULE 2 Programming, Controlling and Monitoring.
BASIC Stamp Editor Once installed, the Stamp Editor will be available on your desktop, and as a menu option under Start  Program Files  Parallax Inc.
Designing A Computer CPSC 120 Principles of Computer Science February 6, 2012.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
Topics Introduction Hardware and Software How Computers Store Data
The Basic Stamp Instruction Set Architecture. The Microprocessor A microprocessor is a computer that typically has an architecture that is well suited.
MICRO CONTROLLER MODULE 1. Learning Objectives Name some gadgets that use microcontrollers. Define a microcontroller. Differentiate between a computer.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Tomorrow’s Technology and You 8/e Chapter 2 Hardware Basics: Inside the Box.
Controlling the Outside World
Programming the CheapBot-14. Start the Editor Set the Mode.
Computers Are Your Future Eleventh Edition Chapter 2: Inside the System Unit Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall1.
10/10/ Controlling YOUR ROBOT. 10/10/2015 Basic Stamp  Basic Stamp Input - output pins Interpreter Chip Power supply: 5 Volts voltage Memory: EEPROM.
IR Communication Materials taken from a variety of sources including IR Remote for the Boe-Bot by Andy Lindsay.
1 Lecture 1: Your Boe-Bot's Servo Motors Presentation based on: "Robotics with the Boe-Bot" By Andy Lindsay Parallax, Inc Presentation developed by: Martin.
IR Communication October 27, Sources  Lindsay, Andy. IR Remote for the Boe- Bot. v
Microcontrollers Module 3: Digital Display. 7 – Segment Display A seven-segment display (SSD), or seven- segment indicator, is a form of electronic display.
ENGR 101: Robotics Lecture 3 – Robot Motion Outline  Robot Motion  FOR Loops  Making Music References 
ENGR 101: Robotics Lecture 4 – Making Decisions Outline  The Stall Sensor  Making Decisions  Random Number Generation References 
July 7, 2003 Slide 1 of 6 Automation, Robotics and Mechatronics Lab, SUNY at Buffalo Introduction To Programming Chetan Jadhav Talib Bhabharawala Seung-Kook.
Slide Menlo Drive Suite 100 Rocklin, CA
July 18, UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon.
Concepts of Engineering and Technology Copyright © Texas Education Agency, All rights reserved.
Digital Electronics Board-of-Education : Output. Board of Education - Output This presentation will explain, both from a hardware and software perspective,
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 BOE-BOT Lecture #2 DE - Digital Electronics Servos and the BOE-BOT.
Information Technology INT1001 Lecture 2 1. Computers Are Your Future Tenth Edition Chapter 6: Inside the System Unit Copyright © 2009 Pearson Education,
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
The “Board of Education” 1 Three-position switch 0 = OFF 1 = ON / wheels OFF 2 = ON / wheels ON breadboard (for building circuits) electrical power (V.
Chapter 1: Introduction to Computers and Programming
Introduction to Servos
Topics Introduction Hardware and Software How Computers Store Data
IR Communication Materials taken from a variety of sources including IR Remote for the Boe-Bot by Andy Lindsay.
Chapter 1: Getting Started
Servos The material presented is taken from a variety of sources including:
Arduino Part 1 Topics: Microcontrollers Programming Basics
Servos The material presented is taken from a variety of sources including:
Programming Boe-Bots (Part 1)
Servos The material presented is taken from a variety of sources including:
Describe how NASA remotely controls equipment in space.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Controlling YOUR ROBOT
Topics Introduction Hardware and Software How Computers Store Data
Programming the BASIC Stamp
Lab #1: Getting Started.
Presentation transcript:

Hardware Meets Software CPSC 120 Principles of Computer Science February 15, 2012

Quick Reminder: Programming as Encoding  Recall we write computer programs in high level languages such as PBASIC, Java, C++, etc.  These commands are checked for correct spelling and use by a syntax checker  If acceptable, our program is translated into machine specific code by a compiler  This object code or machine code is downloaded to our target device, such as BS2, usually by serial cable or wireless link  This machine code is stored in RAM then fetched, decoded and executed one instruction after another until the program exits

Ideal view of the programming process. What is missing is the design phase and the edit-run-test-edit loop of revision and testing.

Basic Stamp Editor: An Integrated Development Environment (IDE)

Communication Channels  Notice we communicate with our BS2 through a serial link. One character after another sent along a wire. Examples are USB (Universal Serial Bus) and old fashioned RS-232.  Bits in serial mode are encoded as voltage up or down, a pulse, during a short time interval.  This compares to parallel mode of having 8 or more wires in a cable. Ex. Older printers.  ASCII code (American Standard Code for Information Interchange)is used to encode letters, digits, and control characters.  Basic unit is 8 bits called a byte to encode a character. There are 256 possible characters.  Unicode is a more modern extension of ASCII.

ASCII Code Chart

Integrated Circuits Our CPU and RAM are manufactured as integrated circuits. The metal tabs are called pins and allow communication between the IC and connected circuits. The high/low or Vdd/Vss values of certain pins can be set/controlled by our programs! Pin voltage can be read by our programs and thus allow our program to react accordingly. This is programmer controlled input/output or programmed I/O.

Controlling Input/Output Pins  Input/output pins on the Basic Stamp 2 IC are brought out to and are numbered on our BOE board for access via the breadboard.  BS2 has 16 I/O pins available via BOE, labeled P0, P1, P2, …, P14, P15, we can use to read/write values.  A TRUE/HIGH value on a pin means +5 volts (Vdd), a FALSE/LOW value means 0 volts (Vss).  Using program control, we can turn an LED on/off if we set up such a circuit on our breadboard connected to BS2 correctly!  As we can read pin values, we can also build sensor circuits on our breadboard so our robot will be smarter.

Creating a PBASIC program to control PIN values Here is our hardware arrangement with the resistors and LEDs controlled from pins P12 and P13 on the BOE

' Robotics with the Boe-Bot – HighLowLed.bs2 ' Turn the LED connected to P13 on/off once every second. ' Programmer: John Doe ' Date Created: 9/20/2007 ' Last modified: 2/15/2012 ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "The LED connected to Pin 13 is blinking!" DO ' Beginning of loop HIGH 13 ' Set pin 13 high PAUSE 500 ' Pause for 500 milliseconds LOW 13 ' Set pin 13 low PAUSE 500 ' Pause again for 500 milliseconds LOOP ' End of loop A simple PBASIC program to blink an LED

Controlling Servo Motors  Servo motors are electric motors controlled by digital signals, perfect for use with microcontrollers such as BS2  Servo motors have three attached wires: power (+6V), ground, and control  Servo motors rotate left or right depending on the width of a pulse on the control wire  The duration of a servo pulse is about 1.5 thousands of a second. 1.5 milliseconds!  We have library commands in our PBASIC language to generate such very short pulses  Using two servos, we can drive a robot around!

Servo motors attached to the Homework Board, our BOE-BOT connection is similar but easier!

' Robotics with the Boe-Bot - CenterServoP13.bs2 ' This program sends 1.5 ms pulses to the servo connected to ' P13 for servo centering. See BOE-BOT manual for details. ' Programmer: John Doe ' Date Created: 9/21/07 ' Date Modified: 9/24/07 ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 750 ' Send centering pulse to pin 13 PAUSE 20 ' Wait 20 milliseconds LOOP A PBASIC program to test centering of a servo attached to BOE

Review of Common Prefixes from SI Here are some standard prefix modifiers for multiples of number values: Deca: means 10. Ex. A geometric decagon has 10 sides. Kilo: means 1000 = Ex. A kilometer is 1000 meters. Mega: means 1,000,000 = Ex. A megabye of RAM is (about) one million bytes. [Actually it is 2 20 = 1,048,576 in binary] Giga: means 1,000,000,000 = Ex. A gigabyte of disk storage is (about) one billion bytes of storage space. [2 30 in binary] Other prefixes are used for fractions: Deci: means 1/10. Ex. To decimate is to destroy 1/10, also decimal. Centi: means 1/100 = 1 x Ex. Centimeter = 1/100 of a meter. Milli: means 1/1000 = 1 x Ex. A millisecond is 1/1000 of a second. Often denoted ms or msec. Micro: means 1/1,000,000 = 1 x Ex. A microsecond is 1 millionth of a second. Often denoted  sec. [Greek letter mu] Micro: means 1/1,000,000 = 1 x Ex. A microsecond is 1 millionth of a second. Often denoted  sec. [Greek letter mu]

Applications to PBASIC  We have seen how the DEBUG command acts like a mathematical function and takes arguments, the list of items to display. Ex. DEBUG CR, “Hello”, CR, “there!”  The PAUSE command takes one argument which is the number of milliseconds to simply wait, doing nothing.  PAUSE 500 ‘ Wait 1/2 second before continuing  The math: 1 ms x 500 = 500/1000 second = 1/2 second.  The PULSOUT command takes two arguments: A BS2 pin number and interval to create an up/down signal on that pin. However, the basic unit used is NOT milliseconds but 2 microseconds!  PULSOUT 12, 500 ‘ Create a pulse on pin 12 of 1 millisecond The math: 2  s x 500 = 1000  s = 1 millisecond.  So, this turns out to be exactly the kind of extremely short on/off interval we need to send to a servo motor to rotate in a particular direction.

' Robotics with the Boe-Bot - CenterServoP13.bs2 ' This program sends 1.5 ms pulses to the servo connected to ' P13 for manual centering. See BOE-BOT manual for details. ' Programmer: John Doe ' Date Created: 9/21/07 ' Date Modified: 2/15/12 ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 750 ' Send centering pulse to pin 13 PAUSE 20 ' Wait 20 milliseconds LOOP A PBASIC program to test centering of a servo attached to BOE

Variables in PBASIC  Variables are simply named memory locations we can use for arithmetic, control of loops, and storing sensor values. We choose the variable names!  You can declare four different types of variables in PBASIC:  Type Stores This Range of Number Values Bit 0 to 1 Nib 0 to 15 Byte 0 to 255 Word 0 to or to We need to choose the appropriate variable type when we plan on storing values in the variable

Variable Use and Assignments Here are some variable declarations and assignments (with some errors). Notice that PBASIC is not case-sensitive. You can use either upper or lower case letters for your code. Some other languages do not allow this! ‘ Variable declarations begin here Counter VAR WORD ON_OFFVARBIT LetterVARBYTE ‘ Some simple assignments begin here LETTER = 32 Letter = -1 ON_OFF = 4 Counter = 25 Counter = Counter * LETTER DO Counter = Counter + 1 LOOP

Loops in PBASIC We can use several different types of looping constructions in PBASIC depending on what we need to do. ‘ Simple FOR…NEXT loop to drive a servo for about 1 second counter VARWord FOR counter = 1 TO 46 ‘ Iterate this loop 46 times PULSOUT 13, 850‘ Drive servo attached to pin 13 forward, 1.7 ms PAUSE 20 ‘ Do nothing for 20 ms NEXT ‘ Increment our counter variable, then top of loop PULSOUT 13, 750‘ Stop the servo by using the centering value This code “loops” or iterates through the two commands in the body of of the loop as the counter variable (started at 1) is automatically incremented by one each time through. When counter reaches 46, we do one last pass through the loop, then exit to go to the next PBASIC instruction.