1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

TX RX HC-12 radio module

Discussion in 'Oshonsoft' started by camerart, Apr 16, 2018.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I've set up a couple of PICs with HC-12 radio modules. They are sending HSEROUT messages i, e, 'Hserout "PRESS ", strpr, CrLf ' which show on a SERIAL TERMINAL (Teraterm, Putty, Termite) With a number being sent "1", 1 or "2", 2 and setting 'i' as BYTE and STRi as STRING.

    I've tried lots of variations!

    I've tried to use HSERIN, HSERGET on the receiving PCB to do anything like switch a LED etc, but can't get it to work.

    Here's some of what I've tried:
    main:
    stri = #i
    Hserget i
    If i > 0 Then
    Hserout "Number: ", #stri, CrLf
    WaitMs 50
    'WaitMs 1000
    Endif

    Goto main
    End
    'Dim i As Byte
    'Hseropen 19200
    'loop:
    'Hserget i
    'If i > 0 Then
    'Hserout "Number: ", #i, CrLf
    'WaitMs 50
    'Endif
    'Goto loop

    Any ideas please.

    Camerart.
     
  2. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    Hserget receives a character so the # isn't helping
    Code (basic):

    loop:
       Hserget i
        If i > 0 Then
          Hserout "Number: ", i, CrLf
          WaitMs 50
       Endif
    Goto loop

     
    Should work.... I'll test it now..
     
  3. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    Yup! works here.... If the '#' is used it prints the number of the ASCII character ..
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,

    So I can prove the RX is receiving ok, is this ok?

    loop:
    Hserget i
    If i > 0 Then
    Hserout "Number: ", i, CrLf
    LED = 1
    WaitMs 50
    Endif
    ELSE
    LED = 0
    ENDIF

    Goto loop
    Then SEND 0 or 1 from TX?

    EDIT: I'll double check the PCB connections, as it's an old PCB, with previous alterations.

    C
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    So far I've got them to switch ON and stay ON, and not switch ON, but I can't get them to alternate ON/OFF

    Can you show me the code for what you sent from the TX to get yours going please?
    I've tried this:
    main:
    i = 0
    rled = 0
    yled = 1
    Hserout i, CrLf
    WaitMs 5000

    i = 1
    rled = 1
    yled = 0
    Hserout i, CrLf
    WaitMs 5000
    Goto main

    '0' and '1' show on the Terminal.


    C
     
  7. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    Look at your first code..
    Code (basic):

    loop:
        Hserget i
        If i > 0 Then
           Hserout "Number: ", i, CrLf
           LED = 1
           WaitMs 50
        ;Endif <------ Shouldn't be here..
        ELSE
           LED = 0
        ENDIF
    Goto loop
     
    Two things....

    First ) You can't "ENDIF" and then "ELSE"..
    Second) The LED will be on for less than a micosecond

    Code (basic):

    loop:
        Hserget i
        If i > 0   Then
           If LED = 0
              Hserout "Number: ", i, CrLf
              LED = 1
             WaitMs 50
          ELSE
             LED = 0
          ENDIF
       ENDIF
    Goto loop
     
    now LED will toggle when a character is bigger than 0 come in
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    What are you sending to the RX?

    Hserout "Number: ", i, CrLf
    or Hserout i, CrLf
    or Hserout "1 ", CrLf
    or Hserout 1, CrLf

    C
     
  10. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    Not sure what you are saying... I thought this was the receiver?

    The PC sends any character and the LED turns on, then any other character turns it off!
     
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    I have two HC-12s on PCBs One TX and and the other RX.

    I've tried many combinations of SEND and RECEIVE, and got the RX LED to switch ON, but not ON/OFF

    How do I switch 'say' a LED ON/OFF by sending different numbers?

    NOTE: Your last suggestion #6, didn't compile in Oshonsoft. It didn't like 'If LED = 0' for some reason.

    C.
     
  12. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    385
    Likes:
    18
    Location:
    Helsinki, Finland
    Is your serial setup between pic and hc12 correct, speed, number of bits, etc.
     
  13. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    Code (basic):

    loop:
        Hserget i
        If i > 49   Then     ; <----- 49 is number 1
              Hserout "Number: ", i, CrLf
              LED = 1
              WaitMs 50
         ENDIF
        If i > 48  Then   ; <----- 48 is number 0
              Hserout "Number: ", i, CrLf
              LED = 0
              WaitMs 50
       ENDIF
    Goto loop
     
    Now ascii 1 switches it on and ascii 0 switches it off

    Send
    Hserout "1" or Hserout "0" to switch... if your not sure, send numbers 48 and 49
     
  14. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    They both have an element of TX and RX, and both show on a computer terminal using a 3rd HC-12.
    C.
     
  15. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.

    Hi I,
    That answers the odd large number, I occasionally saw i,e, 75 (from memory)
    I'll try your code tomorrow, thanks.
    C.
     
  16. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,

    Your code show both 'If i > 48' also 'If i > 49' is this correct?

    At the moment the RX LED is switcing ON but not OFF.

    I've also tried 72 and 73 DEC

    EDITED

    C.
     
    Last edited: Apr 17, 2018
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I've tried many variations of the above code, but nothing switches the RX ON/OFF yet.

    If I use this: and keep resetting the RX the YLED switches ON or OFF 50% of the time, and the RLED is always ON.
    C.

    TX:--------------------------------------------------------------------------------------
    For x = 0 To 1000
    rled = 0
    yled = 1
    Hserout "0", CrLf
    Next x

    For x = 0 To 1000
    rled = 1
    yled = 0
    Hserout "1", CrLf
    Next x

    RX:--------------------------------------------------------------------------------
    Hserget i
    If i = 0 Then '< --- -- 48 is number 0
    Hserout "Number: ", i, CrLf
    rled = 1
    WaitMs 500
    Endif

    If i = 106 Then '= 106 Then '< --- -- 49 is number 1
    Hserout "Number: ", i, CrLf
    yled = 1
    WaitMs 500
    Endif
     
  18. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    My code uses 48 ( ascii 0) and 49 ( ascii 1) It works because I tested it!!

    ASCII 48 to 57 are numbers 0 to 9 ..

    You can also do this
    if i = asc("1") then....

    Then you dont have to remember stuff
     
  19. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    385
    Likes:
    18
    Location:
    Helsinki, Finland
    "0" is 48 decimal
    "1" is 49 decimal
    What is IF i= 106??
    What do you mean by Rx on/off?
    Does it mean rled on/off?
     
  20. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    Anything to save me remembering stuff is welcome.

    TX is sending "0" or "1" depending on a BUTTON press, and can be seen on my terminal
    RX turns on RLED or YLED depending on TX "0" or "1" but needs to be reset to change.
    RX LEDs don't always come on after reset, approx 50%, but if they do they are the correct colour

    RX CODE---------------------------------------------------------------------------------
    main:
    Hserget i
    If i = Asc("0") Then '< --- -- 48 is number 0
    Hserout "Number: ", i, CrLf
    rled = 1
    WaitMs 500
    Endif

    If i = Asc("1") Then '< --- -- 49 is number 1
    Hserout "Number: ", i, CrLf
    yled = 1
    WaitMs 500
    Endif
    Goto main
     
    Last edited: Apr 18, 2018
  21. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,789
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    The reply in #18 is after more tests, where I found the RX needs to be switched ON/OFF (reset) to get the LEDs to switch. (and then only 50%, but always if they come on they are the correct colour)

    I tried I's <48 <49 and asked why they are both <, if you understand what I mean? Then after lots of < and > I arrived at 106, which worked for some reason, but ignore all that as now I use I's suggestion of Asc("1").

    Hope all that is clear.
    C.
     
  22. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,741
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    There are hundreds of ASCII tables online to check the relating numbers..

    But!! I imagine this is for testing, because you can't easily send non ascii characters from a PC..

    Yeah!! Sorry about that... I tested it with "If i = 48 then" Hey! with help like mine you are definitely kept on your toes!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice