|
| 1 | +/** |
| 2 | + * ---------------------------------------------------------------------------- |
| 3 | + * WirelessControl.ino - wireless controller sketch using AIR430Boost ETSI driver. |
| 4 | + * Copyright (C) 2012-2013 Anaren Microwave, Inc. |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 2.1 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with this library; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + * |
| 20 | + * This example demonstrates usage of the AIR430BoostETSI library which uses |
| 21 | + * the 430Boost-CC110L AIR Module BoosterPack created by Anaren Microwave, Inc. |
| 22 | + * and available through the TI eStore, for the European Union. |
| 23 | + * |
| 24 | + * ---------------------------------------------------------------------------- |
| 25 | + * |
| 26 | + * Note: This file is part of AIR430Boost. |
| 27 | + * |
| 28 | + * ---------------------------------------------------------------------------- |
| 29 | + * |
| 30 | + * Description |
| 31 | + * =========== |
| 32 | + * |
| 33 | + * On each loop cycle, a message is transmitted and a message is received from |
| 34 | + * a remote node or a timeout occurs. The message contains a control command. |
| 35 | + * The control command turns the red LED on or off. Both nodes can control |
| 36 | + * each others red LED through a button press. When the button on one node is |
| 37 | + * pressed or held down, the red LED should light up on the remote node, and |
| 38 | + * vice versa. |
| 39 | + * |
| 40 | + * ---------------------------------------------------------------------------- |
| 41 | + * |
| 42 | + * This example assumes that two BoosterPacks will be used to showcase the |
| 43 | + * wireless radio communication functionality. This same code should be |
| 44 | + * programmed to both LaunchPad development kits. |
| 45 | + * |
| 46 | + * This BoosterPack relies on the SPI hardware peripheral and two additional |
| 47 | + * GPIO lines for SPI chip-select and GDO0 for packet handling. They use pins 18 |
| 48 | + * and 19 respectively. |
| 49 | + * |
| 50 | + * In the default configuration, this BoosterPack is not compatible with an |
| 51 | + * external crystal oscillator. This can be changed, if necessary, and would |
| 52 | + * require reconfiguration of the BoosterPack hardware and changes to the |
| 53 | + * AIR430BoostETSI library. Refer to the BoosterPack User's Manual if necessary. |
| 54 | + * |
| 55 | + * ETSI regulations must be followed when using this library. This example |
| 56 | + * limits the wireless duty cycle to 0.1% per ETSI. |
| 57 | + * |
| 58 | + * For complete information, please refer to the BoosterPack User's Manual |
| 59 | + * available at: |
| 60 | + * https://www.anaren.com/air/cc110l-air-module-boosterpack-embedded-antenna-module-anaren |
| 61 | + * |
| 62 | + * To purchase the 430Boost-CC110L AIR module BoosterPack kit, please visit the |
| 63 | + * TI eStore at: |
| 64 | + * https://estore.ti.com/430BOOST-CC110L-CC110L-RF-Module-BoosterPack-P2734.aspx |
| 65 | + */ |
| 66 | + |
| 67 | +// The AIR430BoostETSI library uses the SPI library internally. Energia does not |
| 68 | +// copy the library to the output folder unless it is referenced here. |
| 69 | +// The order of includes is also important due to this fact. |
| 70 | +#include <SPI.h> |
| 71 | +#include <AIR430BoostETSI.h> |
| 72 | + |
| 73 | +// ----------------------------------------------------------------------------- |
| 74 | +/** |
| 75 | + * Defines, enumerations, and structure definitions |
| 76 | + */ |
| 77 | + |
| 78 | +#define CMD_OFF 0 |
| 79 | +#define CMD_ON 1 |
| 80 | + |
| 81 | +/** |
| 82 | + * sControl - control packet. |
| 83 | + */ |
| 84 | +struct sControl |
| 85 | +{ |
| 86 | + unsigned char cmd; |
| 87 | +}; |
| 88 | + |
| 89 | +// ----------------------------------------------------------------------------- |
| 90 | +/** |
| 91 | + * Global data |
| 92 | + */ |
| 93 | + |
| 94 | +struct sControl txControl = { CMD_OFF }; // TX control packet |
| 95 | +struct sControl rxControl = { CMD_OFF }; // RX control packet |
| 96 | + |
| 97 | +// ----------------------------------------------------------------------------- |
| 98 | +// Debug print functions |
| 99 | + |
| 100 | +void printRxData() |
| 101 | +{ |
| 102 | + // Print the last received command to the serial port. |
| 103 | + Serial.print("RX Command: "); |
| 104 | + Serial.println(rxControl.cmd); |
| 105 | +} |
| 106 | + |
| 107 | +// ----------------------------------------------------------------------------- |
| 108 | +// Main example |
| 109 | + |
| 110 | +void setup() |
| 111 | +{ |
| 112 | + // The radio library uses the SPI library internally, this call initializes |
| 113 | + // SPI/CSn and GDO0 lines. Also setup initial address, channel, and TX power. |
| 114 | + Radio.begin(0x01, CHANNEL_1, POWER_MAX); |
| 115 | + |
| 116 | + // Setup serial for debug printing. |
| 117 | + Serial.begin(9600); |
| 118 | + |
| 119 | + /** |
| 120 | + * Setup LED for example demonstration purposes. |
| 121 | + * |
| 122 | + * Note: Set radio first to ensure that GDO2 line isn't being driven by the |
| 123 | + * MCU as it is an output from the radio. |
| 124 | + */ |
| 125 | + pinMode(RED_LED, OUTPUT); |
| 126 | + digitalWrite(RED_LED, LOW); |
| 127 | + |
| 128 | + // Setup push button. |
| 129 | + pinMode(PUSH2, INPUT_PULLUP); |
| 130 | +} |
| 131 | + |
| 132 | +void loop() |
| 133 | +{ |
| 134 | + // Check for a button press. If the button is being pressed, load the txControl |
| 135 | + // into the radio TX FIFO and transmit it to the broadcast address. |
| 136 | + if (digitalRead(PUSH2) == LOW) |
| 137 | + { |
| 138 | + txControl.cmd = CMD_ON; |
| 139 | + } |
| 140 | + else |
| 141 | + { |
| 142 | + txControl.cmd = CMD_OFF; |
| 143 | + } |
| 144 | + Radio.transmit(ADDRESS_BROADCAST, (unsigned char*)&txControl, sizeof(txControl)); |
| 145 | + |
| 146 | + /** |
| 147 | + * The radio transmitter and receiver cannot be operated at the same time. |
| 148 | + * Wait until transmit completes before turning on the receiver. Please note |
| 149 | + * that the radio is considered busy when it is transmitting. |
| 150 | + * |
| 151 | + * WARNING: If busy is not checked between two successive radio operations |
| 152 | + * receiverOn/transmit, the radio may not perform the specified task. The |
| 153 | + * radio must be complete with the transmission before it can begin the next |
| 154 | + */ |
| 155 | + while (Radio.busy()); |
| 156 | + |
| 157 | + // Turn on the receiver and listen for incoming data. Timeout after 1 seconds. |
| 158 | + // The receiverOn() method returns the number of bytes copied to rxData. |
| 159 | + if (Radio.receiverOn((unsigned char*)&rxControl, sizeof(rxControl), 1000) > 0) |
| 160 | + { |
| 161 | + // Perform action based on incoming command: turn on/off red LED. |
| 162 | + if (rxControl.cmd == CMD_ON) |
| 163 | + { |
| 164 | + digitalWrite(RED_LED, HIGH); |
| 165 | + } |
| 166 | + else |
| 167 | + { |
| 168 | + digitalWrite(RED_LED, LOW); |
| 169 | + } |
| 170 | + |
| 171 | + printRxData(); // RX debug information |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Warning: ETSI regulations require duty cycling of 0.1% per hour. Changing |
| 176 | + * this may invalidate ETSI compliance. Some margin has been added. Please |
| 177 | + * refer to Anaren's A110LR09 User's Manual for more information. |
| 178 | + */ |
| 179 | + delay(500); |
| 180 | +} |
| 181 | + |
0 commit comments