user26782: I have written code to read temperatures on a motor which also has pulse feedback to see speed, (one hall sensor) and my previous version of the code does work fine, however when i add example frequency code from codebender into my code it doesn't give feedback on the frequency. Standalone the frequency code works fine. Is there any obvious failure in the code or is there just some conflict between files in library? 
Trying to return RPM into the SD card results in 0.00. And the temperature measurements goes into switching between 85C and -127C.
Equipment: Arduino Nano, DS18B20, 2x16 LCD, Homemade SD shield, motor with internal motordriver.
Here is my code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <SD.h>
#include <FreqMeasure.h>

// Data wire is plugged into pin 9 on the Arduino
#define ONE_WIRE_BUS 9

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

float temperature1, temperature2, temperature3;
double RPM;
void setup(void)
{
  // start serial port
  Serial.begin(57600);
  FreqMeasure.begin();
  Serial.println("Dallas Temperature IC Control Library Demo");
  // Start up the library
  lcd.begin(16, 2);
  sensors.begin();
  Serial.print("Initializing SD card...");      // Initialize SD card

  if (!SD.begin(10)) {                          
    Serial.println("initialization failed!");   // Initialize SD card failed
    return;                                     
  }
  Serial.println("initialization done.");       // Initialize SD card done
}

double sum=0;
int count=0;

void loop(void)
{
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      double frequency = F_CPU / (sum / count);
      RPM=frequency*60;
      sum = 0;
      count = 0;
    }
  }

  unsigned long curMillis = millis();  
  unsigned long curSeconds = curMillis/1000;   // Get current seconds
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  temperature1=sensors.getTempCByIndex(0);
  temperature2=sensors.getTempCByIndex(1);
  temperature3=sensors.getTempCByIndex(2);
  logData();
  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
  Serial.print("Temperature for Device 2 is: ");
  Serial.print(sensors.getTempCByIndex(1));
  Serial.print("Temperature for Device 3 is: ");
  Serial.println(sensors.getTempCByIndex(2));

  lcd.setCursor(0, 0);
  lcd.print("T1=");
  lcd.setCursor(3, 0);
  lcd.print(sensors.getTempCByIndex(0));
  lcd.setCursor(8, 0);
  lcd.print("T2=");
  lcd.setCursor(11, 0);
  lcd.print(sensors.getTempCByIndex(1));
  lcd.setCursor(0, 1);
  lcd.print("T3=");
  lcd.setCursor(3, 1);
  lcd.print(sensors.getTempCByIndex(2));
  lcd.setCursor(8, 1);
  lcd.print("S=");
  lcd.setCursor(10, 1);
  lcd.print(curSeconds);
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire

}

void logData() {
  Serial.print("Temperature1 = ");   Serial.print(temperature1);    // Printing to serial communication
  Serial.print(" C, Temperature2 = ");  Serial.print(temperature2);       // Printing to serial communication
  Serial.print(" C, Temperature3 = ");  Serial.print(temperature3);       // Printing to serial communication
  Serial.println(" C");                                           // Printing to serial communication
  Serial.println(RPM);
  unsigned long curMillis = millis();          // Get current time
  unsigned long curSeconds = curMillis/1000;   // Get current seconds

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File myFile = SD.open("LOG.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to LOG.txt...");                        // Printing to serial communication
    myFile.print("Time = "); myFile.print(curSeconds);            // Printing to log file on sd card
    myFile.print(" Temperature1 = "); myFile.print(temperature1);   // Printing to log file on sd card
    myFile.print(" Temperature2 = "); myFile.print(temperature2);         // Printing to log file on sd card
    myFile.print(" Temperature3 = "); myFile.print(temperature3);       // Printing to log file on sd card
    myFile.print(" RPM = "); myFile.println(RPM);       // Printing to log file on sd card
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening LOG.txt");                      // Error either SD card not connected or not detected
  }
  delay(1000);
}


user19867: I believe there is a conflict bewteen the code relative to the SD card, which uses SPI and the use of timer1 within FreqMeasure.
My advice is to temporarily remove the code for the SD card and write that data onto the serial console: if the data displays correctly on the serial monitor than you have an indication the issue is in there.
The problem with SPI and time based interrupts is the latter might prevent the SPI communication to properly complete.

26782: <p>I have written code to read temperatures on a motor which also has pulse feedback to see speed, (one hall sensor) and my previous version of the code does work fine, however when i add example frequency code from <a href="https://codebender.cc/example/FreqMeasure/LCD_Output#LCD_Output.ino" rel="nofollow">codebender</a> into my code it doesn't give feedback on the frequency. Standalone the frequency code works fine. Is there any obvious failure in the code or is there just some conflict between files in library? </p>

