• 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.

TX RX HC-12 radio module

camerart

Active Member
Thread starter #1
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.
 

camerart

Active Member
Thread starter #4
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
 

camerart

Active Member
Thread starter #5
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
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#6
Look at your first code..
Code:
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:
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
 

camerart

Active Member
Thread starter #7
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
 

camerart

Active Member
Thread starter #9
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!
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#11
Code:
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
 

camerart

Active Member
Thread starter #13
Code:
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

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

camerart

Active Member
Thread starter #14
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:

camerart

Active Member
Thread starter #15
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
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#16
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
 
#17
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
"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?
 

camerart

Active Member
Thread starter #18
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
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:

camerart

Active Member
Thread starter #19
"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?
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#20
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..

I tried I's <48 <49 and asked why they are both <
Yeah!! Sorry about that... I tested it with "If i = 48 then" Hey! with help like mine you are definitely kept on your toes!!
 

Latest threads

EE World Online Articles

Loading

 
Top