Examples | Shop
 
Siteplayer™ Serial Communication with the Parallax Basic Stamp2™ connected to a Devantech SRF04 Ultrasonic Range Finder. (Using the SitePlayer Development Kit)
 
This example demonstrates the ease in which serial data can be transmitted to the SitePlayer™ module. In this example, the Parallax Basic Stamp2™ is used as the controlling processor but other microcontrollers can be used similarly.

The example consists of seven separate documents that will interact with each other to create the application. Six of these can be extracted from a zip file that can be downloaded HERE. Whilst the seventh, the BS2 code is available at the bottom of this page.


SitePlayer™
Serial_Demo2.SPD is a file used by Sitelinker™ for the initial variables. Here the IP Address, Sitefile, Sitepath and Includes, amongst others, are stated.

The setting of the Sitefile and Sitepath in Serial_Demo.SPD determines the SitePlayer Binary file (SPB) and the path and file allocations for the documents in this application respectively.

If the current settings are used from Serial_Demo2.SPD, the files will be in the following allocations.

Sitefile “C:\Program Files\SitePlayer\Serial_Demo2.spb”
Sitepath “C:\Program Files\SitePlayer\TR Demo”

The file TR Demo contains the files:
“SerialIn.htm”, “SerialIn.SPI” and “SitePlayer_Logo.Gif”.

The .HTM file is the HTML web page. By changing settings in here, the websites appearance can be altered.

The .GIF file is called up by the Web page and is an image of the SitePlayer logo.

The .SPI (Serial Peripheral Interface) is a pointer for any external device link events that occur. In this application, when baud rate is selected, the same web page is loaded.

The files “Serial_Demo2.SPD”, “UDPsend_def.INC” and “pcadef_Serial.INC” are, in this application, allocated in “C:\Program Files\SitePlayer”.

The .INC files are used by the .SPD file to set up UDP and file allocations within SitePlayer itself. In the file “pcadef_Serial.INC”, comin0 is used as the file to receive serial data from the BS2. Com is the serial port output, and baud is the baud rate for serial communication. These are all used within the web page
.

Basic Stamp2™

The BS2™ is connected to the Devantech SRF04 Ultrasonic Range Finder as follows.

SRF04   BS2
INIT - P0
ECOH - P1
V+ - Vss
GND - GND

The serial connection between the Basic Stamp2 and SitePlayer is as follows.

SP   BS2
SEROUT - PC-TX (shown on siteplayer schematic in main SitePlayer documentation)
GND - GND

The Basic Stamp2 code should be copied into the Stamp compiler and downloaded to the Basic Stamp2. It will convert the SRF04 reading into centimetres and decide whether the reading is more or less than 100cm. Less and an Alarm signal is sent to the SitePlayer. More, and an all-clear signal is sent to the SitePlayer.

A debug window is set up to allow an understanding of what readings the SRF04 obtains and when data is sent to the SitePlayer.


SiteLinker™
Sitelinker is used to download the web files to the SitePlayer. When using Sitelinker, ensure that the BS2 is powered down so no serial communication will occur while the Sitelinker is downloading to SitePlayer.

In SiteLinker, Open “Serial_Demo2.SPD”. Now select “Download” then “Make and Download”.

The Sitelinker creates an .SPB file, which is downloaded to the SitePlayer.

Select Browser and load http://192.168.1.250/Serialin.htm. Power up BS2 and the application should be up and running.


 

'*************************************************************************'
'Description: This application demonstrates simple serial communication from 'the BS2 to
the Siteplayer.'

'An SRF04 ultra sonic range finder inputs readings into a BS2 which decides 'whether any
object is close enough for an alarm condition to be apparent. If it is, a serial out command
sends data to the siteplayer which in turn sets 'an alarm warning on its website.'

'If no alarm condition is apparent, an all-clear screen is displayed.'

'Created: 15/10/02 Revision 1.00
'Written By: TR Control Solutions (Jamie Finnan)
'TRCS-001
'Siteplayer is a Registered Trademark of Netmedia'
'*************************************************************************'
'{$STAMP BS2}sendata var byte(7) 'Set up a 7 byte Array
Dist var word
INIT con 0
ECHO con 1
convfac con 29 ' use centimeters
'*************************************************************************'
main:
gosub sonar
debug dec Dist, cr
pause 200

if Dist < 100 then Alarm_State
if Dist > 100 then All_Clear
goto main
'*************************************************************************'
sonar:
pulsout INIT,5 ' 10us init pulse
output INIT ' dummy command (delay)
rctime ECHO,1,Dist ' measure echo time
Dist=Dist/convfac ' convert to inches
pause 10
return'
*************************************************************************'
Alarm_State:
sendata(0) = "A"
sendata(1) = "L"
sendata(2) = "A"
sendata(3) = "R"
sendata(4) = "M"
sendata(5) = "!"
sendata(6) = "!"debug "Send data Alarm",cr
serout 6,16468,[$80,$00,sendata(0)]
serout 6,16468,[$80,$01,sendata(1)]
serout 6,16468,[$80,$02,sendata(2)]
serout 6,16468,[$80,$03,sendata(3)]
serout 6,16468,[$80,$04,sendata(4)]
serout 6,16468,[$80,$05,sendata(5)]
serout 6,16468,[$80,$06,sendata(6)]
pause 4000
return
'*************************************************************************'
All_Clear:
sendata(0) = " "
sendata(1) = "C"
sendata(2) = "L"
sendata(3) = "E"
sendata(4) = "A"
sendata(5) = "R"
sendata(6) = " "debug "Send data All Clear",cr
serout 6,16468,[$80,$00,sendata(0)]
serout 6,16468,[$80,$01,sendata(1)]
serout 6,16468,[$80,$02,sendata(2)]
serout 6,16468,[$80,$03,sendata(3)]
serout 6,16468,[$80,$04,sendata(4)]
serout 6,16468,[$80,$05,sendata(5)]
serout 6,16468,[$80,$06,sendata(6)]
pause 100
returnEnd
'*************************************************************************'


Examples | Shop