2016-08-11 00:30:43 +00:00
|
|
|
/* Hamshield
|
|
|
|
* Example: Morse Code Beacon
|
2018-02-14 00:51:32 +00:00
|
|
|
*
|
2016-08-11 00:30:43 +00:00
|
|
|
* Test beacon will transmit and wait 30 seconds.
|
|
|
|
* Beacon will check to see if the channel is clear before it
|
|
|
|
* will transmit.
|
|
|
|
* Connect the HamShield to your Arduino. Screw the antenna
|
|
|
|
* into the HamShield RF jack. Connect the Arduino to wall
|
|
|
|
* power and then to your computer via USB. After uploading
|
2016-08-26 21:40:47 +00:00
|
|
|
* this program to your Arduino, open the Serial Monitor to
|
2016-08-11 00:30:43 +00:00
|
|
|
* monitor the status of the beacon. To test, set a HandyTalkie
|
2018-02-14 00:51:32 +00:00
|
|
|
* to 438MHz. You should hear the message " CALLSIGN HAMSHIELD"
|
2018-02-14 00:29:12 +00:00
|
|
|
* in morse code.
|
2015-06-20 20:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-05 19:41:35 +00:00
|
|
|
#define DDS_REFCLK_DEFAULT 9600
|
2015-06-20 21:00:39 +00:00
|
|
|
#include <HamShield.h>
|
2015-06-20 20:37:48 +00:00
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
#define PWM_PIN 3
|
|
|
|
#define RESET_PIN A3
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
2015-06-20 22:22:33 +00:00
|
|
|
HamShield radio;
|
2015-06-20 20:37:48 +00:00
|
|
|
|
2015-06-28 17:20:57 +00:00
|
|
|
// Run our start up things here
|
2015-06-20 20:37:48 +00:00
|
|
|
void setup() {
|
2015-11-23 16:54:10 +00:00
|
|
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
|
|
pinMode(PWM_PIN, OUTPUT);
|
|
|
|
digitalWrite(PWM_PIN, LOW);
|
|
|
|
|
|
|
|
// prep the switch
|
|
|
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
|
|
|
|
|
|
// set up the reset control pin
|
|
|
|
pinMode(RESET_PIN, OUTPUT);
|
|
|
|
digitalWrite(RESET_PIN, HIGH);
|
2018-08-05 02:47:58 +00:00
|
|
|
delay(5); // wait for device to come up
|
2015-11-23 16:54:10 +00:00
|
|
|
|
2015-06-28 17:20:57 +00:00
|
|
|
// Set up the serial port at 9600 Baud
|
2015-06-20 20:37:48 +00:00
|
|
|
Serial.begin(9600);
|
2015-06-28 17:20:57 +00:00
|
|
|
|
|
|
|
// Send a quick serial string
|
|
|
|
Serial.println("HamShield FM Beacon Example Sketch");
|
2015-06-20 21:00:39 +00:00
|
|
|
|
2015-06-28 17:20:57 +00:00
|
|
|
// Query the HamShield for status information
|
2015-06-20 20:37:48 +00:00
|
|
|
Serial.print("Radio status: ");
|
|
|
|
int result = radio.testConnection();
|
|
|
|
Serial.println(result,DEC);
|
2015-06-28 17:20:57 +00:00
|
|
|
|
|
|
|
// Tell the HamShield to start up
|
|
|
|
radio.initialize();
|
2018-02-14 00:51:32 +00:00
|
|
|
|
|
|
|
// Set the transmit power level (0-8)
|
2016-01-05 03:36:37 +00:00
|
|
|
radio.setRfPower(0);
|
2018-02-14 00:51:32 +00:00
|
|
|
|
|
|
|
// Set the morse code characteristics
|
2018-02-14 00:29:12 +00:00
|
|
|
radio.setMorseFreq(600);
|
|
|
|
radio.setMorseDotMillis(100);
|
2016-06-05 19:41:35 +00:00
|
|
|
|
2018-02-14 00:51:32 +00:00
|
|
|
// Configure the HamShield to operate on 438.000MHz
|
2016-06-05 19:41:35 +00:00
|
|
|
radio.frequency(438000);
|
2015-06-28 17:20:57 +00:00
|
|
|
|
|
|
|
Serial.println("Radio Configured.");
|
2015-06-20 20:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2015-06-28 17:20:57 +00:00
|
|
|
// We'll wait up to 30 seconds for a clear channel, requiring that the channel is clear for 2 seconds before we transmit
|
2015-07-15 03:05:20 +00:00
|
|
|
if (radio.waitForChannel(30000,2000,-5)) {
|
2015-06-28 17:20:57 +00:00
|
|
|
// If we get here, the channel is clear. Let's print the RSSI to the serial port as well.
|
|
|
|
Serial.print("Signal is clear, RSSI: ");
|
|
|
|
Serial.println(radio.readRSSI());
|
|
|
|
|
|
|
|
// Start transmitting by putting the radio into transmit mode.
|
|
|
|
Serial.print("Transmitting... ");
|
|
|
|
radio.setModeTransmit();
|
|
|
|
|
|
|
|
// Send a message out in morse code
|
2018-02-14 00:51:32 +00:00
|
|
|
radio.morseOut(" CALLSIGN HAMSHIELD");
|
2015-06-28 17:20:57 +00:00
|
|
|
|
|
|
|
// We're done sending the message, set the radio back into recieve mode.
|
|
|
|
radio.setModeReceive();
|
|
|
|
Serial.println("Done.");
|
|
|
|
} else {
|
|
|
|
// If we get here, the channel is busy. Let's also print out the RSSI.
|
2015-06-20 22:22:33 +00:00
|
|
|
Serial.print("The channel was busy. Waiting 10 seconds. RSSI: ");
|
|
|
|
Serial.println(radio.readRSSI());
|
2018-02-14 00:29:12 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 00:51:32 +00:00
|
|
|
// Wait 30 seconds before we send our beacon again.
|
2018-02-14 00:29:12 +00:00
|
|
|
delay(30000);
|
2015-07-02 20:52:30 +00:00
|
|
|
}
|