Created
May 9, 2017 22:48
-
-
Save kinasmith/66a2105617b18b2f5177048b45595456 to your computer and use it in GitHub Desktop.
testing initialization of SD card and RFM69HCW radio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 | |
#include <RFM69_ATC.h> | |
#include "Arduino.h" | |
// Use the external SPI SD card as storage | |
#include <SPI.h> | |
#include <SD.h> | |
//********************************************************************************************* | |
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE ************* | |
//********************************************************************************************* | |
#define NETWORKID 100 // The same on all nodes that talk to each other | |
#define NODEID 1 // The unique identifier of this node | |
#define RECEIVER 1 // The recipient of packets | |
//Match frequency to the hardware version of the radio on your Feather | |
#define FREQUENCY RF69_433MHZ | |
//#define FREQUENCY RF69_868MHZ | |
//#define FREQUENCY RF69_915MHZ | |
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes! | |
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module | |
#define SERIAL_BAUD 115200 | |
#define RFM69_CS 10 | |
#define LED 9 // onboard blinky | |
#define SD_PIN 7 // SD Card CS pin | |
//********************************************************************************************* | |
//********************************************************************************************* | |
//Auto Transmission Control - dials down transmit power to save battery | |
//Usually you do not need to always transmit at max output power | |
//By reducing TX power even a little you save a significant amount of battery power | |
//This setting enables this gateway to work with remote nodes that have ATC enabled to | |
//dial their power down to only the required level | |
#define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL | |
//********************************************************************************************* | |
//RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN); | |
#ifdef ENABLE_ATC | |
RFM69_ATC radio; | |
#else | |
RFM69 radio; | |
#endif | |
void setup() | |
{ | |
Serial.begin(SERIAL_BAUD); | |
initSDCard(); | |
initRadio(); | |
} | |
void loop() | |
{ | |
} | |
/** | |
* [initRadio description] | |
*/ | |
void initRadio() | |
{ | |
Serial.println("Arduino RFM69HCW Transmitter"); | |
//Now initialise the radio | |
bool check = radio.initialize(FREQUENCY, NODEID, NETWORKID); | |
if (check) | |
{ | |
if(IS_RFM69HCW) | |
{ | |
radio.setHighPower(); // Only for RFM69HCW & HW! | |
} | |
//radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm) | |
radio.encrypt(NULL); | |
// radio.encrypt(ENCRYPTKEY); | |
// radio.setFrequency(433000000); | |
#ifdef ENABLE_ATC | |
Serial.println("RFM69_ATC Enabled (Auto Transmission Control)"); | |
#endif | |
// pinMode(LED, OUTPUT); | |
Serial.print("\Transmitting at "); | |
Serial.print(radio.getFrequency()); | |
Serial.println(" Hz"); | |
} else { | |
Serial.println("Cannot initialize radio"); | |
} | |
} | |
/** | |
* [initSDCard description] | |
*/ | |
void initSDCard() | |
{ | |
Serial.println(); | |
Serial.print("Initializing SD card..."); | |
// see if the card is present and can be initialized: | |
if (!SD.begin(SD_PIN)) | |
{ | |
Serial.println("Card failed, or not present"); | |
// don't do anything more: | |
return; | |
} | |
Serial.println("card initialized."); | |
} | |
/** | |
* [Blink description] | |
* @param PIN [description] | |
* @param DELAY_MS [description] | |
* @param loops [description] | |
*/ | |
void Blink(byte PIN, byte DELAY_MS, byte loops) { | |
for (byte i=0; i<loops; i++) | |
{ | |
digitalWrite(PIN,HIGH); | |
delay(DELAY_MS); | |
digitalWrite(PIN,LOW); | |
delay(DELAY_MS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment