Shop OBEX P1 Docs P2 Docs Learn Events
BS2 with PINK — Parallax Forums

BS2 with PINK

wingclipperwingclipper Posts: 6
edited 2011-04-27 21:16 in BASIC Stamp
I am having trouble correlating variables from the webserver to use on the bs2 board..

example. i want to change the pause variable in a LED using the web variable of the pink server..

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-12 07:23
    Attach your code to a message using the Attachment Manager that you get when you click on "Go Advanced" when composing a reply.

    There is no correlation involved. The PINK simply provides variables that you can include in your webpage as shown in the examples. The BS2 can read and write these variables. If a variable contains a number, the BS2 can read the variable value as a numeric value as described in the chapter on SERIN in the Stamp Editor's help files. If you're using a PAUSE statement, the time can be any expression including variables.
  • wingclipperwingclipper Posts: 6
    edited 2011-04-19 06:35
    Thank you. Will update as soon as possible.
  • wingclipperwingclipper Posts: 6
    edited 2011-04-21 22:01
    Mike Green wrote: »
    Attach your code to a message using the Attachment Manager that you get when you click on "Go Advanced" when composing a reply.

    There is no correlation involved. The PINK simply provides variables that you can include in your webpage as shown in the examples. The BS2 can read and write these variables. If a variable contains a number, the BS2 can read the variable value as a numeric value as described in the chapter on SERIN in the Stamp Editor's help files. If you're using a PAUSE statement, the time can be any expression including variables.

    can't get teh LED to light...
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-22 07:03
    Look again at page 8 of the PINK documentation. You'll see that the 2nd parameter of the SERIN and SEROUT statements is not the Baud itself, but a code that includes information about the Baud and other stuff. Read the description of the SERIN and SEROUT statements in the Stamp Manual (in the help files of the Stamp Editor). First you have to get the value from the PINK. Your program should blink the LED if it gets the correct value. Remember that your program only reads the PINK value once when it first starts. Is that what you want?
  • jc3IIIjc3III Posts: 21
    edited 2011-04-22 11:05
    wingclipper and I are working on the same project. the LED is blinking, but we can't control how fast.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-22 11:33
    Are you getting the right number from the PINK? There's nothing wrong with your LED blink loop given that you supply the on/off time in milliseconds.
  • jc3IIIjc3III Posts: 21
    edited 2011-04-22 11:41
    This is the program.

    nbvar VAR Byte
    Baud CON 84

    TX PIN 13
    RX PIN 14

    SEROUT TX, Baud, ["!NB0R01"]
    SERIN RX, Baud, [nbvar]


    SEROUT TX, Baud, ["!NB0SI"]
    SERIN RX, Baud, [STR nbvar\11\CLS]

    SEROUT TX, Baud, ["!NB0W01:100 " , CLS]
    SEROUT TX, Baud, ["!NB0W02:", 150, CLS]
    SEROUT TX, Baud, ["!NB0W03:", nbvar, CLS]
    'PAUSE 500

    DEBUG nbvar
    DO
    HIGH 2
    PAUSE nbvar
    LOW 2
    PAUSE nbvar
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-22 12:09
    You don't seem to understand what you're doing with the SERIN and SEROUT statements. You might want to work through some of the exercises in the "What's a Microcontroller?" tutorial on these statements and go through the Stamp Manual chapters on the SERIN and SEROUT statements. Both manuals are in the help files of the Stamp Editor and are downloadable from Parallax. Particularly look at the description and examples of the "formatters" like DEC. When you output something like nbvar, you're outputting a single byte whose value is supplied by the value of nbvar. When you output something like DEC nbvar, you're outputting a sequence of ASCII digits that represent the value in nbvar. For a value like 1, you'll see the character "1". For a value like 240, you'll see the characters "2", "4", and "0".

    Like I said before, there's nothing wrong with the LED blink code. You just have to supply it with a valid value from the PINK.

    What's an "!NB0SI" command? I can't find it in the PINK documentation.
  • jc3IIIjc3III Posts: 21
    edited 2011-04-22 12:20
    Its the command to convert the pink var to a string
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-22 12:33
    I had an older PINK doc version. The "!NB0SI" command doesn't convert the PINK var to a string. It supplies the IP address of the PINK. It's hard to tell from the PINK documentation just what's provided by the PINK, but I suspect it's a string of the form "xxx.xxx.xxx.xxx".
  • wingclipperwingclipper Posts: 6
    edited 2011-04-26 10:54
    Im having an issue with the logic.

    IF the temperature is set to higher then the current temp, the red LED lit..


    'Thermostat with PINK 1.0
    'To remotely access a thermostat built on BS2 board with Pink Module

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    'Variables
    x VAR Byte ' General purpose variable, byte.
    degC VAR Byte ' Variable to hold degrees Celsius.
    degF VAR Byte ' Variable to hold degrees Fahrenheit
    settemp VAR Byte ' Variable to hold temperature set
    storedtemp VAR Byte ' Comparison Variable for temperature
    nbvar VAR Byte ' Variable to RX/TX PINK
    'Pin Assignments
    RX PIN 2 ' Serial Receieve Pin --> PINK.TX
    TX PIN 3 ' Serial Transmit Pin --> PINK.RX

    'Constants Assignments
    Baud CON 84 ' 9600 bps (BS2

    'Initializations

    SEROUT 12, 84, [12,22] 'Initialize LCD and clear LCD

    ' Note: DS1620 has been preprogrammed for mode 2.
    OUTS=%0000000000000000 ' Define the initial state of all pins,
    'FEDCBA9876543210
    DIRS=%0000000000000000 ' as low outputs.

    HIGH 6 ' Select the DS1620.
    SHIFTOUT 5, 7, LSBFIRST, [238] ' Send the "start conversions" command.
    LOW 6

    DEBUG "Initialization Finished",CR
    PAUSE 1000
    'DEBUG "Please set the temperature",CR
    'DEBUGIN DEC2 settemp
    'PAUSE 1000
    DEBUG CLS

    Main:
    DO

    GOSUB Push_Button
    GOSUB Get_Temperature



    LOOP

    Push_Button:
    IF IN11 = 1 THEN 'Monitor pushbutton for setting temperature
    settemp = settemp + 1
    ENDIF
    IF IN10 = 1 THEN
    settemp = settemp - 1
    ENDIF
    RETURN


    Get_Temperature:
    HIGH 6 ' Select the DS1620.
    SHIFTOUT 5, 7, LSBFIRST, [170] ' Send the "get data" command.
    SHIFTIN 5, 7, LSBPRE, [x] ' Get the data.
    LOW 6 ' End the command.
    degC = x / 2
    degF= degC*9/5 + 32 ' Convert the data to Fahrenheit.
    storedtemp = degF

    'Display Temperature on DEBUG,LCD, and transmit to website

    SEROUT 12, 84, [12,22] 'Intialize LCD and clear LCD

    SEROUT 12, 84, [128, DEC3 degC, " C*", 'Display Temperature on LCD
    134, "Temp is ",
    154, "set to:", DEC2 settemp, "F",
    148, DEC3 degF, " F*"]

    DEBUG HOME
    SEROUT TX, Baud, ["!NB0R00"] ' Send Command To Read Variable 01
    SERIN RX, Baud, 100, Timeout, [DEC nbvar] ' Get Data With Timeout
    DEBUG "Variable 00: ", DEC nbvar, CR ' Display Byte In Decimal
    settemp = nbvar

    IF settemp < storedtemp THEN
    HIGH 0
    LOW 1
    ENDIF

    IF settemp > storedtemp THEN
    LOW 0
    HIGH 1
    ENDIF

    IF settemp = storedtemp THEN 'Heat/Cold Programming
    LOW 0
    LOW 1
    ENDIF

    SEROUT TX, Baud, ["!NB0W00:", DEC settemp, CLS]
    SEROUT TX, Baud, ["!NB0W01:", DEC degF, CLS]
    SEROUT TX, Baud, ["!NB0W02:", DEC degC, CLS]








    DEBUG ? degC 'Display All Variables on DEBUG
    DEBUG ? degF
    DEBUG ? settemp
    DEBUG ? storedtemp
    DEBUG ? IN13
    DEBUG ? IN11
    DEBUG ? IN10
    DEBUG ? IN9
    DEBUG ? IN8
    PAUSE 250

    RETURN

    Timeout:
    DEBUG "Communication Timeout!" ' Serial Timeout
    END
  • wingclipperwingclipper Posts: 6
    edited 2011-04-27 21:16
    Thank you for your help. Ive learned a lot and finished my project. There is a ton of room for expansion but you have helped me grow!!
Sign In or Register to comment.