SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By dpicts
#129381
I have the following code that will not compile and I cannot figure out what I am doing wrong:
I get the following errors when attempting to compile:
Serial_Output.cpp: In function 'void setup()':
Serial_Output:6: error: 'FreqMeasure' was not declared in this scope
Serial_Output.cpp: In function 'void loop()':
Serial_Output:13: error: 'FreqMeasure' was not declared in this scope
Code: Select all
#include <FreqMeasure.h>

void setup() 
{
  Serial.begin(57600);
  FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      double frequency = F_CPU / (sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }
  }
}
In the same folder are capture.h, FreqMeasure.cpp, and FreqMeasure.h
FreqMeasure.h:
Code: Select all
#ifndef FreqMeasure_h
#define FreqMeasure_h

#include <inttypes.h>

class FreqMeasureClass {
public:
	static void begin(void);
	static uint8_t available(void);
	static uint32_t read(void);
	static void end(void);
};

extern FreqMeasureClass FreqMeasure;

#endif
FreqMeasure.cpp (I removed the contents of the procedures/functions to save space, but I can post them if needed):
Code: Select all
#include "FreqMeasure.h"
#include "capture.h"

#define FREQMEASURE_BUFFER_LEN 12
static volatile uint32_t buffer_value[FREQMEASURE_BUFFER_LEN];
static volatile uint8_t buffer_head;
static volatile uint8_t buffer_tail;
static uint16_t capture_msw;
static uint32_t capture_previous;

void FreqMeasureClass::begin(void)
{	...   }

uint8_t FreqMeasureClass::available(void)
{	...   }

uint32_t FreqMeasureClass::read(void)
{	...   }

void FreqMeasureClass::end(void)
{	...   }

ISR(TIMER_OVERFLOW_VECTOR)
{	...   }

ISR(TIMER_CAPTURE_VECTOR)
{	...   }

FreqMeasureClass FreqMeasure;
Sure I must be doing something stupid, but this has my project stalled so any help would be appreciated.
Dpicts
By esklar81
#129385
dpicts,

The writeup I found for FreqMeasure says it for Teensy processors, but you've posted you query to an Arduino forum. If you're trying to run it on an Arduino, have you looked at the instructions to which that page points for porting the library? If you're trying to run it on something other than an Arduino, you might be better served asking in a forum specific to your hardware.

Good Luck,
Eric
By dpicts
#129386
Actually the code is for the Teensyduino (basically Arduino code run on a Teensy)... I am using a Teensy, but that should have zero relevance on the problem I am having as it is a compile issue under the Arduino environment (not a hardware issue.)
By esklar81
#129388
dpicts,

I accept that a failure to compile is independent of the hardware to which you are intending to load the resulting binary file.

However, you don't appear to have addressed the matter of the library you are trying to include having been written for Teensy. That is, there appears to be an inconsistency between for what the library was written and for what you are trying to compile it.

Have you tried different device type settings within the Arduino IDE? It may be that the library works as-is with only some flavors of Arduino, but requires porting for others.

Eric