Code: Select all
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_Si4713.h>
#include "RTClib.h"
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
#define RESETPIN 12 //reset pin for adafruit radio SI713
Adafruit_Si4713 radio = Adafruit_Si4713(RESETPIN);
RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
while(1);
}
void setup(void)
{
Serial.begin(9600);
Serial.println();
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
Serial.println("Adafruit Radio - Si4713 Test");
if(! radio.begin()) { //begin with address 0x63 (CS high default)
logfile.println("Couldn't find radio?");
Serial.println("Couldn't find radio?");
while(1);
}
logfile.println("unix time,date/time,station,signal strength");
#if ECHO_TO_SERIAL
Serial.println("unix time,date/time,station,signal strength");
#endif //ECHO_TO_SERIAL
}
void loop()
{
DateTime now;
for (uint16_t f = 8750; f<10800; f+=10) {
// fetch the time
now = RTC.now();
// log time
logfile.print(now.unixtime()); // seconds since 1/1/1970
logfile.print(", ");
logfile.print('"');
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
logfile.print('"');
logfile.flush();
#if ECHO_TO_SERIAL
Serial.print(now.unixtime()); // seconds since 1/1/1970
Serial.print(", ");
Serial.print('"');
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.print('"');
#endif //ECHO_TO_SERIAL
Serial.print(1);
radio.readTuneMeasure(f);
Serial.print(2);
logfile.print(f);
Serial.print(3);
Serial.print(f);
logfile.print(", ");
Serial.print(", ");
radio.readTuneStatus();
logfile.print(radio.currNoiseLevel);
Serial.print(radio.currNoiseLevel);
logfile.println();
Serial.println();
logfile.flush();
delay(1000);
}
}
The Adaradio sketch with the signal sweep enabled works fine. The data logger sketch works fine and creates a usable csv. However, the sketch above hangs at:
Code: Select all
radio.readTuneMeasure(f);
Code: Select all
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
}
Any thoughts of insights would be greatly appreciated.