1 / 32

Basic Stamp OEM module

Basic Stamp OEM module. By Wilmer Arellano. P0-P15 I/O. Reset Input (RES). 5.5 – 15V input (Vin). Ground- 0V (Vss). Regulated 5V (Vdd). The BASIC Stamp 2 OEM is a discreet component version of the BS2 which may be purchased in kit form.

helga
Download Presentation

Basic Stamp OEM module

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic StampOEM module By Wilmer Arellano

  2. P0-P15 I/O Reset Input (RES) 5.5 – 15V input (Vin) Ground- 0V (Vss) Regulated 5V (Vdd) • The BASIC Stamp 2 OEM is a discreet component version of the BS2 which may be purchased in kit form. • The male header provides the means to ‘plug-it’ into your own board, or connect to other boards. Power the board with EITHER:A) 5.5-15VDC on Vin. This will also provide 5VDC regulated output on Vdd.B) Regulated 5V Input on Vdd. 2

  3. Using the breadboard(Socket board) The metal strips are laid out as shown in orange. The long top and bottom row of holes are usually used for power supply connections. The bread board has many strips of metal (copper usually) which run underneath the board. To use the bread board, the legs of components are placed in the holes (the sockets). The holes are made so that they will hold the component in place. The circuit is built by placing components and connecting them together with jumper wires.

  4. Connection 220 Ohm resistor should be connected to pin P4 of the OEM Basic Stamp 2sx. “+” (long) lead of LED should be connected to opposite side of the resistor. The other (short) lead of the LED goes to “-” 220 Ohm 9 V battery LED

  5. Flashing LED ' {$STAMP BS2sx} ' {$PBASIC 2.5} Green: 'Label Or point were you can RETURN LOW 4 'Set pin 4 an output pin and low voltage "0" PAUSE 1000 'Pause 1000 ms HIGH 4 'Set pin 4 an output pin and high voltage "1" PAUSE 1000 'Pause 1000 ms GOTO Green

  6. Flashing LED + Switch Input ' {$STAMP BS2sx} ' {$PBASIC 2.5} Green: 'Label Or point were you can RETURN LOW 4 'Set pin 4 an output pin and low voltage "0" PAUSE 1000 'Pause 1000 ms HIGH 4 'Set pin 4 an output pin and high voltage "1" PAUSE 1000 'Pause 1000 ms DEBUG ? IN1 'Input the value of pin 1 PAUSE 1000 'Pause 1000 ms GOTO Green

  7. ' {$STAMP BS2} ' {$PBASIC 2.5} OUTPUT 4 Green: OUT4=0 PAUSE 1000 OUT4=1 PAUSE 1000 DEBUG ? IN1 PAUSE 1000 GOTO Green

  8. ' {$STAMP BS2} ' {$PBASIC 2.5} OUTPUT 4 INPUT 1 Green: OUT4=IN1 PAUSE 1000 GOTO Green

  9. Variables • Bit 0 or 1 • Nibble (Nib) 0-15 • Byte 0-255 • Word 0-65535 or -32768 to + 32767

  10. ' {$STAMP BS2} ' {$PBASIC 2.5} NS VAR Bit EW VAR Bit TOTAL VAR Byte NOC CON 20 TOTAL = 0 OUTPUT 4 INPUT 1 TOTAL = TOTAL +100 DEBUG ? TOTAL TOTAL= TOTAL/3 DEBUG ? TOTAL DEBUG ? NOC Green: OUT4=IN1 PAUSE 1000 GOTO Green

  11. Pseudo Code • Start of program • Measure temperature • Temperature < 100 F? • Yes, Turn on heat • Temperature > 102 F? • Yes, Turn on cooling fan • Go back to start.

  12. Start MeasureTemperature Temp.< 100 Yes EnergizeHeater No Temp.> 102 Yes EnergizeFan No Start 13

  13. Sequential Flow Example Code: Start ' <<<< INSERT COMMON ' CIRCUIT DECLARATIONS >>>> 'Prog 6A: Example of sequential flow ' ****** Main program ************ LED1 = LED_Off 'Turn off LED 1 LED2 = LED_Off 'Turn off LED 2 PAUSE 2000 'Pause for 2 sec. LED1 = LED_On 'Light LED 1 PAUSE 2000 'Pause for 2 sec. LED2 = LED_On 'Light LED 2 END Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 2 Second Pause Turn ON LED2 End Flowchart: Pseudo-Code: Start of program • Turn off LED 1 • Turn off LED 2 • Pause for 2 seconds • Light LED 1 • Pause for 2 seconds • Light LED 2 • End of program 14

  14. Branching Overview - GOTO • Branching is the act of breaking out of a sequence to perform code in another location of the program. • The simplest form of branching is to use the GOTO instruction: GOTO label

  15. Looping Flow Example Code: Start ' <<<< INSERT COMMON ' CIRCUIT DECLARATIONS >>>> 'Prog 6B: Example of sequential flow ' with looping ' ****** Main program ************ Main: LED1 = LED_Off 'Turn off LED 1 LED2 = LED_Off 'Turn off LED 2 PAUSE 2000 'Pause for 2 sec. LED1 = LED_On 'Light LED 1 PAUSE 2000 'Pause for 2 sec. LED2 = LED_On 'Light LED 2 GOTO Main 'Repeat sequence Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 2 Second Pause Turn ON LED2 Flowchart: Pseudo-Code: Start of program • Turn off LED 1 • Turn off LED 2 • Pause for 2 seconds • Light LED 1 • Pause for 2 seconds • Light LED 2 • Go back to start 16

  16. Conditionals Overview • The previous example is an unconditional branch; the program will branch back to Main regardless of any code parameters. • In a conditional branch a decision is made based on a current condition to branch or not to branch. • As humans, we constantly make decisions based on input as to what to perform. Shower too cold? Turn up the hot. Shower too hot? Turn down the hot water. • Microcontrollers can be programmed to act based on

  17. IF…THEN • The IF-THEN is the primary means of conditional branching.IF condition THEN addressLabel • If the condition is evaluated to be true, execution will branch to the named address label. • If the condition is not true, execution will continue to the next step in the program sequence. • A condition is typically an equality:value1 = value2value1 > value2value1 < value2IN8 = 1 • Compared to many versions of BASIC and other languages, the PBASIC 2.0 implementation of the IF-THEN is fairly limited. See the PBASIC 2.5 appendix for new implementations of IF-THEN.

  18. IF-THEN Example: Alarm Main Button 1Pressed False True Speaker2000Hz for1 second Main • This program will sound the alarm as long as pushbutton 1 is pressed. Flowchart Program Code ' <<<< INSERT SECTION 5 COMMON ' CIRCUIT DECLARATIONS >>>> 'Prog 6C: Conditional Branching Alarm Main: ' If pushbutton 1 is pressed, ' then go sound alarm IF PB1 = PB_On THEN Alarm GOTO Main Alarm: 'Sound the alarm FREQOUT Speaker, 1000, 2000 GOTO Main Pseudo-Code • Start: • Is button 1 pressed? • Yes, Go sound Alarm • No, Go back to start • Alarm • Sound speaker • Go back to start of program 19

  19. ' {$STAMP BS2} ' {$PBASIC 2.5} NS VAR Bit EW VAR Bit OUTPUT 4 OUTPUT 10 INPUT 1 Green: OUT4=1 OUT10=0 NS=IN1 IF NS=1 THEN green OUT4=0 OUT10=1 PAUSE 10000 GOTO Green

  20. Car1 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • PAUSE 5000 • HIGH 10 • LOW 11 • start: • HIGH 4 • HIGH 8 • LOW 9 • PAUSE 3000 • LOW 4 • LOW 8 • PAUSE 3000 • HIGH 9 • PAUSE 3000 • LOW 9 • PAUSE 3000 • GOTO start

  21. PWM

  22. Car 2 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • PWM 8, 200, 255

  23. Car 3 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • DO • PWM 8, 80, 255 • LOOP

  24. Car 4 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 1 • DO WHILE (IN1 = 0) • PWM 8, 80, 255 • LOOP

  25. Car 5, Switch in pin 1 will stop • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 1 • DO WHILE (IN1 = 0) • PWM 8, 80, 255 • LOOP

  26. Car 6, Switch in pin 1 will change speed • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 1 • DO • IF IN1 = 0 THEN • PWM 8, 80, 255 • ELSE • PWM 8, 255, 255 • ENDIF • LOOP

  27. IR SENSOR • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 6 • DO • FREQOUT 5, 10, 15400 • IF IN6 = 0 THEN • HIGH 4 • ELSE • LOW 4 • ENDIF • LOOP LED at pin 4 will turn on if an object is present

  28. Car 7 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 6 • PWM 8, 120, 255 • DO • FREQOUT 5, 10, 15400 • IF IN6 = 0 THEN • LOW 8 • ELSE • PWM 8, 120, 255 • ENDIF • LOOP IR emitter pin 5 Sensor pin 6 There is no need for the pause The car will stop completely

  29. Car 8 • ' {$STAMP BS2sx} • ' {$PBASIC 2.5} • INPUT 6 • PWM 8, 150, 255 • LOW 11 • DO • FREQOUT 5, 10, 15400 • IF IN6 = 0 THEN • HIGH 9 • HIGH 11 • PAUSE 1000 • ELSE • LOW 11 • LOW 9 • PWM 8, 150, 255 • ENDIF • LOOP If obstacle detected, the car will move backwards while turning Try to use left and right sensors You are not required to use the PING sensor this time. If you are interested please let me know

More Related