I am trying to record GPS using the Adafruit ultimate gps breakout at 10 Hz and two Adafruit rfm69 transmitters running at ~8 Hz. GPS and radios work separately and record to the builtin SD card so it appears the conflict is between the radio and the gps. (In loop() I comment out the eight GPS lines or all the other lines) It will run through a few cycles then hang, usually when the gps should read, then the serial monitor goes offline and I have to push the program button to upload again. I tried putting "noInterrupts" before the gps while statement (and interrupts afterwards) but that won't compile.
I am using windows 10, IDE 1.8.1, and gps code clipped out of the Adafruit example.
Thanks for any help.
I am using windows 10, IDE 1.8.1, and gps code clipped out of the Adafruit example.
Thanks for any help.
HTML:
/*
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GPS.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
//Match frequency to the hardware version of the radio on your Feather
#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 9600
// for Feather M0
#define RFM69_CS 10
#define RFM69_IRQ 14
#define RFM69_IRQN 14
#define RFM69_RST 15
Sd2Card card;
SdVolume volume;
SdFile root;
char c;//This will read the NMEA sentence as a series of characters.
String NMEA1;String Sgps;
String Slat;String Slong;String Sspd;String Sang;
String S1;String Stime;
String TotStr;
Adafruit_GPS GPS(&Serial1);
#define GPSECHO true
#define LOG_FIXONLY false
boolean usingInterrupt = false;//I should learn to use interrupts
void useInterrupt(boolean); byte i;
File myFile;
const int chipSelect = BUILTIN_SDCARD;
RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
byte Tin; byte Tcent; byte Tout; byte nit=0;char charNam[10]="SD100.txt";
int tim;byte k1;byte k2;unsigned long reft;
//________________________________________________________________
void setup() {
Serial.begin(SERIAL_BAUD);
delay(5000);
Serial.println("Feather RFM69HCW Receiver");
// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);
// Initialize radio
if (radio.initialize(FREQUENCY, NODEID, NETWORKID)) {
Serial.print("radio initialized ");
}
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)
radio.encrypt(ENCRYPTKEY);
Serial.print("\nListening at ");
Serial.print(FREQUENCY == RF69_433MHZ ? 433 : FREQUENCY == RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");
pinMode(8, OUTPUT); pinMode(10, OUTPUT);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
tim=micros();
byte SDx= tim%(tim/1000);
Serial.println(tim);
Serial.println(SDx);
randomSeed(SDx);
byte randNumber=(random(65,85));
Serial.println(randNumber);
charNam[2]=randNumber;
charNam[4]=65;
myFile = SD.open(charNam, FILE_WRITE);delay(1000);
byte GPSon=1;
if (GPSon==1){
GPS.begin(9600);//Base baud rate so we can talk to gps
Serial.println("start gps");
delay(1000);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);delay(100);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ); delay(100);
GPS.sendCommand(PGCMD_NOANTENNA);delay(100);
GPS.sendCommand(PMTK_SET_BAUD_57600);delay(100);//Can go to adafruit_gps.h to see these settings
delay(1000);
Serial1.end();delay(100);//Terminate Serial1 then open at the set baud rate
Serial1.begin(57600);delay(100);
GPS.begin(57600);delay(100);
Serial.println("gps restarted");
}
}
//____________________________________________________________________
void loop()
{
// Serial.print(millis());
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c=GPS.read(); //read a character from the GPS
//Serial.print(c);
}
// Serial.print(millis());
NMEA1=GPS.lastNMEA();
Serial.println(NMEA1);myFile.println(NMEA1);
reft=millis();
while(millis()-reft<80)
{
//check if something was received (could be an interrupt from the radio)
if (radio.receiveDone())
{
Serial.print(millis()); Serial.print(",");
Serial.print(radio.RSSI);Serial.print(",");
Serial.print(radio.SENDERID);
for(k1=0;k1<6;k1++){
Serial.print(",");
Serial.print(radio.DATA[k1]);
Serial.print(radio.DATA[k1]);
}
Serial.println("");myFile.println(".");
}
}
if (millis()/(nit+1) > 180000)
{
myFile.close();delay(100);
nit++;Serial.println(nit);
Serial.println("file closed");
charNam[4]++;
if (charNam[4]==90)
{
charNam[4]=65;
charNam[2]++;
}
Serial.println(charNam);
myFile = SD.open(charNam, FILE_WRITE);
delay(100);
}
}