Stage 3 – Interfacing Workshop Handout. Page 1 of 21 myke predko. Stage 3 –
Interfacing Workshop “IR. Tag” Robot Modification Notes. In the “Stage 3 ...
Stage 3 – Interfacing Workshop Handout
Stage 3 – Interfacing Workshop “IR Tag” Robot Modification Notes
In the “Stage 3 – Interfacing Workshop”, instructions will be provided to modify the Sumo-Bot with new hardware and software so that it can compete in “IR Tag” competitions against other robots. Changes in the robot’s operation are made by downloading new software into the BS2 built into the Sumo-Bot and additional hardware was added to the breadboard. An important aspect of these modifications is how the BS2 built into the Sumo-Bot can interface with both the Sumo-Bot itself as well as electronics added to the breadboard. The modifications do not change the basic function or the capabilities of the Sumo-Bot and can be removed or changed at any time. The parts required for the IR Tag modification are: • Preprogrammed PIC16F505 • 2x Infrared (IR) Receivers • 1x IR LED • 3x Bright White LEDs • 1x Red LED • 2x 100 Ohm Resistors • 1x 4.7k Resistor • 2x 47 uF Capacitors • 3 cm Long Piece of 5 mm Heat Shrink Tubing
Page 1 of 21
The tools required for the IR Tag modification are: • Small wire clippers • Small Needle Nose Pliers • Jeweller’s Screw Driver Kit • Pre-Cut Breadboard Wiring Kit
myke predko
Stage 3 – Interfacing Workshop Handout
Sumo-Bot IR Tag Modification The modification to the Sumo-Bot to give it the capabilities of playing “IR Tag” is based around the addition of a PIC16F505 microcontroller. The PIC16F505 is programmed with a base set of subroutines which controls the operation of a number of LEDs by command of a controlling BS2 as well as monitor an input from a pair of IR Remote control receivers. The Sumo-Bot BS2 is controls the PIC16F505 and provides the basic “brains” of the robot with the IR Tag electronics added to it. The schematic for the IR Tag Modification is shown in Figure 1. Appendix A provides a brief description of the different components and some of their important attributes. Note that the schematic in Figure 1 is slightly unconventional as it based on the pinout and I/O characteristics of the PIC16F505. Assembly instructions are provided in the workshop itself.
IR Rx
IR Rx
The PIC16F505 controls the operation of three bright white LEDs which normally flash on and off in sequence to help autonomous robots detect it. Also in the circuit is a red “Hit” indicator LED which is lit by the PIC16F505 either when an IR signal is received on one of the two IR Remote Control Receivers (“IR Rx”) or by command from the Sumo-Bot’s BS2. The “IR LED” will shoot a beam of IR light (directed by the heat shrink tubing placed over it) on command from the BS2.
Figure 1. IR Tag Electronics Modification The IR Tag circuitry is wired to the Sumo-Bot’s breadboard as shown in Figure 2 and uses the parts listed at the start of this handout and results in the circuitry shown in the photograph at the start of the handout. When wiring the circuitry to the breadboard, make sure that the polarity of the LEDs and capacitors is checked and followed when installing and wiring the parts into the breadboard.
Page 2 of 21
myke predko
IR LED
100
4.7k
47
+3V Bat Gnd P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
100
47
PIC16C505
Robot Front
+3V Bat Gnd P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
Stage 3 – Interfacing Workshop Handout
Figure 2 – IR Tag Sumo-Bot Breadboard Wiring The IR Tag PIC16F505 has the same BS2 to the PIC16C505 interface built into the Sumo-Bot (which is described in a later section) with its own unique set of commands listed in Table 1. By reading through the commands, you can see that the various visible light LEDs can be turned on and off from the BS2, some LEDs can be flashed, the IR LED can be commanded to shoot, the IR Receiver counter can be polled and some basic operating conditions (such as allowing a set number of hits before stopping) can be specified.
Page 3 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Direct Commands Label TagFire
Response Command Function Label Value TagGetHitNum 16 Shoot IR Cannon (1x per Second) Turn Off IR 2 TagIROff Sensors Turn On IR 3 TagIROn Sensor Turn off 4 TagWhiteOff all three White LEDs Turn on all 5 TagWhiteAll three White LEDs Toggle 6 TagLeftWhite State of Front/Left White LED Toggle 7 TagRightWhite State of Front/Right White LED Toggle 8 TagRearWhite State of Rear White LED Cycle Three 9 TagWhiteCycle White LEDs Turn on Red 10 TagIndOn LED Turn off 11 TagIndOff Red LED Clear the 12 TagHitClear Tag Hit Counter Stop 13 TagMaxHit1 Competition after 1 Hit Stop 14 TagMaxHit5 Competition after 5 Hits No Limit to 15 TagNoMaxHit hits (Default) Table 1 – BS2 to IR Tag PIC16F505 Commands Value 1
Function Return the Current Hit Counter Value
To help facilitate the wiring of the application a “Test Gun” was created. This circuit uses a modified version of the PIC16F505 code to indicate if a built in IR Receiver is “Hit” by the modified Sumo-Bot. Along with this feature, the Test Gun is capable of sending out a compatible “Shot” that the two IR Receivers on the modified Sumo-Bot should be able to detect. The “Shot” consists of eight, 3 ms signals which are 3 ms apart and modulated at 38 kHz and passed to the IR LED. The heat shrink tubing directs the signal out of the IR LED to a narrow
Page 4 of 21
myke predko
Stage 3 – Interfacing Workshop Handout beam that spreads by only two to four degrees, requiring some element of “aiming” to hit a competitor. The light output is much less than the total from the IR LED due to the heat shrink tubing absorbing most of the energy. The basic BS2 application is called “MAX 5 Tournament” and can be blocked out using pseudocode as: Start: Initialize Robot and IR Tag ‘505 Interface Pins Stop Robot from Starting Random Movement Flash LED Once Set IR Tag PIC16F505 to indicate when it has been hit 5x Do PAUSE 100 ms
‘
Don’t Saturate ‘505s
If 1BarButton then Fire IR Cannon/Flash LED If 5 Hits (Robot Lost) and 3BarButton then Reset IR Tag Loop
‘
Loop Forever
Autonomous operation of the robot can be programmed by moving the robot randomly (to prevent a competitor from hitting it) while trying to sense obstacles in front of the robot and implementing some kind of search and fire strategy. Possible strategies could consist of: 1. Move randomly about the arena (turning away when an obstacle is encountered) and “Fire” once every three hundred milliseconds or so. The PIC16F505 software will not allow firing of the IR Cannon in intervals of less than one second, so the repeated attempts will ensure the robot fires as soon as it is possible. 2. Move randomly and continuously poll the light sensors, waiting for the light level in front of the robot to change (indicating the white LED facing the robot is flashing and the opposing robot is in front of the robot) before firing. This strategy would probably work best in a small arena with constant lighting. 3. Move until hitting an obstacle, retreat backwards a few centimeters and then turn while firing, this attempt at blanketing the arena would give the robot a good opportunity for hitting an opponent. 4. Waiting for the opponent to hit you and then turning while firing in an attempt to hit the opponent by assuming that the opponent will be in a vulnerable position. This strategy could be dangerous as the opponent could get multiple hits on the robot before the robot hits it. These strategies have been tried with varying degrees of success. Factors which affect their effectiveness against other autonomous or human controlled opponents is dependent on various factors including, arena size and type, ambient lighting, the skill of the opponent and a large amount of luck. Regardless of the factors that the robot will have to contend, the process of coming up with a strategy and testing it out is a lot of fun and very educational.
Page 5 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Sumo-Bot Microcontroller Operation The basic Sumo-Bot consists of two microcontrollers (MCUs) that work together. This was an important design feature for the Sumo-Bot as it allows people that are new to electronics and programming to easily add simple modifications but does not limit more experienced designers from adding complex modifications relatively easily and efficiently. The IR Tag application would be considered to be a sophisticated modification, taking advantage of the communications capabilities of the built in Parallax BASIC Stamp 2 (BS2) MCU of the Sumo-Bot to control the overall operation of the robot and the added electronics.
I/O Pins Basic Sumo-Bot BASIC Stamp 2
Remote Control
PIC16C505
Sumo-Bot Motors and Built in Sensors
Figure 3 – Sumo-Bot Microcontroller (MCU) Interconnection Block Diagram In Figure 3, the interconnection between the Sumo-Bot’s two MCUs and the IR Tag MCU is shown. The base Microchip PIC16C505 MCU provides control for the “hard” interfaces built into the robot and provides a base set of functions that can be used by the robot application developer instead of having to create them on their own. Without any commands from the BS2, the PIC16C505 provides a basic capability for the robot which includes automatic operation (ie starting random motion when the robot is first turned on) and handling remote control commands from the user. The functions provided by the PIC16C505 include: • Robot Power Up Initialization • “Random” Motion Behavior • “Light Seeking” Motion Behavior • “Light Avoiding” Motion Behavior • “Wall Following/Maze solving” Behavior
• • • •
IR Object Detector Operation and Polling Light Sensor Operation and Polling Remote Control Receiver Operation BS2 Control Interface
The built in Parallax BASIC Stamp 2 (BS2) gives the application developer the ability to create their own programs to control the operation of the Sumo-Bot. The BS2 is programmed in a variant of BASIC (“Beginner’s All-purpose Symbolic Instruction Code”) known as “PBASIC” and a
Page 6 of 21
myke predko
Stage 3 – Interfacing Workshop Handout synopsis of the language is provided in the Appendices. Figure 4 is an overview of the BS2 and more information and sample BS2 applications can be found at http://www.parallax.com.
Parallax BASIC Stamp 2 Information •
Programmed in “PBASIC” o Simplified BASIC Designed for Control Applications o Has 42 Built in Functions o Compiled on a PC and Tokens Downloaded into Stamp o Version 2.5 Provides Structured Programming Statements • Built from Microchip PIC Microcontroller o PIC MCU Executes PBASIC Token Interpreter o 16 PIC MCU I/O Pins used for BS2 I/O o PIC MCU Provides RS-232 and EEPROM Communications • 2 kByte EEPROM holds PBASIC Tokens • In Standard BS2, Power Supply Converts 6 to 25 V to 5 Volts o Power Supply not used in SumoBot • Executes at 4,000 PBASIC Statements per Second Figure 4 – BS2 Features
Power Supply
PIC15C57 Microcontroller
RS-232
I/O Pins
EEPROM Memory
Using the serial “SHIFTIN” and “SHIFTOUT” PBASIC Commands, the built in BS2 can communicate with the PIC16C505. The traditional code format to send data to the PIC16C505 in the Sumo-Bot is: RobotData = RobotCommand GOSUB RobotSend
‘
Send Command to Robot
or RobotData = RobotPollCommand ‘ Get Information from Robot GOSUB RobotSendReceive ‘ “RobotData” Contains the Response from the PIC16C505 The Robot Commands are listed in Table 2 and Table 3 has the direct operating commands and commands that produce a response from the PIC16C505, respectively. These commands can be used to make the robot move forwards, backwards or turn. The executing state of the robot can be polled as well as the state and value of the different sensors on the robot. When a BS2 command is sent to the PIC16C505, the command reception, processing and optional reply becomes the highest priority task for the PIC16C505 and all other tasks become secondary. If a BS2 application is to send commands repeatedly to the PIC16C505, it is recommended that each command waits at least 50 ms after the previous one before being sent. Ideally this delay should be 100 ms or more.
Page 7 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Label Value Function RobotStop 0 Stop Robot Behavior1 1 Random Movement – Default Operation (after 1.5 Seconds) Behavior2 2 Light Seeking Behavior3 3 Light Avoiding Behavior4 4 Maze Solving/Wall Following RobotForward 5 Robot Moves Forward for 200 ms RobotReverse 6 Robot Moves in Reverse for 200 ms RobotLeft 7 Robot Turns Left for 200 ms RobotRight 8 Robot Turns Right for 200 ms RobotLEDOn 9 LED on Robot Turned On RobotLEDOff 10 LED on Robot Turned Off RobotPWM0 11 Motor PWM Duty Cycle Set to Zero RobotPWM1 12 Motor PWM Duty Cycle Set to First “Notch” (63%) RobotPWM2 13 Motor PWM Duty Cycle to Second “Notch” (75%) RobotPWM3 14 Motor PWM Duty Cycle to Third “Notch” (86%) RobotPWM4 15 Motor PWM Duty Cycle to Fourth “Notch” (100%) – Default Power Level Table 2 – BS2 to PIC16C505 Commands Label RobotPWM RobotState
Value Function 16 Return the Current PWM “Notch” Value 17 Return Executing State (See Previous Table for Movement/Behavior Values) RobotWhiskers 18 Return State of Whiskers Bit 0 Set, Left Bit 1 Set, Right RobotCDSL 19 Return Left Light Sensor Value RobotCDSR 20 Return Right Light Sensor Value RobotBUTTON 21 Return Last Remote Button Press 0/No Button Pressed 1/Single Bar (“|”) Last Pressed 2/Double Bar (“||”) Last Pressed 3/Third Bar (“|||”) Last Pressed After Button Read, Save is Cleared Table 3 –PIC16C505 to BS2 Data Return Commands The BS2 built into the robot can interface to external circuitry via the I/O connectors and breadboard built into the top of the Sumo-Bot (Figure 5). The connector passes ground, regulated and unregulated power for use by the application. It is recommended that the regulated 3.3 Volts available on the PCB be used for digital logic as this is the same voltage as used by the BS2 and will avoid the need for performing any kind of level shifting. The 11 I/O pin interface (“P0” through “P10”) consists of standard BS2 I/O pins which can be used for digital I/O, serial I/O or limited analog capabilities (described in the BS2 Documentation).
Page 8 of 21
myke predko
+3V Bat Gnd P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
+3V Bat Gnd P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
Stage 3 – Interfacing Workshop Handout
Figure 5 – Sumo-Bot Breadboard and BS2 Connector When programming the BS2, especially as part of the Sumo-Bot, it is recommended that the “Program Template.bs2” file is used as this will provide the application developer with the basic framework and declarations for the Sumo-Bot interfaces listed in Table 2. At the very least, all software should be designed to take advantage of PBASIC 2.5 which includes structured programming statements (if/else/endif, do while/loop). PBASIC 2.5 can compile and execute code written for a previous version of the compiler. The CD-ROM that comes with the Sumo-Bot contains a downlevel version of the PBASIC desktop and compiler, the latest version can be downloaded, free of charge, from (http://www.parallax.com). To ensure that the advanced features of PBASIC 2.5 are available, add the following two lines at the start of the program: '{$STAMP BS2} '{$PBASIC 2.5}
Page 9 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Appendix A – Components The Microchip PIC16F505 Microcontroller Two PIC ‘505 microcontrollers are used in the Sumo-Bot and IR Tag modifications. The PIC16C505 comes pre-programmed as part of the Sumo-Bot, provides basic I/O operations and cannot be reprogrammed. The PIC16F505 that is added to the Sumo-Bot and controls the IR Tag operations can be reprogrammed to perform different functions. The basic part information for the PIC16F505 can be found in Figure 6. More information, including development tools can be found at http://www.microchip.com.
Microchip PIC16F505 Microcontroller Programmed in “Assembler” or Compiled High Level Language Has 33 Instructions Applications “Built” on a PC and Instruction File Programmed into PIC MCU Many Free Development Tools On Internet Memory, I/O, Processor Support on Single Chip 512 Instruction Reprogrammable (Flash) Memory 12 I/O Pins Internal or External Clocking and Reset Requires 2 to 6 Volts for Operation Normally Executes at 4 MHz 1 MIPs Operation
Figure 6 – Microchip PIC16F505 Features
Page 10 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
LEDs An LED produces light when current passes through it. This light can be a variety of different colours including Infrared, which is invisible to the human eye. The schematic symbol and part appearance is shown in Figure 7.
Schematic Symbol “Light Rays” Indicating LED
Line Corresponds to "Flat" on component’s base
Current Direction
Actual Part Appearance “Flat” on side of diode Indicates polarity and Direction of Current Flow
Figure 7 – LED Schematic Symbol and Part Appearance
Page 11 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Resistors Resistors impede the flow of electricity according to Ohm’s Law which states that The current through a resistor is proportional to the Voltage applied to it. Or put mathematically: i = V/ R
Where: i is the current in Amperes (“A”) V is the voltage in Volts (“V”) R is the resistance in Ohms (“Ω”)
Figure 8 shows the physical appearance of a resistor while Table 4 provides the resistance values specified by different colour rings on the body of the resistor. The actual resistance is calculated using the formula: Resistance = ((Band1 x 10) + (Band2 x 1)) x 10Band3
Resistor Lead (wire)
Resistor Body
Value “Bands”
Resistor Lead
Tolerance Band
Value Bands should be Brown, Black and Red, from the End of the Resistor to the Center
Figure 8 – Resistor appearance and band placement. Colour Band Value Tolerance Black 0 N/A Brown 1 1% Red 2 2% Orange 3 N/A Yellow 4 N/A Green 5 0.5% Table 4 – Resistor Colour Band Values
Page 12 of 21
Colour Blue Violet Gray White Gold Silver
Band Value 6 7 8 9 N/A N/A
Tolerance 0.25% 0.1% 0.05% N/A 5% 10%
myke predko
Stage 3 – Interfacing Workshop Handout
Capacitors Capacitors are simple energy storage devices – they store energy in the form of electrical charge. The larger the electrical charge, the greater the amount of energy is stored in the device. The amount of charge stored in the capacitor is dependent on the voltage level of the charge and the amount of space within the capacitor. The units of charge storage in a capacitor is known as the “Farad” and is a very large number, resulting in the capacitances in most popular devices being measured in millionths or trillionths of a Farad. Along with storing energy, capacitors are also used to filter “noise” from a power line; in this application capacitors are analogous to neighbourhood water towers, storing water when the demand is low and releasing water when the demand is high. By storing and releasing water dynamically, the pressure delivered to the homes remains constant. There are different packages used for capacitors as shown in Figure 9. Note that some capacitors are polarized and how the Anode (Positive) and Cathode (Negative) connections are marked. The value of the capacitor is usually marked on the package with the units in Farads or consists of three digits which can be used to decode the capacitance using the formula: Capacitance = ((Digit1 x 10) + (Digit2)) x 10-12+Digit3 Farads
+
Positive Lead (Anode)
Electrolytic (Polarized) Capacitor Value/Rating
Capacitor Value Stamp (See Text)
Tantalum (Polarized) Capacitor Value/Rating
Unpolarized (Ceramic Disk or Polyester)
Negative Lead (Cathode)
Figure 9 – Capacitor Packages
Page 13 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
IR Operation The operation of the Sumo-Bot IR remote control, object detection system and the IR Tag IR Cannon are based on the same theory and hardware shown in Figure 10. An IR signal is sent from an IR LED to an IR Receiver. When the IR signal is received by the IR Receiver it drives its output line low. The IR signal does not consist of a simple digital signal, but a signal of a known duration which is modulated at 38 kHz (which means that the signal oscillates at 38 kHz while it is active). The IR Receiver is actually a very complex electronic device which detects and filters the 38 kHz modulated signal from the environment around it out from any other sources of IR light. When detecting objects around the robot, or when the IR Tag cannon “Shoots”, a modulated pulse of IR light is sent from the IR Receivers for a short period of time. If the IR Receivers receive this pulse (either by reflecting off an object or by being “shot” by another robot), their output signal goes active and the microcontroller that it is connected to responds as it is programmed.
I/R LED Sending 38 Khz Pulse
Opaque Barrier Between LED and Detector
Reflected Light Waves
Obstruction
I/R 38 KHz Detector Figure 10 – IR Object Detection Operation
Page 14 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Appendix B – Code Listings In this appendix, the BS2 code listings can be found for the IR Tag workshop. Downloadable versions of this code along with the IR Tag PIC16F505 source code can be found on http://www.tabrobotkit.com.
Tag Template This file provides the interfaces to the Sumo-Bot and IR Tag PIC ‘505 MCUs and should be used as a base for all applications. In the later applications, the Sumo-Bot and IR Tag constants and routines have been deleted to keep the code as short as possible. ' Template File ' ' Description ' ' ' Author: ' ' Date: ' ' '{$STAMP BS2} '{$PBASIC 2.5}
'
Variables
'
Mainline HIGH SC HIGH SD HIGH LED HIGH TC HIGH TD
'
Set the I/O Bits As O/P and High
'
High Tag I/O
#### - Put Application Code Here
' Robot Tag Interface Code ' ' Myke Predko ' ' Copyright (C) 2004 ' ' Tag PIC16C505 Commands TagFire CON 1 ' TagIROff CON 2 ' TagIROn CON 3 ' TagWhiteOff CON 4 ' TagWhiteAll CON 5 ' TagLeftWhite CON 6 ' TagRightWhite CON 7 ' TagRearWhite CON 8 ' TagWhiteCycle CON 9 ' TagIndOn CON 10 ' TagIndOff CON 11 ' TagHitClear CON 12 ' TagMaxHit1 CON 13 ' TagMaxHit5 CON 14 ' TagNoMaxHit CON 15 ' TagGetHitNum CON 16 ' '
' '
Follows
Fire (Once Per Second) IR Sensor Off IR Sensor ON (Default) White LEDs Off White LEDs ALL ON Left White LED Toggle Right White LED Toggle Rear White LED Toggle White LEDs Cycle (Default) Indicate LED ON Indicator LED Off (Default) Hit Counter Clear Maximum Hit Counter 1 (LEDs Flash) Maximum Hit Counter 5 (LEDs Flash) No Maximum Hit (Default) RETURN Hit Counter
Tag PIC16C505Interface Pins
Page 15 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
TC TD ' '
PIN 9 PIN 10
'
Define the I/O Pins
Robot Interface Variables "RobotData" is used for this Interface
' Robot Operation Subroutines TagSend: ' Send the Byte in "RobotData" LOW TC ' Hold Low for 1 msec before PAUSE 1 ' Shifting in DATA SHIFTOUT TD, TC, LSBFIRST, [RobotData] HIGH TC RETURN TagSendReceive: ' Send the Byte in "RobotData" LOW TC ' Hold Low for 1 msec before PAUSE 1 ' Shifting in Data SHIFTOUT TD, TC, LSBFIRST, [RobotData] PAUSE 1 ' Wait for Operation to Complete SHIFTIN TD, TC, LSBPOST, [RobotData] HIGH TC RETURN
' Robot Interface Code Follows: ' ' Myke Predko ' ' Copyright (C) 2004 McGraw-Hill ' ' Robot Commands RobotStop CON 0 ' Stop the Robot Behavior1 CON 1 ' Random Movement Behavior2 CON 2 ' Photovore Behavior3 CON 3 ' Photophobe Behavior4 CON 4 ' Wall Hugger/Maze Solver RobotForward CON 5 ' Move Forward for 200 msecs RobotReverse CON 6 ' Move Reverse for 200 msecs RobotLeft CON 7 ' Turn Left for 200 msecs RobotRight CON 8 ' Turn Right for 200 msecs RobotLEDOn CON 9 ' Turn on the Robot's LED RobotLEDOff CON 10 ' Turn off the Robot's LED RobotPWM0 CON 11 ' PWM = 0% Duty Cycle RobotPWM1 CON 12 ' PWM = 1st "Notch" RobotPWM2 CON 13 ' PWM = 2nd "Notch" RobotPWM3 CON 14 ' PWM = 3rd "Notch" RobotPWM4 CON 15 ' PWM = 100% Duty Cycle RobotPWM CON 16 ' Return the Current PWM Value RobotState CON 17 ' Return the Executing State RobotWhiskers CON 18 ' Return State of the "Whiskers" ' Bit 0 - Left "Whisker" ' Bit 1 - Right "Whisker" RobotCDSL CON 19 ' Return Value of Left CDS Cell RobotCDSR CON 20 ' Return Value of Right CDS Cell RobotBUTTON CON 21 ' Return the Last Remote Button Press ' 0 - No Buttons Pressed ' 1 - Leftmost Button Pressed ' 2 - Middle Button Pressed ' 3 - Rightmost Button Pressed ' After "RobotButton" Operation, ' Button Save is Cleared ' ROBOt Interface Pins SC PIN 14 SD PIN 15 LED PIN 11
'
Define the I/O Pins
'
ON PCB LED
' Robot Interface Variables RobotData VAR Byte ' Data Byte to Send to/Receive ' from Robot
Page 16 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
' Robot Operation Subroutines RobotSend: ' Send the Byte in "RobotData" IF ((RobotData = RobotLEDOn) OR (RobotData = RobotLEDOff)) THEN IF (RobotData = RobotLEDOn) THEN LOW LED ELSE ' LED Off HIGH LED ENDIF ELSE LOW SC ' Hold Low for 1 msec before PAUSE 1 ' Shifting in DATA SHIFTOUT SD, SC, LSBFIRST, [RobotData] HIGH SC ENDIF RETURN RobotSendReceive: ' Send the Byte in "RobotData" LOW SC ' Hold Low for 1 msec before PAUSE 1 ' Shifting in Data SHIFTOUT SD, SC, LSBFIRST, [RobotData] PAUSE 1 ' Wait for Operation to Complete SHIFTIN SD, SC, LSBPOST, [RobotData] HIGH SC RETURN
Robot No Start This application sends a “RobotStop” command and Flashes the Sumo-Bot’s LED to prevent the robot from moving when it is first turned on. This application does not affect the operation of the remote control and should be used when developing interfacing applications. ' Robot No Start ' ' This application causes the robot to Flash the LED Once ' and Just Sit There ' ' ' Author: Myke Predko ' ' Date: 04.10.28 ' ' '{$STAMP BS2} '{$PBASIC 2.5}
'
Variables
'
Mainline HIGH SC HIGH SD HIGH LED
' '
Set the I/O Bits As O/P and High
HIGH TC HIGH TD
'
High Tag I/O
PAUSE 100 RobotData = RobotStop GOSUB RobotSend
' '
Wait for Power Up Stop Robot From Moving...
Page 17 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
PAUSE 100 RobotData = RobotLEDOn GOSUB RobotSend PAUSE 500 RobotData = RobotLEDOff GOSUB RobotSend DO LOOP **
'
'
Flash the LED
Finished, Loop Forever
IR Tag/Sumo-Bot Interface Code Deleted – See Tag Template
Light Show This application randomly flashes the various LEDs on the Sumo-Bot with the IR Tag PIC ‘505 and associated LEDs added to it. ' Light Show ' ' Cycle through the Different LED Combinations on the Robot/Hardware ' ' ' Myke Predko ' ' '{$STAMP BS2} '{$PBASIC 2.5}
'
Variables
'
Mainline HIGH SC HIGH SD HIGH LED
' '
Set the I/O Bits As O/P and High
HIGH TC HIGH TD
'
High Tag I/O
PAUSE 100 RobotData = RobotStop GOSUB RobotSend
' '
Wait for Robot to Get Setup Stop Random Movement
'
Turn Off Cycling LEDs
' '
Wait for Robot to Get Setup Flash LED
'
Repeat Forever
PAUSE 100 RobotData = TagWhiteOff ' GOSUB TagSend PAUSE 100 RobotData = RobotLEDOn GOSUB RobotSend PAUSE 500 RobotData = RobotLEDOff GOSUB RobotSend PAUSE 300 DO
Page 18 of 21
Stop
myke predko
Stage 3 – Interfacing Workshop Handout
PAUSE 400 RobotData = TagIndOn ' GOSUB TagSend PAUSE 250 RobotData = TagLeftWhite GOSUB TagSend PAUSE 250 RobotData = TagRightWhite GOSUB TagSend PAUSE 250 RobotData = TagRearWhite GOSUB TagSend PAUSE 250 RobotData = TagIndOn GOSUB TagSend PAUSE 250 RobotData = TagWhiteCycle GOSUB TagSend PAUSE 400 RobotData = RobotLEDOn GOSUB RobotSend PAUSE 400 RobotData = TagIndOff GOSUB TagSend PAUSE 400 RobotData = RobotLEDOff GOSUB RobotSend PAUSE 400
Indicator On
LOOP **
IR Tag/Sumo-Bot Interface Code Deleted – See Tag Template
Max 5 Tournament This is the basic IR-Tag application for the Sumo-Bot. The robot is initially stopped and the IR Tag PIC16F505 is set to allow a maximum of five hits. During operation, the remote control can be used to move the robot and fire the IR Cannon. At the end of a competition, the loosing robot can have its counter cleared by pressing the three bar (“|||”) button on the remote control. ' Max 5 Tournament ' ' Basic Tournament - Stop When Hit 5x ' ' Button 1 (|) = Send "Fire" Command to PIC ' Button 3 (|||) = Reset the Hit Counter ' ' ' Myke Predko ' ' '{$STAMP BS2} '{$PBASIC 2.5}
' Variables oldButton VAR Byte
Page 19 of 21
'
Save the Button Value
myke predko
Stage 3 – Interfacing Workshop Handout
'
Mainline HIGH SC HIGH SD HIGH LED
' '
Set the I/O Bits As O/P and High
HIGH TC HIGH TD
'
High Tag I/O
PAUSE 100 RobotData = RobotStop GOSUB RobotSend
' '
Wait for Robot to Get Setup Stop Random Movement
PAUSE 100 RobotData = RobotLEDOn GOSUB RobotSend PAUSE 500 RobotData = RobotLEDOff GOSUB RobotSend
' '
Wait for Robot to Get Setup Flash LED
'
Maximum 5 Hits
'
Make Sure Cycling
PAUSE 100 RobotData = TagMaxHit5 GOSUB TagSend PAUSE 100 RobotData = TagWhiteCycle GOSUB TagSend PAUSE 100 DO
' Wait for "Fire" Button RobotData = RobotButton ' Any Buttons There? GOSUB RobotSendReceive oldButton = RobotData IF (RobotData = 1) THEN ' Fire/Flash LED RobotData = RobotLEDOn GOSUB RobotSend RobotData = TagFire GOSUB TagSend ' Send a "Fire" Command PAUSE 500 RobotData = RobotLEDOff GOSUB RobotSend ENDIF PAUSE 100 RobotData = TagGetHitNum GOSUB TagSendReceive IF (RobotData = 5) AND (oldButton = 3) THEN RobotData = TagHitClear GOSUB TagSend PAUSE 100 ' Lost, Restart Contest RobotData = TagWhiteCycle GOSUB TagSend ENDIF PAUSE 100 ' Don't Saturate Robot '505
LOOP **
IR Tag/Sumo-Bot Interface Code Deleted – See Tag Template
Page 20 of 21
myke predko
Stage 3 – Interfacing Workshop Handout
Appendix C – PBASIC Reference The following synopsis of the BS2 and the PBASIC programming language was taken from “123 Robotics Experiments for the Evil Genius”.
Page 21 of 21
myke predko
335
SIN
ATN
VSS
P0-P15
Vdd
2
3
4
5-20
21
VSS
VIN
23
24
Unregulated power in the range of 5.5 to 15 volts.
BS2 ground. Same as pin 4.
Pulled-up, negative active reset pin.
Regulated 5 volts. If external power source on VIN, then 5 volts out (up to 90 mA). Can have 5 volts applied to drive
General-purpose I/O pins.
BS2 ground. Same as pin 23.
RS-232 attention pin. Connected to host PC DTR line (DB9 pin 4).
RS-232 serial input to BS2. Serial pin 16.
RS-232 serial output from BS2. Serial pin 16.
Courtesy of Parallax, Inc. of Rocklin, CA (http://www.parallax.com).
RES
22
BS2.
SOUT
1
Eight-bit value passed to P8—P15. Single bit to set the output value of P#. Sixteen-bit word used to set the I/O state of P0—P15. “1” written to an I/O pin will put it into “output mode.” “0” written to an I/O pin will put it in “input mode.” Eight-bit value setting I/O state of P0—P7. Eight-bit value setting I/O state of P8—P15. Single-bit value setting I/O state of P#. Sixteen-bit variable (W0 to W12 available). Eight-bit variable (B0 to B25 available). Note that the space used for 8-bit variables is shared with space used for 16-bit variables. Divide the # in B# by 2 and round down to determine which 16-bit variable the 8-bit variable is located in.
OUT# DIRS
DIRL DIRH DIR# W# B#
Eight-bit value passed to P0—P7.
Sixteen-bit word used to set the output values of P—P15.
Single-bit value returned for P#.
OUTH
OUTL
OUTS
IN#
INH
Function
Eight-bit value returned from P8—P15.
INL
Name
Eight-bit value returned from P0—P7.
INS
Onboard Regulator Output: 5 V /-5 percent, 50 mA from a 12-volt source, and 150 mA from a 7.5-volt source
Pin
Sixteen-bit word that returns the value of P0—P15.
Name
Function
PBASIC Built-in I/O Port Labels
Pin Current Parameters: Source 20 mA, sink 25 mA (typically)
Current Supply:
Current Draw: 8 mA running, 100 uA sleep
Speed: Approximately 4,000 statements per second
Number of I/O Pins: 16 2 dedicated RS-232 lines '{$STAMP BS2} '{$PBASIC 2.5}
The following statements must be in place before any application code statements. Both statements must be used to take advantage of all the built-in PBASIC functions:
Memory Size: 2K electrically erasable programmable read-only memory (EEPROM), 26 bytes of variable RAM
Programming Language: PBASIC
PBASIC Header Statements
BS2 Specifications
PBASIC Reference
336
Decimal value
Hex value
Binary value
ASCII value returned
Nothing
$##
%## . . .
#
is used with # being the number of the pin being defined (from 0 to 15).
PinName Pin #
To define pins, the declaration statement
VariableName var Type(size)
Single-dimension arrays (numbered from 0 to size 1) are defined as
LED var OUTS.bit0
Type can also be another variable to share the space or can be subdivided into highbyte (or byte1), lowbyte (or byte0), highnib (or nib3 or nib1 depending on the variable type), lownib (or nib0), and bit# (as well as highbit and lowbit). For example, an LED on Output pinp can be defined as
where Type can be bit, nib (four bits), byte, and word (16 bits).
VariableName var Type
Variables can be given names and space dynamically within the application using the declare statement:
Data Type
Modifier
Constant values can consist of other values manipulated with mathematical operators or constants with their type modifiers consisting of the following: COS A
n
Y
A/B
Y Y
AB
Y
n
-A
A-B
A */ B
Y
Y
A B
n
Y
A B
A ** B
Y
A
A*B
Y
A&B
n
Y
A // B
Y
A|B
A REV B A^B
n n
A DIG B
n
A MIN B A MAX B
n
n
NCD A
DCD A
n
n
ABS A
SIN A
n n
SQR A
Constant
Symbol/Format
Adds A to B.
Returns negative A.
Subtracts B from A.
Multiplies A by B and return the middle 16 bits of the 32-bit result.
Multiplies A by B and return high 16 bits of 32bit result.
Multiplies A by B.
Returns the remainder of A divided by B.
Divides A by B.
Shifts A left B bits.
Shifts A right B bits.
Returns the bitwise complement of A.
Bitwise AND A and B.
Bitwise OR A and B.
Bitwise XOR A and B.
Reverses B bits (starting at LSB) of A.
Returns digit B from decimal number A.
Returns largest value.
Returns smallest value.
Priority encode of 16-bit value (NCD 12 8).
2**n power decoder (DCD 4 %0000000000010000).
Returns 16-bit sine value for 8-bit angle A.
Returns 16-bit cosine value for 8-bit (0 to 255) angle A.
Returns absolute value of A.
Returns square root of A.
Function
The following table lists the operators available in PBASIC. The operators only available for use in constant declarations are indicated in the Constant column.
Constant values are defined using the statement format:
ConstantName con value
Arithmetic Operators
PBASIC Constant, Variable, and Pin Declarations
337
Displays “Symbol #” and carriage return. Can be combined with other formatters to display data in different formats (such as hex ? hexVariable).
Displays “Symbol ‘#’” and carriage return where # is the ASCII representation for the symbol.
Decimal display. The number of digits is displayed optionally specified.
Signed decimal display. The number of digits displayed optionally is specified.
Hexadecimal display. The number of digits displayed is optionally specified.
Signed hexadecimal display. The number of digits displayed optionally specified.
Indicates (with proceeding $ character) hexadecimal display. Number of digits displayed is optionally specified.
Indicates (with proceeding $ character) signed hexadecimal display. Number of digits displayed is optionally specified.
Binary display. The number of digits displayed is optionally specified.
Signed binary display. The number of digits displayed is specified.
Indicates (with proceeding % character) signed binary display. The number of digits displayed is optionally specified.
Indicates (with proceeding % character) signed binary display. The number of digits displayed is optionally specified.
Displays ASCII string in array until NUL ($00) character is encountered or an optionally specified number of characters is displayed.
Displays the specified ASCII character # times.
?
ASC ?
DEC{1 . . . 5}
SDEC{1 . . . 5}
HEX{1 . . . 4}
SHEX{1 . . . 4}
IHEX{1 . . . 4}
ISHEX{1 . . . 4}
BIN{1 . . . 16}
SBIN{1 . . . 16}
IBIN{1 . . . 16}
ISBIN{1 . . . 16}
STR bytearray{\#}
REP byte\#
For display control with the debug statement, the special control characters listed in the following table are used. For special control characters, use “rep #\1” where # is the ASCII value listed in the table.
Function
Formatter
Output strings are specified within double quotes, and numeric and ASCII data can be displayed by using the formatters listed in the following table. Multiple data (with optional formatters) can be output from one statement by separating them with commas.
Debug and Serout Data Formatter Commands
bell
Carriage Return
Clear Down
cr
13
12
11
Clear Right
9 10
tab Line Feed
Tab
8
7
Bell
bksp
6
Cursor Down
Backspace
5
4
Cursor Right
Cursor Up
3
2
1
0
ASCII
Cursor Left
Move to (x,y)
home
cls
Clear Screen
Home
Symbol
Special Control Characters
Moves cursor to the start of the next line in Debug Terminal. In other devices, the cursor may be returned to the start of the current line and a line feed character will be needed to move to the next line.
Clears the Debug Terminal below the cursor.
Clears the line to the right of the cursor.
Moves the cursor down one line.
Moves cursor to the next tab column.
Deletes character to the left of cursor and moves the cursor to its position.
Beeps the PC’s speaker.
Moves cursor one row down.
Moves cursor one row up.
Moves cursor one column to the right in Debug Terminal.
Moves cursor one column to the left in Debug Terminal.
Moves cursor to specified location on Debug Terminal. Must be followed by two values (x and then y).
Places cursor in home position (top left of Debug Terminal).
Clears screen and places cursor at home position of Debug Terminal.
Function
When using the special control characters with “serout,” just bell, bksp, tab, Line Feed, and cr are recommended as these will be supported by different ASCII terminal devices.
338
Serout only. Reset with data driven out. Set (add 32,768) with open drain output.
Reset with data not inverted. Set (add 16,384) with data inverted.
Reset with data in the 8-N-1 format (eight data bits, no parity, one stop bit). Set (add 8,192) with data in the seven-bit format with even parity.
Data rate defined using the formula Bits 11—0 INT (1,000,000/desired baud rate) 20.
15
14
13
11—0
Assigns a variable the result of a single arithmetic operation. If multiple operations are specified in the statement, they are executed from left to right. The order of operations in a multiple-operator assignment statement can be “forced” by enclosing higherpriority operations within parentheses.
'
ABC
end
stop
do . . . loop
do while condition . . . loop
Comment
Assignment
Stop BS2
Stop BS2
Loop code
Loop while
Repeats the code between the do and loop statements while condition is true.
Executes the code between do and loop repeatedly. Can exit using a goto or exit statement.
Stops the BS2 without placing the BS2 in a lowpower mode.
Stops the BS2 from executing any more code. BS2 goes into a low-power mode.
Everything to the right of a single quote (') is ignored.
Example
Statement
Comments/Parameters
In the following table, braces ({ and }) indicate optional parameters and “ . . . “ indicates that parameters can be repeated.
PBASIC Functions and Statements
Function
Bits
The Baudmode value is defined using the following bits:
Serin and Serout Baudmode Bit Value Definitions
Label:
Address Label
Execute code according to data value:
Execution branch
Repeat code
Conditionally jump
If the condition is true, then execute the statements immediately following the if statement. If the condition is false, execute the statements following the else statement. Else and the statements following it are optional.
case condition ... case condition ... case else ...
select expression
Goes to Address# for a branch value of #.
Loads Variable with the InitialValue and executes code to the next statement. At the next statement, increment Variable either by 1 or Step Value if it is defined. When Variable is greater than StopValue, execute the first statement after next.
for Variable InitialValue to StopValue {step StepValue} . . . next branch Offset, [Address0, Address1, . . . ]
The test condition is in the format “A cond B” where cond is (equals), (not equals), (less than), (less than or equal to), (greater than), or (greater than or equal to). A and B can be variables, constants, or expressions. Parentheses are allowed in this statement. Logical operators (AND, OR, and NOT) can be used to combine multiple condition expressions.
if condition then Label
if condition then . . . else . . . endif
Conditionally execute multiple statements
Returns to statement after gosub Label statement.
Executes instructions after Label: statement until a return statement is encountered.
If condition is true, it executes the first statement. If condition is false, it executes the statement after “else.” “Else” and the statement that follows it are optional. Multiple statements can be executed if the condition is true or false if they are separated by a colon (:).
return
gosub Label
Changes execution to continue after Label: statement.
Specific address within application.
Repeats the code between the do condition and loop statements until the condition is true.
Comments/Parameters
Conditionally if condition then execute statement else statement
Return from subroutine
Jump to subroutine
goto Label
do . . . loop until condition
Loop until
Jump to Label
Example
Statement
339
count Pin, Interval, Counter
debug {formatter} Data/String/ Constant, . . .
dtmf Pin, {on Time, offTime,} [tone{, . . . }]
freqout Pin, Period, Freq1 {, Freq2}
high Pin
Count pulses
Return status
Touch-tone output
Output frequency
High on Pin
Pin will be changed to output and a high voltage will be output from it.
Outputs Freq1 on Pin for the specified Period (in msecs). If Freq2 is specified, it will be mixed with Freq1. Freq1 and Freq2 are specified in Hz and the maximum value is 32,767 Hz.
Generates a touch-tone phone. onTime and offTime are optional values, setting the length for the tone in msecs. Tone is the touch-tone button to send data. If onTime and offTime are not specified, the BS2 defaults to 200 msecs and 50 msecs, respectively.
Returns a string of data to the host PC in the Debug Terminal after BS2 programming to indicate what is happening in the application. Note that if no formatter exists, variable values are printed in decimals. The different formatters available are listed and explained in the previous table along with the special control characters that can be used to control the operation of the Debug Terminal.
Delays 1 msec times the number of Interval and counts the number of times Pin is pulsed. The result is saved in Counter.
Polls Pin and increments the byte variable Workspace if Pin is in a downstate each time the Button statement is encountered. It jumps to Address if the number of times specified by Delay is equal to the current value of Workspace and the TargetState is met. If the button is released, Workspace is reset. If Delay is equal to 0, no debounce or autorepeat takes place. If Delay is equal to 255, debounce is performed, but with no autorepeat. Autorepeat is executed if the Button statement is executed with Delay plus Rate * n times (and Delay does not equal 0 or 255).
Executes according to the value of the expression. Condition consists of a constant value with an optional comparison operator (, , , , or ) and executes the code following the case statement if the condition is true. Case else is for expression values that do not match any of the set conditions.
endselect
button Pin, Downstate, Delay, Rate, Workspace, TargetState, Address
Comments/Parameters
Example
Button debounce
Statement
pulsout Pin, Period pwm Pin, Duty, Cycles
PWM output
pulsin Pin, State, Variable
Measure pulse
Drive out pulse
sleep Value
Power down
pause Value
lookdown Target, {ComparisonOp}, [value0, value1{, . . . }], Variable
Find list value
Power down
toggle Pin
Change Pin value
nap Value
reverse Pin
Change Pin mode
Power down
output Pin
Pin “output”
lookup Index, [value0, value1{, . . . }], Variable
input Pin
Pin “input”
Find list offset
low Pin
Example
Low on Pin
Statement
(continued)
Drives out a pulse width modulation (PWM) cycle on the specified Pin for the Cycles’ number of times. The PWM period is 255 msecs, with the Duty being the number of msecs, and the PWM output is active high.
Pulses Pin for the specified Period times 2 usecs.
Waits for Pin to be at the specified State and times how long it is at this state. It then returns the time (in 2-usec increments) in Variable.
Power down for Value times 2.3 seconds.
Stops for the number of msecs specified by Value. This mode does not save as much power as nap or sleep.
Power down for Value length of time where, if Value is 0, the nap time is 18 msecs. It is 36 msecs for a Value of 1, 72 msecs for 2, 144 msecs for 3, 288 msecs for 4, 576 for 5, 1.15 secs for 6, and 2.30 secs for 7. Note that actual delays can be different by as much as 50 percent.
Returns the Index value from the list in Variable. Note that the values can be a string enclosed in double quotes.
Returns the offset of Target in the list of values in Variable. Note that values can be a string enclosed in double quotes. ComparisonOp is an optional conditional operator for specifying how the search is to be done (equals [] is the default).
The output value for Pin is complemented.
Pin changes between input and output modes.
Pin mode is changed to an output.
Pin mode is changed to an input.
Pin will be changed to output and a low voltage will be output from it.
Comments/Parameters
340
write Location, {word} Value
Write EEPROM
serin Pin {\Ffpin}, Baudmode, ={Plabel,} {Timeout, Tlabel,} [InputData]
data {@Starting Address,} Value{, “string”}
Preload EEPROM
Serial input
rctime, Pin, State, Variable
Measure RC
read Location, {word} Variable
random Variable
Get random value
Read from EEPROM
Example
Statement
Gets serial input data from I/O pin. Note that Pin 16 is the programming serial port. fpin is the flow control output pin (indicating if data can be received). Baudmode has been defined previously. The Plabel and Tlabel jumps to addresses on error (parity and timeout, respectively) are optional. If the Tlabel option is used, then the Timeout interval (units are msecs) and the flow control pin (fpin) must be specified. InputData consists of a destination variable along with formatting variable. If waiting for a numeric string of some kind, the DEC, HEX, or BIN filters are used along with the S or I prefixes, indicating that a signed value or integer, respectively, is required. Using the STR filter stores a string into an array until the number of specified characters has been received (using the \# parameter). A second \# parameter can be used to indicate a string-ending character. The WAIT(#[,# . . . ]) filter will not return any values until the specified values have been
Read the 8 bits in EEPROM at Location into Variable. The optional word parameter indicates that Value is 16 bits instead of the default 8 bits.
Writes a byte value at the specified location in EEPROM memory. Location can be any value from 0 to 2,047. To ensure application code is not overwritten, use the Ctrl-M command from BASIC Stamp Editor to check application locations. The optional word parameter indicates that Value is 16 bits instead of the default 8 bits.
Saves the specified value or string in EEPROM at the first available address. The starting address can be specified by placing an integer value proceeded by a @ character before the data that is to be saved.
Measures the charge/discharge time (specified by State) and saves the result in Variable, which is required for an RC network on a Pin. The recommended method of using this circuit is to place a capacitor at Vdd with the resistor grounded at the other end and use a State of 1. The discharge time returned is in 2 usec units.
Returns a 16-bit pseudo-random number in Variable.
Comments/Parameters
Shift data out
shiftout Dpin, Cpin, Mode, [OutputData {/Bits} {, . . . }]
shiftin Dpin, Cpin, Mode, [Variable {\Bits} {, . . . }]
XOUT Mpin, Zpin, [House/ Command {\Cycles} {, . . . }]
X-10 output
Shift data in
serout Pin {\Ffpin}, Baudmode, {Pace,} {Timeout, Tlabel,} [Data}
Example
Serial output
Statement
Synchronous shift of data out on Data and Clock pins. The Mode values are LSBFIRST (value 0 is the least significant bit first) and MSBFIRST (value 1 is the most significant bit first). Data is taken from OutputData and can have a set number of bits shifted out (eight is the default). The clock is high for 14 usecs and low for 46 usecs with data available 14 usecs before the clock goes high.
Synchronous shift of data on Data and Clock pins. The Mode values are MSBPRE (value 0 is the most significant bit first and sample before clock), LSBPRE (value 1 is the least significant bit first and sample before clock), MSBPOST (value 2 is the most significant bit first and sample after clock), and LSBPOST (value 3 is the least significant bit first and sample after clock). Data is shifted into the specified variable with an optional number of bits (the default is eight). The clock is high for 14 usecs and low for 46 usecs.
Output X-10 outputs to other devices. Mpin is the modulation source pin to the power-line interface device. Zpin is the zero-crossing signal from the power-line interface device. House is the X-10 “house code” and Command is the command to send. Cycles is the number of times the House and Command values are to be sent.
Outputs serial data onto the specified pin. fpin is an optional pin used for flow control. Baudmode has been defined earlier. Pace is the time between byte outputs and is in the units of msecs. Timeout and Tlabel operate exactly the same way as serin. Data and its optional formatting options are identical to the ones used with debug and are listed in the previous table.
received first. WAITSTR will wait for a series of bytes to match the contents of a specified array (which can be limited to \# characters). Finally, using SKIP #, a set number of characters can be ignored before reading the input data.
Comments/Parameters