Datasheets.org.uk - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine
  
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

Student Guide WARRANTY Parallax warrants products against de


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet


wiring circuit stepper motor - wiring circuit stepper motor  
web controlled pick and place robot - web controlled pick and place robot  
Solar Traffic LED Flasher - Solar Traffic LED Flasher  
pushbutton* - pushbutton*  
photoresistor datasheet - photoresistor datasheet  
Photoresistor 5 mm - Photoresistor 5 mm  
Photoresistor - Photoresistor  
parallax-boe-bot - parallax-boe-bot  
parallax* key BS2 - parallax* key BS2  
parallax 900 - parallax 900  
Parallax - Parallax  
nokia tv - nokia tv  
nokia buzzer - nokia buzzer  
nokia 3520 - nokia 3520  
music keyboard encoder schematic - music keyboard encoder schematic  
motion sensing camera - motion sensing camera  
mini four channel radio control use in rc airplan - mini four channel radio control use in rc airplan  
microwave motion sensors - microwave motion sensors  
LED-BICOLOR - LED-BICOLOR  
computer science mini projects creating college h - computer science mini projects creating college h  
coming home sheet music on piano - coming home sheet music on piano  
code for controlling robot by usb port - code for controlling robot by usb port  
circuit diagram used for pick and place robot - circuit diagram used for pick and place robot  
circuit diagram of moving LED message display - circuit diagram of moving LED message display  
cell phone CONTROLLED ROBOT - cell phone CONTROLLED ROBOT  
Cell phone controlled pick and place robot - Cell phone controlled pick and place robot  
Camera with LED Flash Module model - Camera with LED Flash Module model  
camera Nokia - camera Nokia  
BS2-IC - BS2-IC  

