Issue with Data Logger Shield and FM Transmitter

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Darkwing
 
Posts: 7
Joined: Sat May 24, 2014 4:32 pm

Issue with Data Logger Shield and FM Transmitter

Post by Darkwing »

I am trying to record the fm signal strengths on my way to work, so I can find the best station to set my fm transmitter to. I have the SI4713 FM Radio Transmitter hooked up to the Adafruit data logger shield. I frankensteined the Adaradio and the data logger code together.

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);
The radio code works when I add all of the RTC code. After slowly adding the SD code from the top of the sketch down, I found out that it starts to hang after

Code: Select all

if (!SD.begin(chipSelect)) {
        error("Card failed, or not present");
    }
More specifically the SD.begin(chipSelect). I am at a loss as to why the SD.begin causes the radio.readTuneMeasure to hang up.

Any thoughts of insights would be greatly appreciated.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Issue with Data Logger Shield and FM Transmitter

Post by adafruit_support_mike »

Could you post a photo showing your hardware and connections please? 800x600 images usually work best.

User avatar
Darkwing
 
Posts: 7
Joined: Sat May 24, 2014 4:32 pm

Re: Issue with Data Logger Shield and FM Transmitter

Post by Darkwing »

Image

I apologize for the same color wires.
The connections are:
- Arduino D12 to Radio RST
- Arduino SDA to Radio SDA
- Arduino SCL to Radio SCL
- Arduino 5v to Radio Vin
- Arduino Gnd to Radio GND

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Issue with Data Logger Shield and FM Transmitter

Post by adafruit_support_bill »

It sounds like a possible stack-crash. As soon as you start to use in the SD library, it will allocate a 512byte block buffer in SRAM for the card. SRAM is a fairly limited resource in the Arduino. The UNO has only 2K available.

This guide has some tips on diagnosing memory problems and some optimizations that can help.
http://learn.adafruit.com/memories-of-an-arduino

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”