Shop OBEX P1 Docs P2 Docs Learn Events
would love help from anyone? — Parallax Forums

would love help from anyone?

michaelmonsomichaelmonso Posts: 19
edited 2011-08-24 09:33 in General Discussion
im trying to convert the following code from running a servo, to turning a pin on for a second to trigger a relay that would trigger my gate. the idea is being used from this guys video and code for his sms servo based door opener

http://www.youtube.com/embed/eexlYrESdP8

I want to do the same sms opening but that's a later battle.

his code operates the servo currently but i want to have it turn the pin high for a second and then go low so that the gate is tricked into thinking someone pushed the manual open control button and proceeds to run its course.

i have other questions but i want to address them one at a time. this one is how to change the servo from being controlled to just the pin 24 toggled on then off after a second in the same places the servo would be opperated

his sms function uses www.twilio.com so when he send an "o" it will open and respond to him that its "opening" same for "c" close and respond "closing" i would also need an "L" for locked so i could control stopping the gate at what ever position its is in at the time of opening or closing. this is because there is a open/close/lock manual button at the gate that im trying to manipulate through the parallax spinneret
'
' NOTICE: Change the value for SetMAC, SetGetway, SetSubnet, and SetIP to match your network!!!
'
' Show how to get data from a form using the "GET" method
' Your inputs must be named "0" thru "9" for example
'   Name: <INPUT NAME="0"><BR>
'   City: <INPUT NAME="1"><BR>
'
'  VarExists[0] will be 1 if input "0" was sent otherwise it will be zero (same for "1" thru "9")
'  VarStr[0] will be a pointer to the string entered for the input (same for "1" thru "9")
'  Unchecked checkboxes do NOT return the input, checked checkboxes return the string "on"
'
' The variable VarFilename is a pointer to the filename specified in the URL (without the "/" prefix)
'
' If you have more than 10 inputs, you should probably be using the POST method
'
CON
  _clkmode = xtal1 + pll16x     'Use the PLL to multiple the external clock by 16
  _xinfreq = 5_000_000          'An external clock of 5MHz. is used (80MHz. operation)

  ServoCh1 = 24                                        'Pin that the servo is on

CON
  CR            = 13
  LF            = 10
  QUOTE         = 34
  _bytebuffersize = 2048


VAR

  'Configuration variables for the W5100
  byte  MAC[6]                  '6 element array contianing MAC or source hardware address ex. "02:00:00:01:23:45"
  byte  Gateway[4]              '4 element array containing gateway address ex. "192.168.0.1"
  byte  Subnet[4]               '4 element array contianing subnet mask ex. "255.255.255.0"
  byte  IP[4]                   '4 element array containing IP address ex. "192.168.0.13"
  long  localSocket             '1 element for the socket number

  'Variables to info for where to return the data to
  byte  destIP[4]               '4 element array containing IP address ex. "192.168.0.16"
  long  destSocket              '1 element for the socket number

  'Misc variables
  byte  data[_bytebuffersize]


  ' Get variables 0 thru 9
  long VarFilename ' pointer to string
  byte VarExists[10]
  long VarStr[10]   ' pointer to string 

  ' Status of the door
  byte status
OBJ
  ETHERNET      : "Brilldea_W5100_Indirect_Driver_Ver006.spin"
  ''SERVO        : "Servo32v7.spin"
  PST           : "Parallax Serial Terminal.spin"