What's Microcontroller?
Student Guide
WARRANTY
Parallax warrants products against defects materials workmanship period days from receipt product. discover defect, Parallax will, option, repair replace merchandise, refund purchase price. Before returning product Parallax, call Return Merchandise Authorization (RMA) number. Write number outside used return merchandise Parallax. Please enclose following along with returned merchandise: your name, telephone number, shipping address, description problem. Parallax will return your product replacement using same shipping method used ship product Parallax.
14-DAY MONEY BACK GUARANTEE
within days having received your product, find that does suit your needs, return full refund. Parallax will refund purchase price product, excluding shipping/handling costs. This guarantee void product been altered damaged. Warranty section above instructions returning product Parallax.
COPYRIGHTS TRADEMARKS
This documentation copyright 2003 Parallax, Inc. downloading obtaining printed copy this documentation software agree that used exclusively with Parallax products. other uses permitted represent violation Parallax copyrights, legally punishable according Federal copyright intellectual property laws. duplication this documentation commercial uses expressly prohibited Parallax, Inc. Duplication educational permitted, subject Conditions Duplication stated Preface. BASIC Stamp, Stamps Class, Board Education registered trademarks Parallax, Inc. decide names BASIC Stamp, Stamps Class, and/or Board Education your page printed material, must state that "BASIC Stamp registered trademark Parallax, Inc.," Stamps Class registered trademark Parallax, Inc.," and/or "Board Education registered trademark Parallax, Inc.," respectively, upon first appearance trademark name. Other brand product names trademarks registered trademarks their respective holders.
ISBN 1-928982-02-6 DISCLAIMER LIABILITY
Parallax, Inc. responsible special, incidental, consequential damages resulting from breach warranty, under legal theory, including lost profits, downtime, goodwill, damage replacement equipment property, costs recovering, reprogramming, reproducing data stored used with Parallax products. Parallax also responsible personal damage, including that life health, resulting from products. take full responsibility your BASIC Stamp application, matter lifethreatening
SITE DISCUSSION LISTS
Parallax site (www.parallax.com) many downloads, products, customer applications on-line ordering components used this text. also maintain several e-mail discussion lists people interested
using Parallax products. These lists accessible from www.parallax.com Support menu. These lists that operate:
Discussion Groups
BASIC Stamps With over 2,500 subscribers, this list widely utilized engineers, hobbyists students share their BASIC Stamp projects questions. Stamps Class Created educators students, this list subscribers discuss Stamps Class curriculum their courses. list provides opportunity both students educators questions answers. Parallax Educators -Exclusively educators those contribute development Stamps Class. Parallax created this group obtain feedback curricula provide forum educators develop obtain Teacher's Guides. Parallax Translators Consisting less than people, purpose this list provide conduit between Parallax those translate documentation languages other than English. Parallax provides editable Word documents translating partners attempts time translations coordinate with publications. Toddler Robot customer created this discussion list discuss applications programming Parallax Toddler robot. Tech Discussion programming microcontroller with Parallax assembly language tools party BASIC compilers. Approximately members. Javelin Stamp Discussion application design using Javelin Stamp, Parallax module that programmed using subset Microsystems' Java® programming language. Approximately members.
ERRATA
While great effort made assure accuracy texts, errors still exist. find error, please know sending email editor@parallax.com. continually strive improve educational materials documentation, frequently revise texts. Occasionally, Errata sheet with list known errors corrections given text will posted site, www.parallax.com. Please check individual product page's free downloads errata file.
Table Contents Page
Table Contents
Preface.v
Audience.v Support Teacher's Guide.v Stamps Class Curriculum Conditions Duplication .vii Foreign Translations .vii Special Contributors .vii
Chapter Getting Started.1
Many Microcontrollers Today? BASIC Stamp Your Microcontroller.1 Amazing Inventions with BASIC Stamp.2 Hardware Software Activity Getting Software.5 Activity Installing Software Activity Setting Hardware Testing System Activity First Program.21 Activity Looking Answers Activity When You're Done SUMMARY
Chapter Lights Lights
Indicator Lights Making Light Emitting Diode (LED) Emit Light.37 Activity Building Testing Circuit.38 Activity On/Off Control with BASIC Stamp.47 Activity Counting Repeating.52 Activity Building Testing Second Circuit Activity Using Current Direction Control Bi-Color SUMMARY
Chapter Digital Input Pushbuttons.71
Found Calculators, Hand Held Games, Appliances Receiving Sending High Signals Activity Testing Pushbutton with Circuit.71 Activity Reading Pushbutton with BASIC Stamp Activity Pushbutton Control Circuit Activity Pushbuttons Controlling Circuits.83 Activity Reaction Timer Test SUMMARY
Page What's Microcontroller?
Chapter Controlling Motion
Microcontrolled Motion On/Off Signals Motor Motion Activity Connecting Testing Servo. Activity Controlling Position with Your Computer Activity Converting Position Motion Activity Pushbutton Controlled Servo SUMMARY
Chapter Measuring Rotation.
Adjusting Dials Monitoring Machines. Variable Resistor under Dial Potentiometer. Activity Building Testing Potentiometer Circuit Activity Measuring Resistance Measuring Time Activity Reading Dial with BASIC Stamp Activity Controlling Servo with Potentiometer. SUMMARY
Chapter Digital Display.
Every-Day Digital Display. What's 7-Segment Display? Activity Building Testing 7-Segment Display Activity Controlling 7-Segment Display. Activity Displaying Digits. Activity Displaying Position Dial. SUMMARY
Chapter Measuring Light.
Devices that Contain Light Sensors Introducing Photoresistor. Activity Building Testing Light Meter. Activity Graphing Light Measurements. Activity Tracking Light Events. Activity Simple Light Meter SUMMARY
Chapter Frequency Sound
Your Electronic Beeps. Microcontrollers, Speakers, Beeps On/Off Signals Activity Building Testing Speaker Activity Action Sounds Activity Musical Notes Simple Songs Activity Microcontroller Music Activity Cell Phone RingTones
Table Contents Page
SUMMARY .253
Chapter Electronic Building Blocks .257
Those Little Black Chips .257 Expand Your Projects with Peripheral Integrated Circuits .258 Activity Control Current Flow with Transistor.259 Activity Introducing Digital Potentiometer .261 SUMMARY .271
Chapter #10: Running Whole Show .273
Subsystem Integration .273 Activity Building Testing Each Pushbutton Circuit .274 Activity Building Testing Each RC-Time Circuit .277 Activity Subsystem Integration Example.279 Activity Developing Adding Software Subsystem .283 SUMMARY .289
Appendix Serial Adaptor.293 Appendix Equipment Parts Lists.295 Appendix BASIC Stamp Carrier Board Components Functions.299 Appendix Batteries Power Supplies.303 Appendix Trouble-Shooting.307 Appendix More About Electricity.309 Appendix RTTTL Format Summary .317 Index .319
Preface Page
Preface
This text answers question "What's microcontroller?" showing students they design their customized, intelligent inventions using BASIC Stamp. activities this text incorporate variety interesting experiments designed appeal student's imagination using motion, light, sound, tactile feedback introduce concepts. These activities designed introduce students variety basic principles fields computer programming, electricity electronics, mathematics physics. Many activities facilitate hands-on presentation design practices used engineers technicians creation modern machines appliances using inexpensive easily obtainable parts.
AUDIENCE
This text organized that used widest possible variety students well independent learners. Middle school students examples this text guided tour fashion simply following check-marked instructions instructor supervision. other spectrum, pre-engineering students' problem-solving skills challenged last activity each chapter assignments Projects section each chapter. Independent learners work their pace, obtain assistance through Stamps Class forum cited below.
SUPPORT TEACHER'S GUIDE
following Parallax Yahoo! Discussion Groups available those would like support using this text: Stamps Class Group: Open students, educators, independent learners, this forum allows members each other questions share answers they work through activities, exercises projects this text. Parallax Educator's Group: Teacher's Guide this text available only educators; obtained through this forum after proof status educator been verified Parallax. This moderated forum provides support educators welcomes feedback continue develop Stamps Class curriculum. These groups accessible from www.parallax.com under Discussion Groups Support menu. having difficulty subscribing either these Yahoo! Groups,
Page What's Microcontroller?
have other questions about this text Stamps Class, contact Parallax Stamps Class Team directly stampsinclass@parallax.com.
STAMPS CLASS CURRICULUM
What's Microcontroller? gateway text Stamps Class curriculum. After completing this text, continue your studies with Student Guides listed below. books listed available free download from www.parallax.com. versions cited below were current time this printing. Please check sites www.parallax.com www.stampsinclass.com latest revisions; continually strive improve educational program. Stamps Class Student Guides: well-rounded introduction design practices that into modern devices machinery, working through activities projects following Student Guides highly recommended. "Applied Sensors", Student Guide, Version 2.0, Parallax Inc., 2003 "Basic Analog Digital", Student Guide, Version 2.0, Parallax Inc., 2003 "Industrial Control", Student Guide, Version 2.0, Parallax Inc., 2002 "Robotics!", Student Guide, Version 1.5, Parallax Inc., 2000 More Robotics Kits: Some enter Stamps Class curriculum through Robotics! Student Guide. After completing will ready either both these more advanced robotics texts kits: "Advanced Robotics: with Toddler", Student Guide, Version 1.2, Parallax Inc., 2003 "SumoBot", Student Guide, Version 1.1, Parallax Inc., 2002 Educational Project Kits: Elements Digital Logic Understanding Signals focus more closely topics electronics, while StampWorks provides variety projects that useful hobbyists, inventors product designers interested trying variety projects.
Preface Page
"Elements Digital Logic", Student Guide, Version 1.0, Parallax Inc., 2003 "StampWorks", Manual, Version 1.2, Parallax Inc., 2001 "Understanding Signals", Student Guide, Version 1.0, Parallax Inc., 2003 Reference This book essential reference Stamps Class Student Guides. packed with information BASIC Stamp microcontrollers, Board Education other carrier boards, BASIC Stamp Editor, PBASIC programming language. "BASIC Stamp Manual", Users Manual, Version 2.0c, Parallax Inc., 2000
CONDITIONS DUPLICATION
Parallax grants user conditional right download, duplicate, distribute this text without Parallax's permission. This right based following conditions: text, portion thereof, duplicated commercial use; duplicated only educational purposes when used solely conjunction with Parallax products, user recover from student only cost duplication. This text available printed format from Parallax, Inc. Because print text volume, consumer price often less than typical retail duplication charges.
FOREIGN TRANSLATIONS
Parallax educational texts translated other languages with permission (email stampsinclass@parallax.com). plan doing translations please contact provide correctly-formatted Word documents, images, etc. also maintain discussion group Parallax translators that join. It's called Parallax Translators Yahoo-group, directions finding included inside cover this text. section entitled: SITE DISCUSSION LISTS after Title page.
SPECIAL CONTRIBUTORS
Parallax team assembled write this text includes: curriculum design technical writing Andy Lindsay, illustration Rich Allred, cover design Jacobs Larissa Crittenden, general consulting Aristides Alvarez Jeff Martin, electromechanical consulting John Barrowman, technical review Kris Magri,
Page viii What's Microcontroller?
technical editing Stephanie Lindsay, committee review Rich Allred, Gabe Duran, Stephanie Lindsay, Kris Magri. What's Microcontroller? Student Guide Version written Andy Lindsay after collecting observations educator feedback while traveling nation teaching Parallax Educators Courses. Andy studied Electrical Electronic Engineering California State University, Sacramento, this third Stamps Class Student Guide. also contributing author several papers that address topic microcontrollers pre-engineering curricula. When he's writing educational material, Andy does product engineering Parallax. Parallax wishes thank StampsInClass Yahoo Group member Robert thorough draft review detailed input, veteran engineer esteemed customer Weaver insightful review. Thanks also Stamps Class authors Tracy Allen (Applied Sensors), Martin Hebel (Industrial Control) their review recommendations. Andy Lindsay wishes thank father Marshall brother-in-law Kubilay their expert musical advice suggestions. Stamps Class founded Gracey, wishes thank Parallax staff great they Each every Parallaxian made contributions this every Stamps Class text.
Chapter Getting Started Page
Chapter Getting Started
MANY MICROCONTROLLERS TODAY?
microcontroller kind miniature computer that find kinds gizmos. Some examples common, every-day gizmos that have microcontrollers builtin shown Figure 1-1. buttons digital display, chances also programmable microcontroller brain.
Figure Every-Day Examples Devices that Contain Microcontrollers
making list counting many devices with microcontrollers typical day. Here some examples: your clock radio goes off, snooze button times morning, first thing your interact with microcontroller. Heating some food microwave oven making call cell phone also involves operating microcontrollers. That's just beginning. Here more examples: turning television with handheld remote, playing handheld game, using calculator, checking your digital wristwatch. those devices have microcontrollers inside them that interact with you.
BASIC STAMP YOUR MICROCONTROLLER
BASIC Stamp module shown Figure microcontroller built onto It's black chip with lettering that reads "PIC16C57". rest components BASIC Stamp also found consumer appliances every day. together, they called embedded computer system. This name almost always shortened just "embedded system". activities this text will guide through building circuits similar ones found consumer appliances high-tech gizmos. will also write computer programs that BASIC Stamp will run. These programs will make BASIC Stamp monitor control these circuits that they perform useful functions.
Page What's Microcontroller?
Figure BASIC Stamp
this text, BASIC Stamp used refer BASIC Stamp There other BASIC Stamps, some which shown Figure 1-3. Each BASIC Stamp color coded. BASIC Stamp green. BASIC Stamp red. BASIC Stamp blue, BASIC Stamp gold. Each variation BASIC Stamp slightly different, featuring higher speed, more memory, additional functionality, some combination these extra features.
Figure BASIC Stamp Modules From Left Right: BASIC Stamp 2SX,
AMAZING INVENTIONS WITH BASIC STAMP
Consumer appliances aren't only things that contain microcontrollers. Robots, machinery, aerospace designs other high-tech devices also built with microcontrollers. Let's take look some examples that were created with BASIC Stamps. Robots have been designed everything from helping students learn more about microcontrollers, mowing lawn, solving complex mechanical problems. Figure shows example robots. each these robots, students BASIC Stamp read sensors, control motors, communicate with other computers. robot left called Boe-Bot. projects Robotics! text tackled using Boe-Bot after you've worked through activities this one. robot right
Chapter Getting Started Page
built group students entered into recent First Robotics competition. goal contest different each year. example shown, goal which group's robot could sort colored hoops fastest.
Figure Educational Robots Parallax Boe-Bot (left) First Competition Robot (right)
Other robots solve complex problems, such autonomous remote flight robot shown left Figure 1-5. This robot built tested mechanical engineering students University California, Irvine. They used BASIC Stamp help communicate with satellite global positioning system (GPS) that robot could know position altitude. BASIC Stamp also read level sensors controlled motor settings keep robot flying properly. mechanical millipede robot right developed professor Nanyang Technical University, Singapore. more than BASIC Stamps, they communicate with each other elaborate network that helped control orchestrate motion each legs. Robots like this only help better understand designs nature, they eventually used explore remote locations, even other planets.
Figure Examples Research Robots that Contain Microcontrollers Autonomous flying robot Irvine (left) Millipede Project Nanyang University (right)
With help microcontrollers, robots will also take day-to-day tasks, such mowing lawn. BASIC Stamp inside robotic lawn mower shown Figure
Page What's Microcontroller?
helps stay inside boundaries lawn, also reads sensors that detect obstacles controls motors that make move.
Figure Robotic Lawn Mower Prototype Robot Shop
Microcontrollers also used scientific, high technology, aerospace projects. weather station shown left Figure used collect environmental data related coral reef decay. BASIC Stamp inside gathers this data from variety sensors stores later retrieval scientists. submarine center undersea exploration vehicle, thrusters, cameras lights controlled BASIC Stamps. rocket shown right that part competition launch privately owned rocket into space. Nobody competition, this rocket almost made because launched from platform raised high altitudes weather balloons. BASIC Stamp controlled just about every aspect launch sequence sensing altitude, communicating information ground based technicians, triggering actual launch.
Figure High-tech Aerospace Microcontroller Examples Ecological data collection Systems (left), undersea research Harbor Branch Institute (center), Aerospace test launch (right)
From common household appliances through scientific aerospace applications, microcontroller basics will need started projects like these introduced here. working through activities this book, will
Chapter Getting Started Page
experiment with learn variety building blocks found these cool gizmos. will build circuits displays, sensors, motion controllers. will learn connect these circuits BASIC Stamp, then write computer programs that make control displays, collect data from sensors, control motion. Along way, will learn many important electronic computer programming concepts techniques. time you're done, might find yourself well inventing gizmo your design.
HARDWARE SOFTWARE
Getting started with BASIC Stamp similar getting started with brand-new laptop. first things that most people have when they laptop take box, plug install test some software, maybe even write some software their using programming language. this your first time using BASIC Stamp, will doing these same activities. class, BASIC Stamp already you. this case, your teacher have other instructions. not, activities this chapter will take through steps getting your BASIC Stamp computer running.
ACTIVITY GETTING SOFTWARE
BASIC Stamp Editor (version higher) software will most activities projects this text. will this software write programs that BASIC Stamp will run. also this software display messages sent BASIC Stamp that help understand what senses.
BASIC Stamp Editor free software, easiest ways are: Download from Internet: Look "BASIC Stamp Windows Editor version 2.0." www.parallax.com Downloads BASIC Stamp Software page. Included Parallax Follow Software link Welcome page. Make sure date printed 2003 newer. Hurry? your copy BASIC Stamp Windows Editor version higher) install your laptop. Then, skip Activity Setting Hardware Testing System. have questions along way, Activity used step-by-step reference getting software, Activity used reference installation procedure.
Page What's Microcontroller?
Computer System Requirements
will need either laptop computer BASIC Stamp Editor software. Getting started with BASIC Stamp easiest your laptop following features: Windows newer operating system serial port CD-ROM drive, World Wide access, both
Port Adaptor your computer only ports, will need Serial Adaptor. Appendix Serial Adaptor details installation instructions.
Downloading Software from Internet
It's easy download BASIC Stamp Editor software from Parallax site. page shown Figure look different from page when visit site. Nonetheless, steps downloading software should still similar these: Using browser, www.parallax.com (shown Figure 1-8). Point Downloads menu display options. Point BASIC Stamp Software link click select
Figure Parallax Site: www.parallax.com
Chapter Getting Started Page
When BASIC Stamp Software page, find most recent version BASIC Stamp Windows Editor download, with version number higher. Click Download icon. Figure 1-9, download icon looks like file folder right description: "BASIC Stamp Windows Editor version Beta (6MB)".
Figure Parallax Site Downloads Page
When File Download window shown Figure 1-10 appears, select: Save this program disk. Click button.
Figure 1-10 File Download Window
Figure 1-11 shows Save window that appears next. Save field browse your computer's hard drives find convenient place save file. After choosing where save file downloading, click Save Button.
Page What's Microcontroller?
Figure 1-11 Save Window Selecting place save file
Wait while BASIC Stamp Editor installation program downloads (shown Figure 1-12). This take while using modem connection.
Figure 1-12 Download Progress Window
When download complete, leave window shown Figure 1-13 open while skip next section Activity Installing Software.
Figure 1-13 Download Complete Activity Installing Software.
Chapter Getting Started Page
Other free downloads Parallax site include: This text other Stamps Class texts Robot Videos More free software Hundreds applications experiments
Finding Software Parallax
also install BASIC Stamp Editor from Parallax 2003 newer that version BASIC Stamp Editor that compatible with examples this text. find Parallax CD's Year Month examining labeling front Place Parallax into your computer's drive. Parallax browser called Welcome application. It's shown Figure 1-14 should soon load into your computer's drive. Welcome application does automatically run, double-click Computer, then double-click your drive, then double-click Welcome. Click Software link shown Figure 1-14.
Figure 1-14 Parallax Browser
Click next BASIC Stamps folder shown Figure 1-15. Click next Windows folder.
Page What's Microcontroller?
Click floppy diskette icon labeled "Stamp 2/2e/2sx/2p/2pe (stampw.exe)". Move Activity Installing Software.
Figure 1-15 Parallax Browser Select BASIC Stamp Editor installation program from Software page.
Free downloads Parallax site included Parallax only date created. date front indicates when created. just months old, will probably have most up-to-date material. it's older consider requesting from Parallax downloading files need from Parallax site.
ACTIVITY INSTALLING SOFTWARE
now, have either downloaded BASIC Stamp Editor Installer from Parallax site located Parallax it's time BASIC Stamp Editor Installer.
Installing Software Step Step
downloaded BASIC Stamp Editor Installer from Internet, click Open Folder button Download Complete window shown Figure 1-16.
Chapter Getting Started Page
Figure 1-16 Download Complete Window skipped here from "Downloading Software from Internet" section, click Open button.
located software Parallax click Install button shown Figure 1-17.
Figure 1-17 Parallax Browser Install button located near bottom window.
When BASIC Stamp Editor's InstallShield Wizard window opens, click Next button shown Figure 1-18.
Figure 1-18 InstallShield Wizard BASIC Stamp Editor Click Next.
Select Typical your setup type shown Figure 1-19.
Page What's Microcontroller?
Click Next button.
Figure 1-19 Setup Type Click Typical, then click Next button.
When InstallShield Wizard tells "Ready Install Program", click Install button shown Figure 1-20.
Figure 1-20 Ready Install. Click Install button.
When InstallShield Wizard window tells "InstallShield Wizard Completed", shown Figure 1-21, click Finish.
Chapter Getting Started Page
Figure 1-21 InstallShield Wizard Completed: Click Finish button.
ACTIVITY SETTING HARDWARE TESTING SYSTEM
BASIC Stamp needs connected power run. also needs connected programmed. After making these connections, BASIC Stamp Editor test system. This activity will show how.
Introducing BASIC Stamp, Board Education, HomeWork Board
BASIC Stamp Board Education shown Figure 1-22. mentioned earlier, BASIC Stamp very small computer. This very small computer plugs into Board Education, which called carrier board. will soon see, Board Education makes easy connect power supply serial cable BASIC Stamp. later activities, will also Board Education makes easy build circuits connect them BASIC Stamp.
Figure 1-22 BASIC Stamp (left) Board Education (right)
Page What's Microcontroller?
BASIC Stamp HomeWork Board shown Figure 1-23. This board like Board Education with BASIC Stamp built-in. either Board Education BASIC Stamp HomeWork Board activities this text.
Figure 1-23 BASIC Stamp HomeWork Board
Learn more about features parts functions BASIC Stamp, Board Education, HomeWork Board. Appendix BASIC Stamp Carrier Board Components Functions page 299.
Required Hardware
BASIC Stamp Board Education BASIC Stamp HomeWork Board Figure 1-24: battery Strip with four adhesive rubber feet Serial cable
Chapter Getting Started Page
Figure 1-24 Battery, Rubber Feet, Serial Cable
Start with fully charged battery. Avoid confusion dead battery cause. Start with alkaline battery rechargeable battery that recently been fully recharged.
CAUTION Before using adaptor, "battery replacer", supply: Consult Appendix Batteries Power Supplies page make sure supply appropriate activities this text.
Connecting Hardware
Both Board Education BASIC Stamp HomeWork Board come with strip that four adhesive rubber feet. These rubber feet shown Figure 1-25, they should affixed underside your Board Education BASIC Stamp HomeWork Board.
Figure 1-25 Rubber Feet
using Board Education, circles underside that show where each rubber foot should attached. Remove each rubber foot from adhesive strip affix underside Board Education shown Figure 1-26.
Page What's Microcontroller?
Figure 1-26 Rubber Foot Affixed Underside Board Education
using BASIC Stamp HomeWork Board, remove each rubber foot from adhesive strip affix underside HomeWork Board, next each plated hole each corner board shown Figure 1-27.
Figure 1-27 Rubber Foot Affixed Underside HomeWork Board
Next, Board Education BASIC Stamp HomeWork Board should connected your laptop serial cable. Connect your serial cable available port back your computer shown Figure 1-28.
Port Adaptor using Serial adaptor: Connect your PC's port. Connect port adaptor either directly your Board Education HomeWork Board, connect serial cable shown Figure 1-28.
Chapter Getting Started Page
Figure 1-28 Laptop Port Plug serial cable into available port your laptop.
using BASIC Stamp Board Education: 3-position switch Board Education position-0 shown Figure 1-29.
Figure 1-29 3-position Switch
Reset
position turn power.
Only Board Education 3-position switch. turn power Board Education simply disconnect power source either unplugging supply battery These shown Figure 1-30, step
your BASIC Stamp already plugged into your Board Education, insert into socket shown Figure 1-30, step-1. Make sure pins lined properly with holes socket, then press down firmly. Plug serial cable into Board Education shown step-2. Plug power supply into jack shown step-3, plug battery into battery jack shown step-4. Move 3-position switch from position-0 position-1. green light labeled Board Education should
Page What's Microcontroller?
6-9VDC
Powercell
Alkaline Battery
Black
Battery
Sout
Figure 1-30 Board Education, BASIC Stamp, Battery Serial Cable. Connect components order shown diagram.
Reset
Board Education
2000-2003
www.stampsinclass.com
using BASIC Stamp HomeWork Board: Connect serial cable HomeWork Board shown Figure 1-31, step1. Connect battery battery clip shown step-2.
Chapter Getting Started Page
Figure 1-31 HomeWork Board Serial Cable
(916) 624-8333 www.parallaxinc.com www.stampsinclass.com
Plug serial cable battery into HomeWork Board.
Power
BASIC Stamp HomeWork Board
Testing Communication
BASIC Stamp Editor feature testing make sure your laptop communicate with your BASIC Stamp. Double-click BASIC Stamp Editor shortcut your desktop. should look similar shown Figure 1-32.
Figure 1-32 BASIC Stamp Editor Shortcut Look shortcut similar this your computer's desktop.
Alkaline Battery
Powercell
Reset
2002
Page What's Microcontroller?
Windows Start Menu also used BASIC Stamp Editor. Click your Windows Start button, then select Programs Parallax, Inc. Stamp Editor then click BASIC Stamp Editor icon.
Your BASIC Stamp Editor window should look similar shown Figure 1-33.
first time your BASIC Stamp Editor, display some messages list your ports found software.
make sure your BASIC Stamp communicating with your computer, click menu, then select Identify.
Figure 1-33 BASIC Stamp Editor Select Identify from menu.
Identification window similar shown Figure 1-34 will appear. example figure shows that BASIC Stamp been detected COM2. Check Identification window make sure BASIC Stamp been detected ports. BASIC Stamp been detected, then ready Activity First Program. Identification window does detect BASIC Stamp ports, Appendix Trouble-Shooting.
Figure 1-34 Identification Window Example: BASIC Stamp found COM2.
Chapter Getting Started Page
ACTIVITY FIRST PROGRAM
first program will write test will tell BASIC Stamp send message your laptop. Figure 1-35 shows BASIC Stamp sends stream ones zeros communicate text characters displayed laptop. These ones zeros called binary numbers. BASIC Stamp Editor software ability detect display these messages will soon see.
10101001
Powercell
Alkaline Battery
Figure 1-35 Messages from BASIC Stamp Your Computer
6-9VDC
First Program
program listings that will type into BASIC Stamp Editor download BASIC Stamp will always shown with gray background. Here example:
Example Program: FirstProgram.bs2
What's Microcontroller FirstProgram.bs2 BASIC Stamp sends message Debug Terminal. {$STAMP BS2}
Battery
STAM CLASS
Sout
BASIC Stamp sends characters your laptop transmitting stream binary ones zeros. BASIC Stamp Editor detect convert these binary codes characters display them.
www.stampsinclass.com
Page What's Microcontroller?
{$PBASIC 2.5} DEBUG "Hello, it's your BASIC Stamp!"
Type this program into BASIC Stamp Editor shown Figure 1-36.
Figure 1-36 First Program Entered into Editor Enter your first program into BASIC Stamp Editor shown here.
Save your work clicking File selecting Save, (shown Figure 1-37).
Figure 1-37 Saving First Program
Enter name FirstProgram into File name field near bottom Save window shown Figure 1-38. Click Save button.
Figure 1-38 Entering File Name
Chapter Getting Started Page
next time save, BASIC Stamp Editor will automatically save same filename (FirstProgram.bs2) unless tell save different filename clicking File selecting Save (instead just Save).
Click Run, select from menu that appears clicking shown Figure 1-39.
Figure 1-39 Running Your First Program
Download Progress window will appear briefly program transmitted from laptop your BASIC Stamp. Figure 1-40 shows Debug Terminal that should appear when download complete. prove yourself that this message from BASIC Stamp pressing releasing button labeled (Board Education) Reset (HomeWork Board). This button called reset button. Every time press release program will re-run, will another copy message displayed Debug Terminal. Press release reset button. second "Hello." message appear Debug Terminal?
Figure 1-40 Debug Terminal Debug Terminal displays messages sent PC/laptop BASIC Stamp.
Page What's Microcontroller?
BASIC Stamp Editor shortcuts most common tasks. example, program, press `Ctrl' keys same time. also click button. It's blue triangle shown Figure 1-41 that looks like player's Play button. flyover help (the hint) will appear point button with your mouse. similar hints find what other buttons pointing them too. Figure 1-41 BASIC Stamp Editor Shortcut Buttons
FirstProgram.bs2 Works
first lines example called comments. comment line text that gets ignored BASIC Stamp Editor, because it's meant human reading program, BASIC Stamp. PBASIC, everything right apostrophe normally considered comment BASIC Stamp Editor. first comment tells which book example program from what program's filename second comment contains handy, one-line description that explains what program does.
What's Microcontroller FirstProgram.bs2 BASIC Stamp sends message Debug Terminal.
Although comments ignored most time, BASIC Stamp Editor does search through comments special directives. Every program this text will these directives:
{$STAMP BS2} {$PBASIC 2.5}
first directive called Stamp Directive, tells BASIC Stamp Editor that will downloading program BASIC Stamp second directive called PBASIC directive, tells BASIC Stamp Editor that using version PBASIC programming language. command word tell BASIC Stamp certain job. first commands this program called DEBUG command:
DEBUG "Hello, it's your BASIC Stamp!"
Chapter Getting Started Page
This command that tells BASIC Stamp send message using serial cable. second command called command:
This command handy because puts BASIC Stamp into power mode when it's done running program. power mode, BASIC Stamp waits either reset button pressed (and released), program loaded into BASIC Stamp Editor. reset button your board pressed, BASIC Stamp will re-run program loaded into program loaded into erased, program begins run.
Your Turn DEBUG Formatters Control Characters
DEBUG formatter code-word make message BASIC Stamp sends look certain Debug Terminal. example formatter that makes Debug Terminal display decimal value. example control character which used send carriage return Debug Terminal. text numbers that come after will appear line below characters that came before modify your program that contains more DEBUG commands along with some formatters control characters. Here's example First, save program under name clicking File selecting Save good name file would FirstProgramYourTurn.bs2 Modify comments beginning program that they read:
What's Microcontroller FirstProgramYourTurn.bs2 BASIC Stamp sends messages Debug Terminal.
these three lines between first DEBUG command command:
DEBUG "What's 11?" DEBUG "The answer DEBUG
Save changes made clicking File selecting Save. Your program should look like shown Figure 1-42.
Page What's Microcontroller?
your modified program. Hint: will have either click from menu again, like Figure 1-39 click button, like Figure 1-41.
Figure 1-42 Modified FirstProgram Check your work against example program shown here.
Where Debug Terminal Sometimes Debug Terminal gets hidden behind BASIC Stamp Editor window. bring back front using menu shown left Figure 1-43, Debug Terminal shortcut button shown right figure, your keyboard. Figure 1-43 Debug Terminal Foreground Using menu (left) using shortcut button (right).
Your Debug Terminal should resemble Figure 1-44.
Figure 1-44 Modified FirstProgram.bs2 Debug Terminal Output Make sure that when re-run your program, results expect.
Chapter Getting Started Page
ACTIVITY LOOKING ANSWERS
example program just finished introduced PBASIC commands: DEBUG END. find more about these commands they used looking them either BASIC Stamp Editor's Help BASIC Stamp Manual. This activity guides through example looking DEBUG using BASIC Stamp Editor's Help BASIC Stamp Manual.
Using BASIC Stamp Editor's Help
BASIC Stamp Editor, Click Help, then select Index shown Figure 145.
Figure 1-45 Selecting Index from Help Menu
Type DEBUG into field labeled Type keyword find: (shown Figure 1-46). When word DEBUG appears list below where typing, click then click Display button.
Page What's Microcontroller?
Figure 1-46 Looking DEBUG Command Using Help.
Your Turn
scrollbar review DEBUG command's write-up. Notice that lots explanations example programs try. Click Contents tab, find DEBUG there. Click Search tab, search word DEBUG. Repeat this process command.
Getting Using BASIC Stamp Manual
BASIC Stamp Manual available free download from Parallax site, it's also included Parallax also purchased bound printed manual.
Chapter Getting Started Page
Downloading BASIC Stamp Manual from Parallax Site Using browser, www.parallax.com. Point Downloads menu display options. Point Documentation link click select When BASIC Stamp Documentation page, find BASIC Stamp Users Manual. Click Download icon that looks like file folder right description: "BASIC Stamp User's Manual Version (3.2 MB)". Viewing BASIC Stamp Manual Parallax Click Documentation link. Click next BASIC Stamps folder. Click BASIC Stamp Manual book icon. Click View button.
Figure 1-47 shows excerpt from BASIC Stamp Manual v2.0 Contents section. shows that information DEBUG command found page
Figure 1-47 Finding DEBUG Command Table Contents
Figure 1-48 shows excerpt from page BASIC Stamp Manual v2.0. DEBUG command explained detail here along with example programs demonstrate DEBUG command used. Briefly look over BASIC Stamp Manual's explanation DEBUG command.
Page What's Microcontroller?
Count number example programs DEBUG section. many there?
Figure 1-48 Reviewing DEBUG Command BASIC Stamp Manual
Your Turn
BASIC Stamp Manual's Index look DEBUG command. Look command BASIC Stamp Manual.
ACTIVITY WHEN YOU'RE DONE
It's important disconnect power from your BASIC Stamp Board Education HomeWork Board) several reasons. First, your batteries will last longer system drawing power when you're using Second, future experiments, will build circuits Board Education's HomeWork Board's prototyping area.
Circuit prototypes should never left unattended with battery power supply connected. never know what kind accident might occur when there. Always disconnect power from your Board Education HomeWork Board, even only plan leaving alone minute two.
classroom, your instructor have extra instructions, such disconnecting serial cable, storing your Board Education HomeWork Board safe place, etc. Aside from those details, most important step that should always follow disconnecting power when you're done.
Chapter Getting Started Page
Disconnecting Power
With Board Education disconnecting power easy: using Board Education move 3-position switch position-0 pushing left shown Figure 1-49.
Sout
Reset
Figure 1-49 Turning Power
Board Education
2000-2003
www.stampsinclass.com
Board Education
remove BASIC Stamp From socket Board Education. Resist temptation store your Board Education BASIC Stamp separately. Every time BASIC Stamp removed re-inserted into socket Board Education, mistakes occur that damage Although BASIC Stamp sometimes moved from socket another during larger project, will necessary during activities this text.
Disconnecting BASIC Stamp HomeWork Board's power easy too: using BASIC Stamp HomeWork Board, disconnect battery shown Figure 1-50.
Power
Figure 1-50 Disconnecting power HomeWork Board
2002
BASIC Stamp HomeWork Board
Alkaline Battery
Powercell
Reset
Page What's Microcontroller?
Board Education also have power disconnected, either removing battery unplugging supply from jack.
Your Turn
Disconnect power your board now.
Chapter Getting Started Page
SUMMARY
This chapter guided through following: introduction some devices that contain microcontrollers introduction BASIC Stamp tour some interesting inventions that were made with BASIC Stamps Where free BASIC Stamp Editor software will just about experiments this text install BASIC Stamp Editor software introduction BASIC Stamp, Board Education, HomeWork Board your BASIC Stamp hardware test your software hardware write PBASIC program Using DEBUG commands Using control character formatter BASIC Stamp Editor's Help BASIC Stamp Manual disconnect power your Board Education HomeWork Board when you're done.
Questions
What microcontroller? BASIC Stamp microcontroller, does contain one? What clues would look figure whether appliance like clock radio cell phone contains microcontroller? What purpose serial cable? When BASIC Stamp sends character your PC/laptop, what numbers used send message through serial cable? What should between time have entered your program into BASIC Stamp Editor time program? What name window that displays messages sent from BASIC Stamp your PC/laptop? What does apostrophe beginning line PBASIC program code signify? What PBASIC commands learn this chapter?
Page What's Microcontroller?
Let's want take break from your BASIC Stamp project snack, maybe want take longer break return project couple days. What should always before take your break?
Exercises
Explain what with each PBASIC command learned this chapter. Explain what would happen took control characters DEBUG commands below write down would look Debug Terminal.
DEBUG "Hello, it's your BASIC Stamp!" DEBUG "What's 11?" DEBUG "The answer
Explain what asterisk does this command:
DEBUG
Guess what Debug Terminal would display this command:
DEBUG
There problem with these commands. When code, numbers they display stuck together that looks like large number instead small ones. Modify these commands that answers appear different lines Debug Terminal.
DEBUG DEBUG
Projects
DEBUG display solution math problem: Your Turn DEBUG Formatters section page template saving your file under name modifying filename FirstProgramCh01Project02.bs2. this line program, then
DEBUG
Next, insert formatter before each these numbers that line reads:
DEBUG
Chapter Getting Started Page
Re-run program describe what formatter does. Most microcontrollers computers adhere American Standard Code Information Interchange. You'll usually referred ASCII code. ASCII code ASCII code space character code carriage return (CR) this explain paragraph report what each these lines doing.
DEBUG DEBUG DEBUG DEBUG DEBUG "Hello!" "Hello again!" "Goodbye."
Predict what would expect removed formatter from this command. PBASIC program test your prediction.
DEBUG
Take second look Figure 1-35 page send number (representing `A') restricted zeros ones? answer that number represented using ones zeros. will learn more about binary (base-2) number system later. now, just modify program adding this code segment verify that does same thing your code segment Project
Send ASCII codes Debug terminal will display "ABCDEF". DEBUG %01000001, %01000010, %01000011 DEBUG %01000100, %01000101, %01000110
Which lines delete FirstProgramYourTurn.bs2 place command shown below line just before command program? Test your hypothesis (your prediction what will happen). Make sure save FirstProgramYourTurn.bs2 with name, like FirstProgramCh01Project05.bs2. Then make your modification, save your program.
DEBUG "What's 11?", "The answer
Further Investigation
this chapter, visited Software section either Parallax site Parallax copy BASIC Stamp Editor. Documentation
Page What's Microcontroller?
sections either Parallax site Parallax free copy this text BASIC Stamp Manual. Printed copies also purchased from Parallax. "BASIC Stamp Manual", Users Manual, Version 2.0c, Parallax Inc., 2000 learn much more about DEBUG commands looking them BASIC Stamp Manual. find them using Table Contents. BASIC Stamp Manual many more examples try, along with lessons similar those Projects section just completed.
Chapter Lights Lights Page
Chapter Lights Lights
INDICATOR LIGHTS
Indicator lights common that most people tend give them much thought. Figure shows three indicator lights laser printer. Depending which light person using printer knows running properly needs attention. Here just examples devices with indicator lights: stereos, televisions, VCRs, disk drives, printers, alarm system control panels.
Figure Indicator Lights
Turning indicator light simple matter connecting disconnecting from power source. some cases, indicator light connected directly battery power supply, like power indicator light Board Education. Other indicator lights switched microcontroller inside device. These usually status indicator lights that tell what device
MAKING LIGHT EMITTING DIODE (LED) EMIT LIGHT
Most indicator lights devices called light emitting diodes. will often light emitting diode referred books circuit diagrams letters LED. name usually pronounced three letters: "L-E-D". build circuit connect power emits light. disconnect power from circuit, stops emitting light.
Page What's Microcontroller?
circuit connected BASIC Stamp, BASIC Stamp programmed connect disconnect circuit's power. This much easier than manually changing circuit's wiring connecting disconnecting battery. BASIC Stamp also programmed following: Turn circuit different rates Turn circuit certain number times Control more than circuit Control color bi-color (two color) circuit
ACTIVITY BUILDING TESTING CIRCUIT
It's important test components individually before building them into larger system. This activity focuses building testing different circuits. first circuit that makes emit light. second circuit that makes emit light. activity that comes after this one, will build circuit into larger system connecting BASIC Stamp. will then write programs that make BASIC Stamp cause emit light, then emit light. first testing each circuit make sure works, more confident that will work when connect BASIC Stamp. Introducing Resistor resistor component that `resists' flow electricity. This flow electricity called current. Each resistor value that tells strongly resists current flow. This resistance value called ohm, sign Greek letter omega resistor will working with this activity resistor shown Figure 2-2. resistor wires (called leads pronounced "leeds"), coming each end. There ceramic case between leads, it's part that resists current flow. Most circuit diagrams that show resistors symbol left with squiggly lines tell person building circuit that must resistor. This called schematic symbol. drawing right part drawing used some beginner level Stamps Class texts help identify resistor your kit.
Chapter Lights Lights Page
Gold Silver Blank
Figure Resistor Part Drawing Schematic symbol (left) Part Drawing (right)
Yellow
Violet
Brown
Resistors like ones using this activity have colored stripes that tell what their resistance values are. There different color combination each resistance value. example, color code resistor yellow-violet-brown. There fourth stripe that indicates resistor's tolerance. Tolerance measured percent, tells part's true resistance might from labeled resistance. fourth stripe could gold (5%), silver (10%) stripe (20%). activities this book, resistor's tolerance does matter, value does. Each color that tells resistor's value corresponds digit, these colors/digits listed Table 2-1. Figure shows each color with table determine value resistor.
Table 2-1: Resistor Color Code Values Digit Color Black Brown Orange Yellow Green Blue Violet Gray White
Tolerance Code
First Digit Second Digit
Number Zeros
Figure Resistor Color Codes
Here example that shows Table Figure used figure resistor value proving that yellow-violet-brown really
Page What's Microcontroller?
First stripe yellow, which means leftmost digit Second stripe violet, which means next digit Third stripe brown. Since brown means zero right first digits. Yellow-Violet-Brown 4-7-0. Introducing diode one-way current valve, light emitting diode (LED) emits light when current passes through Unlike color codes resistor, color usually just tells what color will glow when current passes through important markings contained shape. Since one-way current valve, have make sure connect right way, won't work intended. Figure shows LED's schematic symbol part drawing. terminals. called anode, other called cathode. this activity, will have build into circuit, will have attention make sure leads connected anode cathode connected circuit properly. part drawing, anode lead labeled with plus-sign (+). schematic symbol, anode wide part triangle. part drawing, cathode lead unlabeled pin, schematic symbol, cathode line across point triangle.
Chapter Lights Lights Page
Figure Part Drawing Schematic Symbol Part Drawing (above) schematic symbol (below).
When start building your circuit, make sure check against schematic symbol part drawing. part drawing, note that LED's leads different lengths. longer lead connected LED's anode, shorter lead connected cathode. Also, look closely LED's plastic case, it's mostly round, there small flat spot right near shorter lead that that tells it's cathode. This really comes handy leads have been clipped same length.
Test Circuit Parts
Green Resistor
(yellow-violet-brown)
Identifying parts: addition part drawings Figure Figure 2-4, photo last page book help identify parts needed this other activities. more information parts this photo, Appendix Equipment Parts Lists.
Building Test Circuit
will build circuit plugging resistor leads into small holes called sockets prototyping area shown Figure 2-5. This prototyping area black sockets along along left. black sockets along have labels above them: Vdd, Vin, Vss. These called power terminals, they will used supply your circuits with electricity. black sockets left have labels like through P15. These sockets that connect your circuit
LED's part drawings later pictures will have next anode leg.
Page What's Microcontroller?
BASIC Stamp's input/output pins. white board with lots holes called solderless breadboard. will this breadboard connect components each other build circuits.
Figure Prototyping Area Power terminals (black sockets along top), access (black sockets along side), solderless breadboard (white sockets)
Input/output pins usually called pins, after connecting your circuit more these pins, program your BASIC Stamp monitor circuit (input) send signals circuit (output). will this activity that follows this one.
Figure shows couple circuits built prototyping area. breadboard separated into rows five sockets. Each five sockets used connect five leads, wires, each other. Examples part leads wires that connected each other circled. Although circled, probably tell that resistor's leads connected another connected P15. LED's leads connected Vss, wire connected circuits also connected Vss.
Chapter Lights Lights Page
Figure Example Circuit Prototyping Area. BUILD THIS CIRCUIT. Rows sockets breadboard used connect leads more parts circled. Leads certain parts also connected P15, Vss.
ready build circuit shown Figure (below) plugging resistor leads into sockets prototyping area. Follow these steps: Disconnect power from your Board Education HomeWork Board. Figure decide which lead connected LED's cathode. Look shorter lead flat spot plastic part LED. Plug LED's cathode into black sockets labeled prototyping area. Plug LED's anode (the other, longer lead) into socket shown breadboard portion prototyping area. Plug resistor's leads into same breadboard LED's anode. This will connect those leads together. Plug resistor's other lead into sockets labeled Vdd.
Direction does matter LED, resistor. plug backward, will emit light when connect power. resistor just resists flow current. There backwards forwards resistor.
Reconnect power your Board Education HomeWork Board. Check make sure your green emitting light. should glow green.
Page What's Microcontroller?
Figure Circuit Wiring Diagram
your green does emit light when connect power board: Some LEDs brightest when viewed from above. looking straight down onto dome part LED's plastic case from above. room bright, turning some lights, your hands cast shadow LED. still green glow, these steps: Double check make sure your cathode anode connected properly. not, simply remove LED, give half-turn, plug back will hurt plug backwards, just doesn't emit light. When have plugged right direction, should emit light. Double check make sure built your circuit exactly shown Figure 2-7. using What's Microcontroller that somebody used before you, damaged, different one. class, check with your instructor.
Chapter Lights Lights Page
Still stuck? don't have instructor friend help, always check with Stamps Class discussion group. first pages this book Internet Access information where find Stamps Class discussion group. group unable help solve problem, contact Parallax Technical Support department following Support link www.parallax.com.
Test Circuit Works terminals supply electrical pressure same that battery would. sockets like battery's positive terminal, sockets like battery's negative terminal. Figure shows applying electrical pressure circuit using battery causes electrons flow through This flow electrons called electric current, often just current. Electric current limited resistor. This current what causes diode emit light.
Figure Circuit Electron Flow minus signs with circles around them used show electrons flowing from battery's negative terminal positive terminal.
Chemical reactions inside battery supply circuit with current. battery's negative terminal contains compound that molecules with extra electrons (shown Figure minus-signs). battery's positive terminal chemical compound with molecules that missing electrons (shown plus-signs). When electron leaves molecule negative terminal travels through wire, called free electron (also shown minus-signs). molecule that lost that extra electron longer extra negative charge; called neutral (shown When electron gets positive terminal, joins molecule that missing electron, that molecule neutral too.
Figure shows flow electricity through circuit described using schematic notation. electric pressure across circuit called voltage. signs used show voltage applied circuit. arrow shows current
Page What's Microcontroller?
flowing through circuit. This arrow almost always shown pointing opposite direction actual flow electrons. Benjamin Franklin credited with having been aware electrons when decided represent current flow charge passing from positive negative terminal circuit. time physicists discovered true nature electric current, convention already well established.
Voltage
Resistance Current
Figure LED-On Circuit Schematic Showing Conventional Voltage Current Flow signs show voltage applied circuit, arrow shows current flow through circuit.
Voltage
schematic drawing (like Figure 2-9) picture that explains more circuits connected. Schematics used students, electronics hobbyists, electricians, engineers, just about everybody else works with circuits. Appendix More About Electricity: This appendix contains some glossary terms activity more familiar with measurements voltage, current resistance.
Your Turn Modifying Test Circuit
next activity, will program BASIC Stamp turn then off, then again. BASIC Stamp will this switching circuit between different connections, Vss. just finished working with circuit where resistor connected Vdd, emits light. Make changes shown Figure 2-10 verify that will turn (not emit light) when resistor's lead disconnected from connected Vss. Disconnect power from your Board Education HomeWork Board. Unplug resistor lead that's plugged into socket, plug into socket labeled shown Figure 2-10. Reconnect power your Board Education HomeWork Board. Check make sure your green emitting light. should glow green.
Chapter Lights Lights Page
Figure 2-10 Circuit Schematic (left) wiring diagram (right).
ACTIVITY ON/OFF CONTROL WITH BASIC STAMP
Activity different circuits were built tested. circuit made emit light while other not. Figure 2-11 shows BASIC Stamp same thing connect circuit pins. this activity, will connect circuit BASIC Stamp program turn off. will also experiment with programs that make BASIC Stamp this different speeds.
Figure 2-11 BASIC Stamp Switching BASIC Stamp programmed internally connect circuit's input Vss.
SOUT
(+5V)
SOUT
(+5V)
BS2-IC
BS2-IC
There differences between changing connection manually having BASIC Stamp First, BASIC Stamp doesn't have power when
Page What's Microcontroller?
changes circuit's supply from Vss. Second, while human make that change several times minute, BASIC Stamp thousands times second!
Test Circuit Parts
Same Activity
Connecting Circuit BASIC Stamp
circuit shown Figure 2-12 wired almost same circuit previous exercise. difference that resistor's lead that manually switched between plugged into BASIC Stamp pin. Disconnect power from your Board Education HomeWork Board. Modify circuit were working with Activity that matches Figure 2-12.
Figure 2-12 BASIC Stamp Controlled Circuit circuit's input connected BASIC Stamp instead Vss.
Resistors essential. Always remember resistor. Without much current will flow through circuit, could damage number parts your circuit, BASIC Stamp, Board Education HomeWork Board.
Chapter Lights Lights Page
Turning On/Off with Program
example program makes blink time second. introduces several programming techniques once. After running will experiment with different parts program better understand works.
Example Program: LedOnOff.bs2
Enter LedOnOff.bs2 code into BASIC Stamp Editor. Reconnect power your Board Education HomeWork Board. program. Verify that flashes once second. Disconnect power when done with program.
What's Microcontroller LedOnOff.bs2 Turn off. Repeat time second indefinitely. {$STAMP BS2} {$PBASIC 2.5} HIGH PAUSE PAUSE LOOP
LedOnOff.bs2 Works command HIGH causes BASIC Stamp internally connect Vdd. This turns command PAUSE causes BASIC Stamp nothing second while stays number tells PAUSE command wait 500/1000 second. number that follows PAUSE called argument. look PAUSE BASIC Stamp Manual, will discover that calls this number Duration argument. name duration chosen this argument show that PAUSE command pauses certain `duration' time, milliseconds.
Page What's Microcontroller?
What's Millisecond? millisecond 1/1000 second. abbreviated takes 1000 equal second.
command causes BASIC Stamp internally connect Vss. This turns off. Since followed another PAUSE 500, stays half second. reason code repeats itself over over again because nested between PBASIC keywords LOOP. Figure 2-13 shows DO.LOOP works. placing code segment that turns with pauses between LOOP, tells BASIC Stamp execute those four commands over over again. result that flashes off, over over again. will keep flashing until disconnect power, press hold reset button, until battery runs out.
HIGH PAUSE PAUSE LOOP
Figure 2-13 DO.LOOP code between keywords LOOP executed over over again.
Your Turn Timing Repetitions
changing PAUSE command's Duration argument change amount time stays off. example, changing both Duration arguments 250, will cause flash twice second. DO.LOOP your program will look like this:
HIGH PAUSE PAUSE LOOP
Chapter Lights Lights Page
Modify PAUSE command's Duration arguments that they 250, rerun program. want make blink once every three seconds, with time twice long high time, program PAUSE command after HIGH command that takes second using PAUSE 1000. PAUSE command after command will have PAUSE 2000.
HIGH PAUSE 1000 PAUSE 2000 LOOP
Modify re-run program using code snippet above. experiment short make pauses still that flashing. When flashing very fast, looks like it's just it's called persistence vision. Here test what your persistence vision threshold modifying both your PAUSE command's Duration arguments that they 100. Re-run your program check flicker. Reduce both Duration arguments again. Keep reducing Duration arguments until appears time with flicker. will dimmer than normal, should appear flicker. last thing create one-shot flasher. When program runs, flashes only once. This look functionality DO.LOOP. temporarily remove DO.LOOP from program placing apostrophe left both LOOP keywords shown below.
HIGH PAUSE 1000
Page What's Microcontroller?
PAUSE 2000 LOOP
Modify re-run program using code snippet above. Explain what happened, only flash once?
Commenting line code: Placing apostrophe left command changes into comment. This useful tool because don't actually have delete command what happens remove from program. much easier remove apostrophe than delete re-type commands.
ACTIVITY COUNTING REPEATING
previous activity, circuit either flashed time, flashed once then stopped. What only want flash times? Computers (including BASIC Stamp) great keeping running totals many times something happens. Computers also programmed make decisions based variety conditions. this activity, will program BASIC Stamp stop flashing after repetitions.
Counting Parts
Same previous activity
Test Circuit
example circuit shown Figure 2-12 page
Many Times?
There many ways make blink times. simplest FOR.NEXT loop. FOR.NEXT loop similar DO.LOOP. Although either loop used repeat commands fixed number times, FOR.NEXT easier use. FOR.NEXT loop depends variable track many times blinked off. variable word your choosing that used store value. next example program uses word counter `count' many times been turned off.
Chapter Lights Lights Page
Picking words variable names several rules: name cannot word that already used PBASIC. These words called reserved words, some examples that should already familiar with are: DEBUG, PAUSE, HIGH, LOW, LOOP. name cannot contain space. Even though name contain letters, numbers, underscores, must begin with character. name must less than characters long.
Example Program: LedOnOffTenTimes.bs2
program LedOnOffTenTimes.bs2 demonstrates FOR.NEXT loop blink times. Your test circuit from Activity should built rebuilt) ready use. Enter LedOnOffTenTimes.bs2 code into BASIC Stamp Editor. Connect power your Board Education HomeWork Board. program. Verify that flashes times. program second time, verify that value counter shown Debug Terminal accurately tracks many times blinked. Hint: instead clicking second time, press release reset button your Board Education HomeWork Board.
What's Microcontroller LedOnOffTenTimes.bs2 Turn off. Repeat times. {$STAMP BS2} {$PBASIC 2.5} counter Byte counter DEBUG counter HIGH PAUSE PAUSE NEXT
Page What's Microcontroller?
DEBUG "All done!"
LedOnOffTenTimes.bs2 Works This PBASIC statement
counter Byte
tells BASIC Stamp Editor that your program will word counter variable that store byte's worth information.
What's Byte? byte enough memory store number between 255. BASIC Stamp four different types variables, each store different range numbers: Table 2-2: Variable Types Values They Store Variable type Byte Word Range Values 65535
question mark formatter before variable DEBUG command tells Debug Terminal display name variable value. This command
DEBUG counter
displays both name value counter variable Debug Terminal. FOR.NEXT loop commands inside shown below. statement counter tells BASIC Stamp that will have counter variable then keep executing commands until gets NEXT statement. When BASIC Stamp gets NEXT statement, jumps back statement. statement adds value counter. Then, checks counter greater than yet. not, repeats process. When value counter finally reaches eleven, program skips commands between NEXT statements moves command that comes after NEXT statement.
Chapter Lights Lights Page
counter DEBUG counter, HIGH PAUSE PAUSE NEXT
command that comes after NEXT statement
DEBUG "All done!"
This command included just show what program does after times through FOR.NEXT loop. moves command that comes after NEXT statement.
Your Turn Other Ways Count
Replace statement
counter
with statement
counter
LedOnOffTenTimes.bs2 re-run program. What program differently, this expected? second modification statement. This time, change
counter STEP
many times flash? What values displayed Debug Terminal?
Page What's Microcontroller?
ACTIVITY BUILDING TESTING SECOND CIRCUIT
Indicator LEDs used tell machine's user many things. Many devices need two, three, more LEDs tell user machine ready not, there malfunction, it's done with task, this activity, will repeat circuit test Activity second circuit. Then will adjust example program from Activity make sure circuit properly connected BASIC Stamp. After that, will modify example program from Activity make LEDs operate tandem.
Extra Parts
addition parts used Activities will need these parts: yellow Resistor (yellow-violet-brown)
Building Testing Second Circuit
Activity manually tested first circuit make sure worked before connecting BASIC Stamp. Before connecting second circuit BASIC Stamp, it's important test too. Disconnect power from your Board Education HomeWork Board. Construct second circuit shown Figure 2-14. Reconnect power your Board Education HomeWork Board. circuit just added turn yes, then continue. Activity some trouble-shooting suggestions that repeat this circuit.
Chapter Lights Lights Page
Figure 2-14 Manual Test Circuit Second
Disconnect power your Board Education HomeWork Board. Modify second circuit just tested connecting circuit's resistor lead (input) shown Figure 2-15.
Figure 2-15 Connecting Second BASIC Stamp Schematic (left) wiring diagram (right).
Page What's Microcontroller?
Using Program Test Second Circuit
Activity used example program HIGH commands control circuit connected P14. These commands will have modified control circuit connected P15. Instead using HIGH will HIGH
Example Program: TestSecondLed.bs2
Enter TestSecondLed.bs2 into BASIC Stamp Editor. Connect power your Board Education HomeWork Board. TestSecondLED.bs2. Make sure circuit connected flashing. connected flashes, move next example (Controlling Both LEDs). circuit connected flashing, check your circuit wiring errors your program typing errors again.
What's Microcontroller TestSecondLed.bs2 Turn connected off. Repeat time second indefinitely. {$STAMP BS2} {$PBASIC 2.5} HIGH PAUSE PAUSE LOOP
Controlling Both LEDs
Yes, flash both LEDs once. this HIGH commands before first PAUSE command. HIGH command sets high, next HIGH command sets high. will also need commands turn both LEDs off. It's true that both LEDs will turn exactly same time because turned after other. However, there more than millisecond's difference between changes, human will detect
Chapter Lights Lights Page
Example Program: FlashBothLeds.bs2
Enter FlashBothLeds.bs2 code into BASIC Stamp Editor. program. Verify that both LEDs appear flash same time.
What's Microcontroller FlashBothLeds.bs2 Turn LEDs connected off. {$STAMP BS2} {$PBASIC 2.5} HIGH HIGH PAUSE PAUSE LOOP
Your Turn Alternate LEDs
cause LEDs alternate swapping HIGH commands that control pins. This means that while other will off. Modify FlashBothLeds.bs2 that commands between LOOP keywords look like this:
HIGH PAUSE HIGH PAUSE
modified version FlashBothLeds.bs2 verify that LEDs flash alternately off.
Page What's Microcontroller?
ACTIVITY USING CURRENT DIRECTION CONTROL BI-COLOR
device shown Figure 2-16 security monitor electronic keys. When electronic with right code used, changes color, door opens. This kind called bi-color LED. This activity answers questions: does change color? with BASIC Stamp?
Figure 2-16 Bi-color Security Device When door locked, this bi-color glows red. When door unlocked electronic with right code, turns green.
Introducing Bi-Color bi-color LED's schematic symbol part drawing shown Figure 2-17.
LEDGreen bicolor
Figure 2-17 Bi-color
Schematic symbol (left) part drawing (right).
Chapter Lights Lights Page
bi-color really just LEDs package. Figure 2-18 shows apply voltage direction will glow red. disconnecting plugging back reversed, will then glow green. with other LEDs, connect both terminals circuit Vss, will emit light.
Figure 2-18 Bi-color Applied Voltage
LEDRed
LED1 Green
(left), green (center) light (right)
Bi-Color Circuit Parts
bi-color Resistor (yellow-violet-brown) Jumper wire
Building Testing Bi-Color Circuit
Figure 2-19 shows manual test bi-color LED. Disconnect power from your Board Education HomeWork Board. Build circuit shown left side Figure 2-19. Reconnect power verify that bi-color emitting light. Disconnect power again. Modify your circuit that matches right side Figure 2-19. Reconnect power. Verify that bi-color emitting green light. Disconnect power.
Page What's Microcontroller?
Figure 2-19 Manual bicolor Test Bi-color (left) green (right).
Controlling bi-color with BASIC Stamp requires pins. After have manually verified that bi-color works using manual test, connect circuit BASIC Stamp shown Figure 2-20. Connect bi-color circuit BASIC Stamp shown Figure 2-20.
Figure 2-20 Bi-color Connected BASIC Stamp
Chapter Lights Lights Page
BASIC Stamp Bi-Color Control
Figure 2-21 shows control current flow bicolor circuit. upper schematic shows current flows through when Vss. This because will current flow through when electrical pressure applied shown, green acts like closed valve does current through bi-color glows red. lower schematic shows what happens when Vdd. electrical pressure reversed. shuts does allow current through. Meanwhile, green turns current passes through circuit opposite direction.
HIGH Current
Figure 2-21 Manual bi-color Test Current through (above) Green (below).
Current
HIGH
Figure 2-21 also shows programming BASIC Stamp make bi-color glow different colors. upper schematic shows make bi-color using HIGH lower schematic shows make bicolor glow green using HIGH turn off, send signals both using other words, both pins.
Page What's Microcontroller?
bi-color will also turn send high signals both P15. Why? Because electrical pressure same regardless whether both pins high low.
Example Program: TestBiColorLED.bs2 Reconnect power. Enter TestBiColorLed.bs2 code into BASIC Stamp Editor. program. Verify that cycles through red, green, states.
What's Microcontroller TestBiColorLed.bs2 Turn bi-color red, then green, then loop. {$STAMP BS2} {$PBASIC 2.5} HIGH PAUSE HIGH PAUSE PAUSE LOOP
Green
Your Turn Lights Display Activity variable named counter used control many times blinked. What happens value counter control PAUSE command's Duration argument? Save TestBiColorLed.bs2 under name, such TestBiColorLedYourTurn.bs2. counter variable declaration before statement:
counter BYTE
Chapter Lights Lights Page
Nest FOR.NEXT loop below within DO.LOOP.
counter HIGH PAUSE counter HIGH PAUSE counter NEXT
When done, your code should look like this:
counter BYTE counter HIGH PAUSE counter HIGH PAUSE counter NEXT LOOP
beginning each pass through FOR.NEXT loop, PAUSE value (Duration argument) only millisecond. Each time through FOR.NEXT loop, pause gets longer millisecond time until gets milliseconds. DO.LOOP causes FOR.NEXT loop execute over over again. modified program observe effect.
Page What's Microcontroller?
SUMMARY
BASIC Stamp programmed switch circuit with light emitting diode (LED) indicator light off. indicators useful variety places including many computer monitors, disk drives, other devices. introduced along with technique identify anode cathode terminals. circuit must have resistor limit current passing through Resistors were introduced along with more common coding schemes figure resistor's value. BASIC Stamp switches circuit internally connecting either Vss. HIGH command used make BASIC Stamp internally connect pins Vdd, command used internally connect Vss. PAUSE command used cause BASIC Stamp execute commands amount time. This used make LEDs stay and/or certain amounts time. This amount time determined number used PAUSE command's Duration argument. DO.LOOP used create infinite loop. commands between LOOP keywords will execute over over again. Even though this called infinite loop, program still re-started disconnecting reconnecting power pressing releasing reset button. program also downloaded BASIC Stamp, this will erase program with infinite loop. Current direction voltage polarity were introduced using bi-color LED. voltage applied across circuit, current will pass through direction, glows particular color. voltage polarity reversed, current travels through circuit opposite direction glows different color.
Questions
What name this Greek letter: What measurement does refer
tell anode from cathode LED?
Chapter Lights Lights Page
Which resistor would allow more current through circuit, 1000 resistor?
resistor
What stripes would look resistor were looking value 2000 resistor color code brown-black-green, what measurement connect wires using breadboard? breadboard connect four wires together? What component limits current? When current flowing through circuit, electrons flowing Vss? What always have before modifying circuit that built breadboard? long does PAUSE last? long would PAUSE 10000 last? would cause BASIC Stamp nothing entire minute? place three commands between DO.LOOP loop, many times will these commands executed? What command control number times group commands executed? What different types variables? byte hold value 500? What smallest variable count
Page What's Microcontroller?
What does question-mark DEBUG command? What will command HIGH command reasonable? yes, why? what's wrong with bi-color circuit connected what commands need turn What commands would make switch color? What commands would turn off?
Exercises
Draw schematic circuit like worked with Activity connect circuit instead P14. Explain would modify LedOnOff.bs2 Page that will make your circuit Exercise flash four times second. Explain modify LedOnOffTenTimes.bs2 that makes circuit flash 5000 times before stops. Hint: will need modify just lines code.
Projects
Make 10-second countdown using yellow bi-color LED. Make bi-color start seconds. After seconds, change bi-color green. When bi-color changes green, flash yellow once every second seconds. When yellow done flashing, bi-color should switch back stay that way. Create your graph using four individual LEDs.
1000 resistors this project. color code 1000 resistor brown-black-red. make graph with more than LEDs using 1000 resistors. want make graph with more than LEDs, 2000 resistors. color code 2000 resistors black red.
Chapter Lights Lights Page
Write program that starts with LEDs off, then LEDs start light time with second delay between each LED. LEDs should light either from left right bottom depending have wired. Save program under different name make LEDs graph light 20-times fast. Make automatic streetlight timer. Assume that drivers from both north south lights made green, yellow, circuits P13, P14, P15. Make another bank LEDs connected that control east-west traffic. Write program that gives north-south traffic seconds, then second yellow, followed second red. When north-south traffic red, east-west traffic should green seconds yellow seconds, then seconds. Keep mind that this real traffic controller, would responsible traffic problems both lights stay length time. both green lights same time, could cause accident!
Further Investigation
resources listed here available free download from Parallax site also included Parallax "BASIC Stamp Manual", Users Manual, Version 2.0c, Parallax Inc., 2000 BASIC Stamp Manual more examples information that further explains following commands: HIGH, LOW, PAUSE, DEBUG formatter, FOR.NEXT. "Basic Analog Digital", Student Guide, Version 2.0, Parallax Inc., 2003 Basic Analog Digital uses LEDs describe counting binary, describes analog conditions, introduces ways adjust LED's brightness.
Page What's Microcontroller?
"BASIC Stamp Editor Help File", PBASIC Version Parallax Inc., 2003 PBASIC Help File information DO.LOOP, which PBASIC included BASIC Stamp Manual. find this information clicking book icon your BASIC Stamp Editor task bar, then selecting PBASIC Reference from menu left sidebar window. This will open PBASIC Command Reference alphabetical listing main window. Detailed information found clicking each command.
Chapter Digital Input Pushbuttons Page
Chapter Digital Input Pushbuttons
FOUND CALCULATORS, HAND HELD GAMES, APPLIANCES
many devices with pushbuttons daily basis? Here examples that might appear your list: computer, mouse, calculator, microwave oven, handheld remote, handheld games, VCR. each device, there microcontroller scanning pushbuttons waiting circuit change. When circuit changes, microcontroller detects change takes action. this chapter, will have experience with designing pushbutton circuits programming BASIC Stamp monitor them take action when changes occur.
RECEIVING SENDING HIGH SIGNALS
Chapter programmed BASIC Stamp send high signals, used circuits display these signals. Sending high signals means used BASIC Stamp output. this chapter, will BASIC Stamp input. input, listens high/low signals instead sending them. will send these signals BASIC Stamp using pushbutton circuit, will program BASIC Stamp recognize whether pushbutton pressed pressed.
Other terms that mean send, high/low, receive: Sending high/low signals described different ways. sending referred transmitting, controlling, switching. Instead high/low, might referred binary, TTL, CMOS, Boolean signals. Another term receiving sensing.
ACTIVITY TESTING PUSHBUTTON WITH CIRCUIT
pushbutton send high signal BASIC Stamp, also control with pushbutton? answer yes, will test pushbutton this activity. Introducing Pushbutton Figure shows schematic symbol part drawing normally open pushbutton. pushbutton's pins connected each terminal. This means that connecting wire part lead pushbutton same connecting same rule applies with pins reason pushbutton doesn't just
Page What's Microcontroller?
have pins because needs stability. pushbutton only pins, those pins would eventually bend break from pressure that pushbutton receives when people press
Figure Normally Open Pushbutton Schematic symbol (left) part drawing (right)
left side Figure shows normally open pushbutton looks when it's pressed. When button pressed, there between terminals. This makes that terminal conduct current terminal. This called open circuit. name "normally open" means that pushbutton's normal state (not pressed) forms open circuit. When button pressed, between terminals bridged conductive metal. This called closed, current flow through pushbutton.
Figure Normally Open Pushbutton pressed (left) pressed (right)
Test Parts Pushbutton
pick color Resistor (yellow-violet-brown) Pushbutton normally open Jumper wire
Building Pushbutton Test Circuit
Figure shows circuit build manually test pushbutton.
Chapter Digital Input Pushbuttons Page
Always disconnect power from your Board Education BASIC Stamp HomeWork Board before making changes your test circuit. From here onward, instructions will longer "Disconnect power." between each circuit modification. remember this. Always reconnect power your Board Education BASIC Stamp HomeWork Board before downloading program BASIC Stamp.
Build circuit shown Figure 3-3.
Figure Pushbutton Test Circuit
Testing Pushbutton
When pushbutton pressed, will off. wiring correct, when pushbutton pressed, should (emitting light).
Warning signs: Board Education flickers, goes dim, goes completely when plug power supply back means have short circuit. this happens you, disconnect power immediately find correct mistake your circuit. Power HomeWork Board different. glows only while program running. program ends (using command), Power will also turn off.
Verify that your test circuit off.
Page What's Microcontroller?
Press hold pushbutton, verify that emits light while holding pushbutton down.
Pushbutton Circuit Works
left side Figure shows what happens when pushbutton pressed. circuit connected Vdd. open circuit that cannot conduct current. pressing pushbutton, close connection between terminals with conductive metal making pathway electrons flow through circuit.
Current
Current
Figure Pushbutton Pressed, Pressed Pushbutton circuit open (left) closed (right)
Your Turn Short-Circuit Figure shows different circuit that will cause behave differently. When button pressed, stays When button pressed, turns off. reason turns when pushbutton pressed because current always follows path least resistance. When pushbutton pressed, terminals 2,3, have almost resistance between them, current passes through pushbutton (short circuit) instead LED. Build circuit shown Figure 3-5. Repeat tests performed first pushbutton circuit built with this circuit.
Chapter Digital Input Pushbuttons Page
Figure that Gets Shorted Pushbutton
really that with LED? until now, LED's cathode always been connected Vss. Now, different place circuit, with anode connected Vdd. People often this breaks circuit rules, answer electrical pressure supplied volts. diode will always volts, resistor will always volts, regardless their order.
ACTIVITY READING PUSHBUTTON WITH BASIC STAMP
this activity, will connect pushbutton circuit BASIC Stamp display whether pushbutton pressed. will this writing PBASIC program that checks state pushbutton displays Debug Terminal.
Parts Pushbutton Circuit
Pushbutton normally open Resistor (red-red-brown) Resistor (brown-black-orange) Jumper wires
Building Pushbutton Circuit BASIC Stamp
Figure shows pushbutton circuit that connected BASIC Stamp Build circuit shown Figure 3-6.
Page What's Microcontroller?
Figure Pushbutton Circuit Connected wiring diagram, resistor left side connecting pushbutton while resistor right, connecting pushbutton circuit Vss.
Figure shows what BASIC Stamp sees when button pressed, when it's pressed. When pushbutton pressed, BASIC Stamp senses that connected Inside BASIC Stamp, this causes place number part memory that stores information about pins. When pushbutton pressed, BASIC Stamp cannot sense Vdd, sense through resistors. This causes store number that same memory location that stored when pushbutton pressed.
Chapter Digital Input Pushbuttons Page
SOUT
(+5V)
BS2-IC
Figure BASIC Stamp Reading Pushbutton When pushbutton pressed, BASIC Stamp reads (above). When pushbutton pressed, BASIC Stamp reads (below).
SOUT
(+5V)
BS2-IC
Binary Circuits: base-2 number system uses only digits make numbers, these binary values transmitted from device another. BASIC Stamp interprets binary-1 binary-0. Likewise, when BASIC Stamp sets using HIGH, sends binary-1. When sets using LOW, sends binary-0. This very common communicating binary numbers used many computer chips other devices.
Programming BASIC Stamp Monitor Pushbutton
BASIC Stamp stores zero senses memory location called IN3. Here example program that shows this works:
Example Program: ReadPushbuttonState.bs2
This program makes BASIC Stamp check pushbutton every second send value Debug Terminal. Figure shows Debug Terminal while program running. When pushbutton pressed, Debug Terminal displays
Page What's Microcontroller?
number when pushbutton pressed, Debug Terminal displays number
Figure Debug Terminal Displaying Pushbutton States Debug Terminal displays when pushbutton pressed when pressed.
Enter ReadPushbuttonState.bs2 program into BASIC Stamp Editor. program. Verify that Debug Terminal displays value when pushbutton pressed. Verify that Debug Terminal displays value when pushbutton pressed held.
What's Microcontroller ReadPushbuttonState.bs2 Check send pushbutton state Debug Terminal every second. {$STAMP BS2} {$PBASIC 2.5} DEBUG PAUSE LOOP
ReadPushbuttonState.bs2 Works
DO.LOOP program repeats every second because command PAUSE 250. Each time through DO.LOOP, command DEBUG sends value Debug Terminal. value state that senses instant DEBUG command executed.
Chapter Digital Input Pushbuttons Page
Your Turn Pushbutton with Pull-up Resistor
circuit just finished working with resistor connected Vss. This resistor called pull-down resistor because pulls voltage down volts) when button pressed. Figure shows pushbutton circuit that uses pull-up resistor. This resistor pulls voltage volts) when button pressed. rules reversed. When button pressed, stores number when button pressed, stores number
resistor used pushbutton example circuits protect BASIC Stamp pin. Although it's good practice prototyping, most products, this resistor replaced with wire (since wires cost less than resistors).
Modify your circuit shown Figure 3-9. Re-run ReadPushbuttonState.bs2. Using Debug Terminal, verify that when button pressed when button pressed.
Figure Modified Pushbutton Circuit
Active-low Active-high: This pushbutton Figure called active-low because sends BASIC Stamp signal (Vss) when button active (pressed). pushbutton circuit Figure main activity active-high because sends high signal (Vdd) when button active (pressed).
Page What's Microcontroller?
ACTIVITY PUSHBUTTON CONTROL CIRCUIT
Figure 3-10 shows zoomed view pushbutton used adjust settings computer monitor. This just many devices that have pushbutton that press adjust device show device's status.
Figure 3-10 Button Computer Monitor
BASIC Stamp programmed make decisions based what senses. example, programmed decide flash on/off times second when button pressed.
Pushbutton Circuit Parts
Pushbutton normally open Resistor (brown-black-orange) color Resistor (red-red-brown) Resistor (yellow-violet-brown) Jumper wires
Building Pushbutton Circuits
Figure 3-11 shows pushbutton circuit used activity just finished along with circuit used Chapter Activity
Chapter Digital Input Pushbuttons Page
Build circuit shown Figure 3-11.
Figure 3-11 Pushbutton Circuit
Programming Pushbutton Control
BASIC Stamp programmed make decisions using IF.THEN.ELSE statement. example program about will flash when pushbutton pressed using IF.THEN.ELSE statement. Each time through DO.LOOP, IF.THEN.ELSE statement checks state pushbutton decides whether flash LED.
Example Program: PushbuttonControlledLed.bs2
Enter PushbuttonControlledLed.bs2 into BASIC Stamp Editor Verify that flashes while pushbutton pressed held down. Verify that does flash when pushbutton pressed down.
What's Microcontroller PushbuttonControlledLed.bs2 Check pushbutton state times second blink when pressed. {$STAMP BS2} {$PBASIC 2.5}
Page What's Microcontroller?
DEBUG (IN3 THEN HIGH PAUSE PAUSE ELSE PAUSE ENDIF LOOP
PushbuttonControlledLed.bs2 Works
This program modified version ReadPushbuttonState.bs2 from previous activity. DO.LOOP DEBUG commands same. PAUSE replaced with IF.THEN.ELSE statement. When condition after true (IN3 commands that come after THEN statement executed. They will executed until ELSE statement reached, which point program skips ENDIF moves When condition after true (IN3 commands after ELSE statement executed until ENDIF reached. make detailed list what program should either help plan program describe what does. This kind list called pseudo code, example below uses pseudo code describe PushbuttonControlledLed.bs2 works. commands between here Loop statement over over again Display value Debug Terminal value Then Turn Wait 1/20 second Turn Wait 1/20 second Else, value nothing, wait same amount time would have taken briefly flash (1/10 second). Loop
Chapter Digital Input Pushbuttons Page
Your Turn Faster/Slower
Save example program under different name. Modify program that flashes twice fast when press hold pushbutton. Modify program that flashes half fast when press hold pushbutton.
ACTIVITY PUSHBUTTONS CONTROLLING CIRCUITS
Let's second pushbutton into project works. make things little more interesting, let's also second circuit second pushbutton control
Pushbutton Circuit Parts
Pushbuttons normally open Resistors (brown-black-orange) Resistors (yellow-violet-brown) Resistors (red-red-brown) LEDs color
Adding Pushbutton Circuit
Figure 3-12 shows second pushbutton circuit added circuit tested previous activity. Build circuit shown Figure 3-12. need help building circuit shown schematic, wiring diagram Figure 3-13 guide. Modify ReadPushbuttonState.bs2 that reads instead IN3, test your second pushbutton circuit.
Page What's Microcontroller?
Figure 3-12 Schematic: Pushbuttons LEDs
Connecting wires with dots: There three places where wires intersect Figure 3-12, only dots. Wires only connect there intersection. wire that connects pushbutton resistor does connect pushbutton circuit because there dot.
Chapter Digital Input Pushbuttons Page
Figure 3-13 Wiring Diagram: Pushbuttons LEDs
Programming Pushbutton Control
previous activity, experimented with making decisions using IF.THEN.ELSE statement. There also such thing IF.ELSEIF.ELSE statement. works great deciding which flash off. next example program shows works.
Example Program: PushbuttonControlOfTwoLeds.bs2
Enter PushbuttonControlOfTwoLeds.bs2 into BASIC Stamp Editor Verify that circuit connected flashes while pushbutton circuit connected held down. Also check make sure circuit connected flashes while pushbutton circuit connected held down
What's Microcontroller PushbuttonControlOfTwoLeds.bs2 Blink pushbutton pressed, blink pushbutton pressed. {$STAMP BS2} {$PBASIC 2.5}
Page What's Microcontroller?
DEBUG HOME DEBUG DEBUG (IN3 THEN HIGH PAUSE ELSEIF (IN4 THEN HIGH PAUSE ELSE PAUSE ENDIF PAUSE LOOP
PushbuttonControlOfTwoLeds.bs2 Works
display scrolled down Debug Terminal they previous example, would difficult read. this always send cursor top-left position Debug Terminal using HOME formatter:
DEBUG HOME
sending cursor home position each time through DO.LOOP, commands:
DEBUG DEBUG
display values same part Debug Terminal each time. keyword begins loop this program:
These commands statement same ones example program from previous activity:
(IN3 THEN HIGH
Chapter Digital Input Pushbuttons Page
PAUSE
This where ELSEIF keyword helps. want turn connected instead connected P14.
ELSEIF (IN4 THEN HIGH PAUSE
neither statement true, still want pause without changing state circuits.
ELSE PAUSE
When you're finished with decisions, don't forget ENDIF.
ENDIF
It's time turn LEDs pause again. could decide which turned turn back off. PBASIC commands execute pretty quickly, just turn them both forget about more decision making?
PAUSE
LOOP statement sends program back statement, process checking pushbuttons changing states LEDs starts over again.
LOOP
Your Turn What about Pressing Both Pushbuttons?
example program flaw. pressing both pushbuttons once, you'll flaw. would expect both LEDs flash off, they don't because only code block IF.ELSEIF.ELSE statement gets executed before skips ENDIF. Here this problem: Save PushbuttonControlOfTwoLeds.bs2 under name. Replace this statement code block:
(IN3 THEN
Page What's Microcontroller?
HIGH PAUSE
with this IF.ELSEIF statement:
(IN3 (IN4 THEN HIGH HIGH PAUSE ELSEIF (IN3 THEN HIGH PAUSE
code block group commands. statement above code block with three commands (HIGH, HIGH, PAUSE). ELSEIF statement code block with commands (HIGH, PAUSE).
your modified program handles both pushbutton circuits would expect.
keyword used IF.THEN statement check more than condition true. conditions with have true statement true. keyword also used check least conditions true.
also modify program that that's flashing stays different amounts time. example, reduce Duration PAUSE both pushbuttons increase PAUSE 100, increase PAUSE 200. Modify PAUSE commands ELSEIF statements discussed. modified program. Observe difference behavior each light.
ACTIVITY REACTION TIMER TEST
embedded systems engineer video game company. marketing department recommends that circuit test player's reaction time added
Chapter Digital Input Pushbuttons Page
next hand held game controller. Your next task develop proof concept reaction timer test. solution will build test this activity example solve this problem, it's definitely only solution. Before continuing, take moment think about would design this reaction timer.
Reaction Timer Game Parts
bi-color Resistor (yellow-violet-brown) Pushbutton normally open Resistor (brown-black-orange) Resistor (red-red-brown) Jumper wires
Building Reaction Timer Circuit
Figure 3-14 shows schematic wiring diagram circuit that used with BASIC Stamp make reaction timer game. Build circuit shown Figure 3-14. TestBiColorLED.bs2 from Chapter Activity test bi-color circuit make sure your wiring correct. re-built pushbutton circuit this activity, ReadPushbuttonState.bs2 from Activity this chapter make sure your pushbutton working properly.
Page What's Microcontroller?
Figure 3-14 Reaction Timer Circuit
Programming Reaction Timer
This next example program will leave bi-color until game player presses holds pushbutton. When pushbutton held down, will turn short period time. When turns green, player pushbutton fast can. time between when turns green when pushbutton tracked program used measure reaction time. example program also demonstrates polling counting work. Polling process checking something over over again very quickly changed. Counting process adding number variable each time something does does not) happen. this program, BASIC Stamp will poll from time bi-color turns green until pushbutton released. will wait 1/1000 second using command PAUSE Each time polls pushbutton released, will counting variable named timeCounter. When pushbutton released, program stops polling sends message Debug Terminal that displays value timeCounter variable.
Example Program: ReactionTimer.bs2
Enter ReactionTimer.bs2. Follow prompts Debug Terminal (see Figure 3-15).
Chapter Digital Input Pushbuttons Page
Figure 3-15 Debug Terminal Reaction Timer Game Instructions
What's Microcontroller ReactionTimer.bs2 Test reaction time with pushbutton bi-color LED. {$STAMP BS2} {$PBASIC 2.5} timeCounter Word Declare variable store time. Display reaction instructions.
DEBUG "Press hold pushbutton.", make light turn red.", "When light turns green, let", fast can.", LOOP UNTIL HIGH PAUSE 1000 HIGH timeCounter
Begin main loop. Nested loop repeats. until pushbutton press. Bi-color red. Delay second. Bi-color green. timeCounter zero.
Page What's Microcontroller?
PAUSE timeCounter timeCounter LOOP UNTIL DEBUG "Your time timeCounter, ms.", play again, hold "button down again.", LOOP
Nested loop, count time.
until pushbutton released. Bi-color off. Display time measurement. Play again instructions. Back "Begin main loop".
ReactionTimer.bs2 Works
Since program will have keep track number times pushbutton polled, variable called timeCounter declared.
timeCounter Word Declare variable store time.
Variables initialize zero: When variable declared PBASIC, value automatically zero until command sets value.
DEBUG commands contain instructions player game.
DEBUG "Press hold pushbutton.", make light turn red.", "When light turns green, let", fast can.", DO.LOOP statements nested. other words, DO.LOOP inside
another.
LOOP UNTIL Rest program here. LOOP Back "Begin main loop". Begin main loop. Nested loop repeats. until pushbutton press.
Chapter Digital Input Pushbuttons Page
inner DO.LOOP deserves closer look. DO.LOOP condition decide whether break loop move more commands that come afterwards. This DO.LOOP will repeat itself long button pressed (IN3 DO.LOOP will execute over over again, until Then, program moves next command after LOOP UNTIL statement. This example polling. DO.LOOP UNTIL polls until pushbutton pressed.
LOOP UNTIL Nested loop repeats. until pushbutton press.
commands that come immediately after LOOP UNTIL statement turn bi-color red, delay second, then turn green.
HIGH PAUSE 1000 HIGH Bi-color red. Delay second. Bi-color green.
soon bi-color turns green, it's time start counting track long until player releases button. timeCounter variable zero, then another DO.LOOP with UNTIL condition starts repeating itself. repeats itself until player releases button (IN3 Each time through loop, BASIC Stamp delays using PAUSE also adds value timeCounter variable.
timeCounter timeCounter zero. Nested loop, count time.
PAUSE timeCounter timeCounter LOOP UNTIL until pushbutton released.
bi-color turned off.
results displayed Debug Terminal.
DEBUG "Your time timeCounter, ms.", play again, hold
Page What's Microcontroller?
"button down again.",
last statement program LOOP, which sends program back very first statement.
Your Turn Revising Design
marketing department gave your prototype some game testers. When game testers were done, marketing department came back with itemized list three problems that have fixed before your prototype built into game controller. Save ReactionTimer.bs2 under name (like ReactionTimerYourTurn.bs2). "itemized list" problems their solutions discussed below. Item-1 When player holds button seconds, score actually 14000 measurement seconds. This fixed! turns that executing loop itself along with adding timeCounter variable takes about without PAUSE command. This called code overhead, it's amount time takes BASIC Stamp execute commands. quick that will improve accuracy simply comment PAUSE command deleting adding apostrophe left
PAUSE
commenting PAUSE test accurate program Instead commenting delay, another program multiply your result two. example, just before DEBUG command that displays number insert command that multiplies result two:
timeCounter timeCounter this DEBUG "Your time timeCounter, ms.",
Uncomment PAUSE command deleting apostrophe, multiply solution instead.
Chapter Digital Input Pushbuttons Page
precision, operator multiply value with fraction make your answer more precise. operator hard use; here's how: Place value variable want multiply fractional value before operator. Take fractional value that want multiply 256. Round anything right decimal point. Place that value after operator.
Example: Let's want multiply timeCounter variable 3.69. Start placing timeCounter left operator: timeCounter timeCounter Multiply your fractional value 256: 3.69 944.64. Round off: 944.64 945.
Place that value right operator: timeCounter timeCounter
Item-2 Players soon figure that delay from green second. After playing several times, they better predicting when their score longer reflects their true reaction time. BASIC Stamp RANDOM command. Here modify your code random number: beginning your code, declaration variable called value, value called seed because starts pseudo random number sequence.
timeCounter WORD value BYTE value this this
Just before pause command, RANDOM command give value "random" value from pseudo random sequence that started with
RANDOM value DEBUG "Delay time 1000 value, this. this.
Page What's Microcontroller?
Modify PAUSE command that random value added 1000 (for second) PAUSE command's Duration argument.
PAUSE 1000 value Modify this.
What's algorithm? algorithm sequence mathematical operations. What's pseudo random? Pseudo random means that seems random, isn't really. Each time start program over again, will same sequence values. What's seed? seed value that used start pseudo random sequence. different value (change value from some other number), will different pseudo random sequence.
Item-3 player that lets button before light turns green gets unreasonably good score ms). Your microcontroller needs figure player cheating. Pseudo code introduced near Activity this chapter. Here some pseudo code help apply IF.THEN.ELSE statement solve problem. value timeCounter equals Display message telling player wait until after light turns green button. Else, value timeCounter greater than Display value timeCounter (just like ReactionTimer.bs2) time Modify your program implementing this pseudo code PBASIC cheating player problem.
Chapter Digital Input Pushbuttons Page
SUMMARY
This chapter introduced pushbutton common pushbutton circuits. This chapter also introduced build test pushbutton circuit BASIC Stamp read state more pushbuttons. BASIC Stamp programmed make decisions based state(s) pushbutton(s) this information used control LED(s). reaction timer game built using these concepts. addition controlling LEDs, BASIC Stamp programmed poll pushbutton take time measurements. Reading individual pushbutton circuits using special variables built into BASIC Stamp (IN3, IN4, etc.) introduced. Making decisions based these values using IF.THEN.ELSE statements, IF.ELSEIF.ELSE statements, code blocks were also introduced. evaluating more than condition, operators were introduced. Adding condition DO.LOOP using UNTIL keyword introduced along with nesting DO.LOOP code blocks.
Questions
What difference between sending receiving HIGH signals using BASIC Stamp? What does normally open mean? What warning signs that indicate might have made serious mistake while wiring your circuit? What happens between terminals normally open pushbutton when press What states pushbutton circuit What numbers does BASIC Stamp each these states? What does BASIC Stamp that input when normally open pushbutton circuit that uses pull-down resistor pressed? What does when pushbutton pressed? When does current flow through pushbutton circuit with normally open pushbutton? What value when pushbutton connects Vdd? What value when pushbutton connects Vss? What does command DEBUG What difference between pull-up pull-down resistor?
Page What's Microcontroller?
modify pushbutton circuit that used have pull-down resistor that pull-up resistor, expect changes values pin? What difference between active-low active-high? What kind code blocks used making decisions based value more pushbuttons? What does nesting mean? What does HOME formatter statement DEBUG HOME? What does polling mean? What does code overhead mean?
Exercises
Draw circuit schematic with normally open pushbutton circuit with pulldown resistor connected Draw circuit schematic with normally open pushbutton circuit with pull-up resistor connected Explain modify ReadPushbuttonState.bs2 page that reads pushbutton every second instead every second. Explain modify ReadPushbuttonState.bs2 that reads normally open pushbutton circuit with pull-up resistor connected Explain FOR.NEXT loop PushbuttonControlledLed.bs2 page that flashes fifteen times before checking button pressed again. Explain modify PushbuttonControlledLed.bs2 that stays (instead flashing) when press hold pushbutton. Modify "Your Turn" version PushbuttonControlOfTwoLeds.bs2 that both LEDs flash when none pushbuttons pressed, LEDs flash when both pushbuttons pressed held. Explain modify ReactionTimer.bs2 page that uses WHILE instead LOOP UNTIL. Write down examples code blocks must change make work. Hint: LOOP UNTIL makes decision using condition that causes program break loop. WHILE makes decision based condition that keeps loop repeating.
Projects
Test your answer Exercise making ReactionTimer.bs2 work with WHILE instead LOOP UNTIL.
Chapter Digital Input Pushbuttons Page
Refer streetlight project previous chapter's Projects section. Some streetlight controllers work just timer; they have sensors under pavement that detect whether waiting light. Modify streetlight controller that north-south street gets green light time, press pushbutton will initialize east-west sequence through. Modify ReactionTimer.bs2 that player game. second button wired second player. HINTS: operator your DO.LOOP UNTIL loop. Declare different timeCounter variables, timeCounterA timeCounterB. IF.THEN reasoning DO.LOOP that increments counters. also borrow some decision making code from PushbuttonControlOfTwoLeds.bs2 help making decisions whether increment counters.
Further Investigation
resources listed here available free download from Parallax site also included Parallax "BASIC Stamp Manual", Users Manual, Version 2.0c, Parallax Inc., 2000 BASIC Stamp Manual more examples information that further explains following: DEBUG HOME formatters, input variables such IN3, IN4, RANDOM command. "Basic Analog Digital", Student Guide, Version 2.0, Parallax Inc., 2003 Basic Analog Digital explains binary counting using pushbuttons. also uses pushbuttons introduce technique transmitting numbers from system another called synchronous serial communication. "BASIC Stamp Editor Help File", PBASIC Version Parallax Inc., 2003 PBASIC Help File information WHILE UNTIL conditions used with DO.LOOP, information nesting IF.THEN.ELSE code blocks, which PBASIC included BASIC Stamp Manual. find this information clicking book icon your BASIC Stamp Editor task bar, then selecting PBASIC Reference from menu left sidebar window. This will open PBASIC Command Reference alphabetical listing main window. Detailed information found clicking each command.
Chapter Controlling Motion Page
Chapter Controlling Motion
MICROCONTROLLED MOTION
Microcontrollers make sure things move right place around every day. have inkjet printer, print head that goes back forth across page prints moved stepper motor that controlled microcontroller. automatic grocery store doors that walk through controlled microcontrollers, automatic eject feature your player also controlled microcontroller.
ON/OFF SIGNALS MOTOR MOTION
Just about microcontrolled motors receive sequences high signals similar ones you've been sending LEDs. difference that microcontroller send these signals rates that usually faster than detect. timing number separate high/low signals differ from motor next, they controlled microcontrollers ca

Other recent searches


VSX50MD23 - VSX50MD23   VSX50MD23 Datasheet
TD62308BP1G - TD62308BP1G   TD62308BP1G Datasheet
TD62308BFG - TD62308BFG   TD62308BFG Datasheet
NJM7800 - NJM7800   NJM7800 Datasheet
NJM7800FA - NJM7800FA   NJM7800FA Datasheet
MCP1826 - MCP1826   MCP1826 Datasheet
MCP1826S - MCP1826S   MCP1826S Datasheet
MAX7651 - MAX7651   MAX7651 Datasheet
LH1505AB - LH1505AB   LH1505AB Datasheet
ICS181-01 - ICS181-01   ICS181-01 Datasheet
ER3A - ER3A   ER3A Datasheet
ER3G - ER3G   ER3G Datasheet
AME8800 - AME8800   AME8800 Datasheet
AME8800 - AME8800   AME8800 Datasheet
8811 - 8811   8811 Datasheet

 

Privacy Policy | Disclaimer
© 2013 Datasheets.org.uk