How to obtain data from a sensor
There are two ways to obtain sensor information:
- Queried sampling to immediately read all enabled digital and analog input pins.
- Automatic sampling to transmit the sensor data periodically or whenever a digital pin changes.
In both cases, the information is sent to the other module is called IO sample. It contains which inputs (DIO lines or ADC channels) have sampling enabled and the value of all the enabled digital and analog inputs.
Queried sampling (IS)
The Force Sample (IS) command forces a read of all enabled digital and analog input pins. You can send it locally or to a remote device.
Use the XCTU console or any serial port terminal application to send this command.
When the module sends the IS command, the receiving device reads all enabled digital IO and analog input channels and returns their value. If the module transmits the IS command locally, it sends the IO data out the serial interface. If the module transmits the IS command to a remote XBee module, it sends the remote IO data over the air to the requester module.
Once you have set up the pin, the remote module must be configured to automatically transmit the sensor information to the main XBee module. The remote XBee module needs to know:
- Where to transmit the sensor data: define this information for the module receiving this information by the destination address (DH + DL) parameters.
- When to transmit the sensor data:
- Periodically: The XBee can send the information read from the sensor at a specified interval.
- By change detection: When a pin or several pins change status.
Configure parameters IO Sampling Rate (IR) and Digital IO Change Detection (IC) to automatically transmit the sensor data.
Note These two features can work in combination with each other, depending on your requirements. For example, you could choose to receive an IO sample every minute (IR) but also when a certain pin changes state (IC).
IO Sampling Rate (IR)
The IR parameter sets the I/O sample rate: that is, how frequently to report the current pin state and transmit it to the destination address. The rate is set in milliseconds using hexadecimal notation. The value 0 disables the feature.
For example, if you want to transmit the sensor info every minute, set this parameter to EA60 (1 minute = 60 seconds = 60000 ms = EA60 hex).
Use XCTU to configure the sample rate interval.
Note Sleeping devices, configured to send samples periodically, transmit the first sample immediately after waking up, and then continue sending periodic IO samples at the IR rate, until the Time Before Sleep (ST) timer expires and the device can resume sleeping.
Digital IO Change Detection (IC)
The IC parameter allows you to set which pins to monitor for change detection. When the state of the monitored pin(s) changes, a sample is immediately sent to the destination address.
Use XCTU to set the value of IC parameter.
To select which pins monitor, assign a binary value to IC parameter based on the following pattern:
For example, if you want to monitor DIO1, the value would be 0000000000010, which is 2 in hexadecimal notation. If you want to monitor DIO12, DIO8, DIO3 and DIO1, the value would be 1000100001010 (binary) = 110A (hexadecimal). The value 0 disables the feature.
The Digital IO Change Detection (IC) feature only works for digital pins, so you will not receive anything if the value of an analog pin changes.