Wireless modules - help with code not working


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Congratulations on sorting it Dick.

    I'm having problems with my code which seems so simple but it won't work with serin/out2 qualifiers.

    I have commented out the Serin2 ACK in the control code as it doesn't get one due to the field code not working. This way, at least the code works the relay ok if I remove the Serin2 qualifier and just send "BOB".
    This points to the qualifiers as the culprit as without them the code works OK.

    I've tried every combination and it doesn't respond. All I want in the Field unit is to receive a qualifier to branch to the desired gosub.

    Please bear in mind code below is probably incorrect as it's what's left of trying.

    Control code

    Code:
    Include "modedefs.bas" 
    DEFINE OSC 10
    
    TRISA=%00000000
    TRISB=%11110000
    CMCON=7                  ; comparators off
    
    redled VAR PortB.4
    greenled VAR PortB.5
    yellowled VAR PortB.6
    switch VAR PortB.7
    
    redstop VAR BYTE
    greengo VAR BYTE
    flip VAR BYTE
    
    ;relay var PortA.1
    
    flip = 0         ; counter flipflop for single command send
    
    redstop = 1
    greengo = 2
    
    
    test:            ; test led outputs
          high redled
          pause 500
          low redled
          high greenled
          pause 500
          low greenled
          high yellowled
          pause 500
          low yellowled
          
          pause 2000
          
    main:
    
    IF SWITCH = 1 and flip = 0 THEN GOSUB red
        pause 500
    IF switch = 0 and flip = 1 then gosub green
    
    goto main
    
    red:
        pause 1
        SEROUT2 PortA.3,T9600,["BOB",redstop]       ; send command to field unit
        ;SERIN2 PortA.2,84,[WAIT("ACK")]           ; wait for acknowledge signal
        low greenled
        high redled
        flip = 1                                  ; flip flop counter to ensure send only once
        gosub flash                               ; flash test led
        return  
        
    green:
        pause 1    
        SEROUT2 PortA.3,T9600,["BOB",greengo]  
        ;SERIN2 PortA.2,84,[WAIT("ACK")]
        low redled
        high greenled
        flip = 0
        gosub flash
        return 
        
    flash:
          high yellowled
          pause 50
          low yellowled
          PAUSE 50
          high yellowled
          pause 50
          low yellowled
          PAUSE 50
          high yellowled
          pause 50
          low yellowled
           
        return
        
    END

    Field code

    Code:
    Include "modedefs.bas" 
    DEFINE OSC 10
    
    TRISA=%00000100
    CMCON=7
    
    relay   VAR PortA.1
    
    signal var BYTE
    
    low relay
    
    
    
    ' Program
    MAIN:
        
        SERin2 PortA.2,84,[wait("BOB"),dec SIGNAL]
            
        if signal = 1 then 
        gosub redstop 
        endif
    
        if signal = 2 then
        GOsub greengo
        endif
    
    goto main
        
    
    redstop:
        high relay
        pause 25 
        SEROUT2 PortA.3,T9600,["ACK"] 
        return
    
    greengo:
        low relay
        pause 25
        SEROUT2 PortA.3,T9600,["ACK"] 
        return 
      
    END

    As an oddball I also discovered that FOR NEXT just doesn't seem to work in any of my codes?

    Rob

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Your Pause 25 may be is too short. Try a longer delay. Say 1 second.

    Also please do the check list as Dick did in post #23.

    Also test if direct connection of your two PIC works as expected.

    Ioannis

  3. #3
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Hi Loannis,

    Thanks for the help.

    I changed the pause to 1 second but it made no difference. It doesn't move on past the Serin unless I remove the 'DEC signal' part so it doesn't reach the Sub.

    I removed the variable parts of the Serout/In and it will work as a one shot. Add a DEC anything and it won't receive it.

    So Field receives "BOB" and will fire relay if I comment out the 'if then' and add a HIGH relay but will not work on a variable value.

    Oh yes, I'm just testing direct connections at moment. When it works as expected I will add the modules.

    I noticed the post of the code had odd formatting, some caps, some lower case. Strange as this was done with Microcode Studio. Just to be sure I copied it into Notepad and wrote the commands as necessary in capitals. No change when compiled, didn't work. I thought the odd 'SIGNAL' in caps was causing a problem. It wasn't written in caps.

    Rob
    Last edited by tasmod; - 9th May 2013 at 12:35.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    WelL I missed that.

    You DO NOT HAVE to place the DEC modifier since what you send is just a binary number.

    So discard the DEC from your SERIN and you will be OK.

    Ioannis

  5. #5
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    OK as you can guess I'm at the pc doing the programming right now.

    I'm sending SEROUT2 PortA.3,T9600,["BOB",redstop] where variable redstop is allocated redstop = 1

    on the other unit ---

    I'm trying to receive SERIN2 PortA.2,84,[WAIT("BOB"),signal] to put the received value into variable 'signal' .

    If signal =1 then gosub

    Whatever combination I try, straight or DEC it doesn't respond.

    Am i doing something stupid?

    Rob

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    1. Serout2 and T9600 are not compatible. Use 84 instead.

    2. Are you sure of the correct ports and connections? Try it directly from PIC to PIC.

    Ioannis

  7. #7
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Yesssss. That was it !

    Read the manual so many times I was confused over what worked with what. Changed to 84 and it works.

    Thank you Loannis

Similar Threads

  1. Wireless modules and simple setup, what is required?
    By tasmod in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 11th April 2013, 17:57
  2. Low latency Wireless RF transceiver modules?
    By mark155 in forum General
    Replies: 0
    Last Post: - 4th March 2010, 05:20
  3. Wireless modules FCC approved
    By Michael in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th September 2008, 02:23
  4. Software RS232 and wireless modules
    By Michael in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th August 2008, 05:27
  5. Wireless comms with Linx LR modules
    By telemark in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2006, 01:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts