RF12demo sketch
- See the repository code.
- RF12demo blog post
The RF12 demo is useful as a first JeeNode sketch, and to confirm function of new (or newly constructed) JeeNode units. It is also intended as a general EEPROM configuration utility. The RFdemo sketch may be found in the Arduino IDE under File -> Examples -> RF12 -> RF12demo.
If you're not seeing Examples -> RF12, then you need to install the RF12 library. You should also install the ports library while you're installing.
After loading the RF12demo sketch in the Arduino IDE, open the serial monitor, and the startup screen should look approximately like this:
You can type commands on the serial port to adjust the configuration settings. These are stored in EEPROM along with a description string and a 16-bit CRC checksum. The EEPROM is non-volatile memory in the Atmega chip, so anytime the JeeNode is powered on, the last settings get re-used. Thus configuring the JeeNode becomes a set-and-forget thing and need only be done once, unless you wish to change settings for some reason.
Once the JeeNode settings have been figured, your sketches only need include the library method “rf12_config();” which will do the following things:
- retrieve the settings from EEPROM and check that they are valid
- if so, configure the RF12 hardware accordingly
- display the current settings on the serial port
Configuring the JeeNode
Before we can configure the JeeNode it's a good idea to understand what the configuration parameters mean.
RF12 Configuration Parameters
nodeId
The ID of this wireless node. The range for ID's within a group is 1 to 31, ID 0 is reserved for a special use. JeeNodes can use the nodeId to talk (or listen to) specific other JeeNodes in a netGroup. So nodeId's should be unique within one netGroup.
freqBand
This determines frequency range in which the wireless module will operate and is set by the manufacturer (HopeRF) of the radio modules. So it is important use the setting matching the radio modules you have. The three options are:
RF12_433MHZ
RF12_868MHZ
RF12_915MHZ
netGroup
Net groups are used to separate nodes: only nodes in the same net group can communicate with each other. This parameter is optional, it defaults to 212 (0xD4) when omitted. The netGroup parameter should be in the range of 1-212.
The RF12 configuration data is stored in EEPROM addresses 0×20..0x3F.
Setting the parameters
To set the nodeId to "4" type
4 i
The serial monitor will respond with
> 4i
D i4 g212 @ 433 MHz
To set the frequency type
9 b // setting for 915 Mhz radio for the US, Canada etc.
The serial monitor will respond with
> 9b
D i4 g212 @ 915 MHz
Testing JeeNodes with the RF12 demo sketch
After configuring two JeeNodes with the proper frequency setting, unique netId's and the same netGroup numbers. Power them both up and type
3 a
The serial monitor should respond with
> 3a
-> 15 b
OK 196 0
The OK is an acknowledgment from the other JeeNode that it received a packet