PUB main 

  'Set up the servo, set it to neutral

   ''SERVO.Start
   ''SERVO.Ramp
   ''SERVO.SetRamp(ServoCh1,1500,200)

   PST.Start(115_200)

  'Start the W5100 driver on Parallax Web Server module
  ETHERNET.StartINDIRECT(0, 8, 9, 12, 11, 10, 14, 15)

  SetMAC($00, $08, $DC, $16, $F2, $04) ' !!! CHANGE TO MATCH YOUR NETWORK !!!
  SetGateway(162, 228, 0, 1)           ' !!! CHANGE TO MATCH YOUR NETWORK !!!
  SetSubnet(255, 255, 255, 0)          ' !!! CHANGE TO MATCH YOUR NETWORK !!!
  SetIP(162, 228, 0, 120)              ' !!! CHANGE TO MATCH YOUR NETWORK !!!

  localSocket := 80 
  destSocket := 80  

  ETHERNET.SocketOpen(0, ETHERNET#_TCPPROTO, localSocket, destSocket, @destIP[0])
  ETHERNET.SocketTCPlisten(0)

  repeat
    if !ETHERNET.SocketTCPestablished(0)
      if ETHERNET.SocketStatus(0) == $00 OR ETHERNET.SocketStatus(0) == $1C
        ResetSocket
      'PST.Str(string("blah"))
      ' next
    else
      bytefill(@data, 0, _bytebuffersize)
      WaitCnt(clkfreq / 100 + cnt) ' 10mSec
      ETHERNET.rxTCP(0, @data)

      if data[0] == "G" ' Assume a GET request
        ParseURL

        'Send the web page - hardcoded here
        'status line
        StringSend(0, string("HTTP/1.1 200 OK", CR, LF))
       
        'optional header
        StringSend(0, string("Server: Parallax Spinneret Web Server", CR))
        StringSend(0, string("Connection: close", CR))
        StringSend(0, string("Content-Type: text/html", CR, LF))

        StringSend(0, string(CR, LF))

        if (byte[VarStr[1]] <> 0)
          if (byte[VarStr[1]] == "o")
            status := "1"
            StringSend(0, string("opening", CR))
            ''SERVO.SetRamp(ServoCh1,500,200)
          elseif (byte[VarStr[1]] == "c")
            status := "0"
            StringSend(0, string("closing", CR))
            ''SERVO.SetRamp(ServoCh1,2300,200)
        elseif (status == "1")
          StringSend(0, string("open", CR))
        elseif (status == "0")
          StringSend(0, string("closed", CR))

        StringSend(0, string(CR, LF))

      ResetSocket

  return 'end of main
  
PRI ResetSocket
  ETHERNET.SocketTCPdisconnect(0)
  ETHERNET.SocketClose(0)
  ETHERNET.SocketOpen(0, ETHERNET#_TCPPROTO, localSocket, destSocket, @destIP[0])
  ETHERNET.SocketTCPlisten(0)
  return

PRI SetMAC(p0, p1, p2, p3, p4, p5)
  MAC[0] := p0
  MAC[1] := p1
  MAC[2] := p2
  MAC[3] := p3
  MAC[4] := p4
  MAC[5] := p5
  ETHERNET.WriteMACaddress(true, @MAC[0])
   return 'end of SetMAC


PRI SetGateway(p0, p1, p2, p3)
  Gateway[0] := p0
  Gateway[1] := p1
  Gateway[2] := p2
  Gateway[3] := p3
  ETHERNET.WriteGatewayAddress(true, @Gateway[0])
  return 'end of SetGateway


PRI SetSubnet(p0, p1, p2, p3)
  Subnet[0] := p0
  Subnet[1] := p1
  Subnet[2] := p2
  Subnet[3] := p3
  ETHERNET.WriteSubnetMask(true, @SubNet[0])
  return 'end of SetSubnet


PRI SetIP(p0, p1, p2, p3)
  IP[0] := p0
  IP[1] := p1
  IP[2] := p2
  IP[3] := p3
  ETHERNET.WriteIPAddress(true, @IP[0])
  return 'end of SetIP


PRI StringSend(_socket, _dataPtr)
  if byte[_dataPtr] <> 0
    ETHERNET.txTCP(_socket, _dataPtr, strsize(_dataPtr))
  return 'end of StringSend


PRI ParseURL | char, inPlace, outPlace  ' !!! NOTICE - THIS MODIFIES data[] !!! 
  inPlace := 4 ' skip "GET "
  VarFileName := @data[5] ' Skip "GET /"
  
  repeat char from 0 to 9
    VarExists[char] := 0
    VarStr[char] := @EmptyStr

  repeat until (char == "?") or (char == " ")
    char := data[inPlace++]

  data[inPlace-1] := 0 ' String terminator for filename string
  outPlace := inPlace

  if char == "?"
    repeat until char == " "
      char := data[inPlace]
      if (char =< "9") and (char => "0")
        char := char - 48
        VarExists[char] := 1
        inPlace+=2 ' skip "x="
        VarStr[char] := @data[outPlace]   
        char := data[inPlace]
        if (char <> "&") and (char <> " ")
          data[outPlace++] := char
      repeat until (char == "&") or (char == " ")
        inPlace++
        char := data[inPlace]
        if (char <> "&") and (char <> " ")
          if char == "%"
            inPlace++
            char := data[inPlace++] - 48
            if char > 9
              char-=7
            char := char << 4
            data[outPlace]:=char
            char := data[inPlace] - 48
            if char > 9
              char-=7
            data[outPlace++]+=char
            char := "x" 
          else
            if char == "+"
              data[outPlace++] := " "
            else
              data[outPlace++] := char  
      data[outPlace++] := 0 ' String terminator
      inPlace++  
  return
  
DAT
  EmptyStr BYTE 0

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-08-23 10:51
    Since the code is for the propeller that would be a more appropriate forum to post in. You would help if you could tell us how you have things connected and what pin you want to operate the solinoid. Also what you have tried so far and how it works.
  • michaelmonsomichaelmonso Posts: 19
    edited 2011-08-23 12:15
    i have a wire connected to ground on the spinneret and a second to pin 24 those wires are connected to a low voltage relay that bridges the two output wires that would be hooked up to the gate (currently hooked up to meter to check connectivity) that would be for gate open when pin 24 goes high then i would need it to go low after about a second so that the gate operators brain can run its own hardware.
    in addition to open i would need to change it to have a close button and a stop button.the open and close buttons would default low in the code and the stop would default high high because the manual pushbuttons controls would reflect the same open/close N.O. and stop N.C.

    in his code i replaced the servo handlers that i wouldnt be using with this.
    where it says PIN24.toggle used to say servo.start blah blah, and PIN25.toggle the same servo.start. because he used servos and i just want to light an led for a second basically.
            if (byte[VarStr[1]] <> 0)
              if (byte[VarStr[1]] == "o")
                status := "1"
                StringSend(0, string("opening", CR))
                 PIN24.Toggle
              elseif (byte[VarStr[1]] == "c")
                status := "0"
                StringSend(0, string("closing", CR))
                PIN25.Toggle
            elseif (status == "1")
              StringSend(0, string("open", CR))
            elseif (status == "0")
    

    So i put the PIN.24.toggle which runs the object below and i think it would work but im not sure.
    CON
      Pin   = 24                           
      Delay = 16_000_000
     
    PUB Toggle
      dira[Pin]~~
      !outa[Pin]
      waitcnt(Delay + cnt)
    

    so....my guess is that would work and the same for PIN25.toggle and i would have to modify the code to allow a third option of PIN26.toggle (for stop)



    im currently trying to figure out how he interfaced his code with the text message. he used Twilio.com to handle it so you text message the number you get from the site, it responds to im guessing some .php files i put on sd card that relays it to spinneret opening closing or stopping the gate as well as responding back to original text message with the status of the gate ie open, closed, locked, opening, closing......

    i think my code may work, maybe not the correct way to do it but work still. but now i need to figure out the sms headache to even test it....

    the lastthing is when im using the spinneret im using my cable modem IP and i think that is causing alot of issues because its not a Domain Name.
  • FranklinFranklin Posts: 4,747
    edited 2011-08-23 15:13
    I think a safer way to do this is to explicitly set the pin high of low in code. If you toggle the pin and the pin state gets out of sync you have no way of knowing.
  • michaelmonsomichaelmonso Posts: 19
    edited 2011-08-23 17:04
    well im completely new to this. so how would i go about replacing PIN24.toggle in the code to explicitly setting it high for a set amount of time then returning it to low afterwards?
  • Ray0665Ray0665 Posts: 231
    edited 2011-08-24 09:33
    Pub Toggle(Pin)
       dira[Pin]~~
       outa[Pin]~~   
       waitcnt(Delay + cnt)
       outa[pin]~
       waitcnt(Delay + cnt)
    
Sign In or Register to comment.