<p>Trying to return RPM into the SD card results in 0.00. And the temperature measurements goes into switching between 85C and -127C.</p>

<p>Equipment: Arduino Nano, DS18B20, 2x16 LCD, Homemade SD shield, motor with internal motordriver.</p>

<p>Here is my code:</p>

<pre><code>#include &lt;OneWire.h&gt;
#include &lt;DallasTemperature.h&gt;
#include &lt;LiquidCrystal.h&gt;
#include &lt;SD.h&gt;
#include &lt;FreqMeasure.h&gt;

// Data wire is plugged into pin 9 on the Arduino
#define ONE_WIRE_BUS 9

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&amp;oneWire);

float temperature1, temperature2, temperature3;
double RPM;
void setup(void)
{
  // start serial port
  Serial.begin(57600);
  FreqMeasure.begin();
  Serial.println("Dallas Temperature IC Control Library Demo");
  // Start up the library
  lcd.begin(16, 2);
  sensors.begin();
  Serial.print("Initializing SD card...");      // Initialize SD card

  if (!SD.begin(10)) {                          
    Serial.println("initialization failed!");   // Initialize SD card failed
    return;                                     
  }
  Serial.println("initialization done.");       // Initialize SD card done
}

double sum=0;
int count=0;

void loop(void)
{
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count &gt; 30) {
      double frequency = F_CPU / (sum / count);
      RPM=frequency*60;
      sum = 0;
      count = 0;
    }
  }

  unsigned long curMillis = millis();  
  unsigned long curSeconds = curMillis/1000;   // Get current seconds
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  temperature1=sensors.getTempCByIndex(0);
  temperature2=sensors.getTempCByIndex(1);
  temperature3=sensors.getTempCByIndex(2);
  logData();
  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
  Serial.print("Temperature for Device 2 is: ");
  Serial.print(sensors.getTempCByIndex(1));
  Serial.print("Temperature for Device 3 is: ");
  Serial.println(sensors.getTempCByIndex(2));

  lcd.setCursor(0, 0);
  lcd.print("T1=");
  lcd.setCursor(3, 0);
  lcd.print(sensors.getTempCByIndex(0));
  lcd.setCursor(8, 0);
  lcd.print("T2=");
  lcd.setCursor(11, 0);
  lcd.print(sensors.getTempCByIndex(1));
  lcd.setCursor(0, 1);
  lcd.print("T3=");
  lcd.setCursor(3, 1);
  lcd.print(sensors.getTempCByIndex(2));
  lcd.setCursor(8, 1);
  lcd.print("S=");
  lcd.setCursor(10, 1);
  lcd.print(curSeconds);
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire

}

void logData() {
  Serial.print("Temperature1 = ");   Serial.print(temperature1);    // Printing to serial communication
  Serial.print(" C, Temperature2 = ");  Serial.print(temperature2);       // Printing to serial communication
  Serial.print(" C, Temperature3 = ");  Serial.print(temperature3);       // Printing to serial communication
  Serial.println(" C");                                           // Printing to serial communication
  Serial.println(RPM);
  unsigned long curMillis = millis();          // Get current time
  unsigned long curSeconds = curMillis/1000;   // Get current seconds

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File myFile = SD.open("LOG.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to LOG.txt...");                        // Printing to serial communication
    myFile.print("Time = "); myFile.print(curSeconds);            // Printing to log file on sd card
    myFile.print(" Temperature1 = "); myFile.print(temperature1);   // Printing to log file on sd card
    myFile.print(" Temperature2 = "); myFile.print(temperature2);         // Printing to log file on sd card
    myFile.print(" Temperature3 = "); myFile.print(temperature3);       // Printing to log file on sd card
    myFile.print(" RPM = "); myFile.println(RPM);       // Printing to log file on sd card
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening LOG.txt");                      // Error either SD card not connected or not detected
  }
  delay(1000);
}
</code></pre>
 19867: <p>I believe there is a conflict bewteen the code relative to the SD card, which uses <code>SPI</code> and the use of timer1 within <code>FreqMeasure</code>.</p>

<p>My advice is to temporarily remove the code for the SD card and write that data onto the serial console: if the data displays correctly on the serial monitor than you have an indication the issue is in there.</p>

<p>The problem with SPI and time based interrupts is the latter might prevent the SPI communication to properly complete.</p>
