433MHz module: Translate basic to spin
Crosswinds
Posts: 182
Hello Guys!
Trying to control some wall-outlet relays, wich is cordless and works on the 433MHz band. I am completely new to the wireless stuff with propeller, and have never used it on another platform either.
I have found a protocol for the recievers, and also code that works with PIC (Basic, PBASIC?)
The protocol can be found following this link: http://svn.telldus.com/svn/rf_ctrl/nexa_2_6_driver/trunk/NexaProtocol.txt
And here is the Pbasic code:
It would be great if someone could help me translate this to spin, so that i have a test-code as a kickstart.
The code above does also use the parallax module, but way back when they came separated as sender and reciever.
Iam very excited to get started with this project, so any help will be greatly appreciated!
Thanks guys.
Daniel
Trying to control some wall-outlet relays, wich is cordless and works on the 433MHz band. I am completely new to the wireless stuff with propeller, and have never used it on another platform either.
I have found a protocol for the recievers, and also code that works with PIC (Basic, PBASIC?)
The protocol can be found following this link: http://svn.telldus.com/svn/rf_ctrl/nexa_2_6_driver/trunk/NexaProtocol.txt
And here is the Pbasic code:
DEFINE OSC 4 ' Timing as described in NexaProtocol.txt T CON 350 ' T = 350uS T3 CON 1050 ' 3T T32 CON 11200 ' 32T (Stop/Synch) ' Note we're using 1 VS X as shown in text A1_ON CON %111000000000 ' 12-bit code for House/Unit A1 ON A1_OFF CON %011000000000 ' 12-bit code for House/Unit A1 OFF ' ||||||||||||____ 4-bit House code ' ||||||||________ 4-bit Unit code ' ||||____________ 3-bit Unknown code ' |_______________ 1-bit Activation code 1=ON 0=OFF D_PACKET VAR WORD ' Holds 12-bit data packet to send INDEX VAR BYTE ' Data packet bit index pointer LOOPS VAR BYTE ' Loop counter TX VAR PORTB.0 ' Connects to RF transmitter data in LOW TX ' TX output idles low for RF carrier OFF Main: D_PACKET = A1_ON GOSUB Send PAUSE 5000 D_PACKET = A1_OFF GOSUB Send PAUSE 5000 GOTO Main Send: FOR LOOPS = 1 TO 4 ' send each packet 4 times FOR INDEX = 0 TO 11 ' sends 12 bits per pass LSB 1st HIGH TX ' The 1st half of a 0 or X bit period is the PAUSEUS T ' same so no need to repeat this sequence inside LOW TX ' the IF block PAUSEUS T3 IF D_PACKET.0[INDEX]=1 THEN HIGH TX ' send a 1 bit (1=X here) PAUSEUS T3 LOW TX PAUSEUS T ELSE HIGH TX ' send a 0 bit PAUSEUS T LOW TX PAUSEUS T3 ENDIF NEXT INDEX ' loop until all 12-bits sent ' Start of Stop/Synch period after each 12-bit packet HIGH TX PAUSEUS T LOW TX PAUSEUS T32 ' End of Stop/Synch period NEXT LOOPS ' send 4 packets per pass RETURN END
It would be great if someone could help me translate this to spin, so that i have a test-code as a kickstart.
The code above does also use the parallax module, but way back when they came separated as sender and reciever.
Iam very excited to get started with this project, so any help will be greatly appreciated!
Thanks guys.
Daniel
Comments
Some assistance please?
Alternatively, you could use PropBasic which has some similarities to your PICBasic and gets translated into Spin and Propeller Assembly Language.
Is there any direct equivalent for LOW / HIGH / PAUSE in spin? I think that i will manage the repeat loops, but i got stuck really at the basics on how the transmitter works. Often there are a object wich you can look at and with the help of that translate the code.
I have a bit experience of spin, but there are some methodes used with the transmitter that im not familliar with.
OUTA[x]~
DIRA[x]~~
HIGH x
OUTA[x]~~
DIRA[x]~~
PAUSE x
WAITCNT((CLKFREQ/1000)*x + CNT)
If you've already done the DIRA[x]~~ somewhere in your initialization code, you don't have to do it again. I put it here because, strictly speaking, the LOW and HIGH statements put the I/O pin into output mode.
That was just stupid of me to not think of the standard outa and dira.. Jesus, you shouldnt put down the coding project for more then a week
Is this somewere right or should i stop right now?
/Daniel
Thank you very much for your help. I did the changes you mentioned, but no luck. Dont get any response from the reciever.
I also tried to move down the repeat 0-11 but that dont change the result. Are you sure that it should only include the if-statements? Because to me it looks like it includes everything in the basic code.
Anyway, i tried it both ways no luck. Its hard to tell whats happening since its wireless
Any ideas?
Heres the code:
Having a hard time understanding what im doing wrong with the indention. I feel that every line after the IF block should be included in the loop for the total packets (4), and i think it is.
Its hard to describe, but please have a look.
So it works great now. And thanks for your clean code, some good pointers there!
Thank you very much for all your help.