Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: Wireless RF - Sharing some Code Examples

Re: Wireless RF - Sharing some Code Examples 7 years 5 months ago #15669

  • bitfogav
  • bitfogav's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Thanks received: 53
Thought I would share some Proton Basic code for RF modules which I used for testing, Might be handy for someone

TX Code:
[proton filename=code.bas]
Device = 12F675

Xtal = 4

Reminders = Off
Config XT_OSC, WDT_OFF, PWRTE_ON, BODEN_OFF, CPD_OFF, CP_OFF, MCLRE_OFF
Reminders = On

Set_OSCCAL ' Calibrate the on-chip oscillator
All_Digital = TRUE ' set CMCON = 7
INTCON = 0 ' Disable Interrupts

'
[DECLARE SERIAL DATA]
Declare Rsout_Pin GPIO.2 ' Assigns the Port and Pin that will be used to Output serial data.
Declare Rsout_Mode 0 ' Sets the serial mode.
Declare Serial_Baud 1200 ' Baud Rate to receive and transmit data.
Declare Rsout_Pace 10 ' Delay between characters transmitted by the Rsout command.

'
[ASSIGN PINS]
Symbol Led = GPIO.0
Symbol btn1 = GPIO.1

'
[ASSIGN GENERAL VARIABLES]
Dim byteOut As Byte
Dim looop As Byte

'
[INITIALISE THE PICMICRO]
TRISIO = %111010 ' Set pin functions (Input/Output)
Output Led
Low Led
Input btn1

' Init variables
byteOut = 1
DelayMS 100 ' Wait for the PICmicro to stabilise

'
[MAIN PROGRAM LOOP STARTS HERE]
While 1 = 1

If btn1 = 0 Then ' test button

High Led ' turn on led to show that button was pressed
DelayMS 50 ' button debounce

' send out some data so stabilize the RF receiver
RSOut Bin 43690
' then send header Z, then your data byte
' send data serveral times to make sure Receiver receives data
For looop = 0 To 2
RSOut "Z" , Dec byteOut, 13
Next

DelayMS 500

EndIf

Low Led ' turn off led

Wend[/proton]

RX Code]
Device = 12F675

Xtal = 4

Reminders = Off
Config FOSC_XT, CPD_OFF, CP_OFF, BODEN_OFF, MCLRE_OFF, PWRTE_ON, WDT_OFF
Reminders = On

Set_OSCCAL ' Calibrate the on-chip oscillator
All_Digital = TRUE ' set CMCON = 7
INTCON = 0 ' Disable Interrupts

'
[DECLARE SERIAL DATA]
Declare Rsin_Pin GPIO.2 ' Assigns the Port and Pin that will be used to input serial data.
Declare Rsin_Mode 0 ' Sets the serial mode.
Declare Serial_Baud 1200 ' Baud Rate to receive and transmit data.
Declare Rsin_Timeout 5000 ' Time, in ms, that Rsin will wait for a start bit to occur.
'
[ASSIGN PINS]
Symbol Led = GPIO.0

'
[ASSIGN GENERAL VARIABLES]
Dim byteIn As Byte

'
[INITIALISE THE PICMICRO]
TRISIO = %111100 ' Set pin functions (Input/Output)
Output Led
High Led

' Init variables
DelayMS 100 ' Wait for the PICmicro to stabilise

'
[MAIN PROGRAM LOOP STARTS HERE]
While 1 = 1

' Wait for the value "Z" to be received
RSIn {Time_Out}, Wait("Z"), Dec byteIn

' Put your code here when correct data received
Low Led ' turn off led to show data received
DelayMS 2000

Time_Out]

Some of the code I used is from Grahams Proton code examples, he explains some of the function better than I can which can be found here:
Proton Basic RF Code Examples

Re: Wireless RF - Sharing some Code Examples 7 years 5 months ago #7746

Cheers Gav, nice way to tie in an article that was part of the original "gramospicbasic", written in 2007, ported in 2009

Which RF modules are you using?

Re: Wireless RF - Sharing some Code Examples 7 years 5 months ago #7759

  • bitfogav
  • bitfogav's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Thanks received: 53
Thanks Graham, The modules Im using was the cheapest I could find. When I got my first batch they was from Sure Electronics, but it seems they no longer sell them now, after abit of searching I found the same RF modules from RFRemotech and still very cheap!.

Receiver module is the RM1SGS
WebLink = RM1SGS

Datasheet

Transmitter module is the TM1000-1
WebLink = TM1000-1

Datasheet

Attachments:
Time to create page: 0.244 seconds