problems to compile

Hello when i try to compile i get this error below:

sketch_jan17a.cpp.o: In function __static_initialization_and_destruction_0': C:\Users\RAPHAE~1.GUA\AppData\Local\Temp\build2873752566763016210.tmp/sketch_jan17a.cpp:6: undefined reference to ChipTemp::ChipTemp()’
sketch_jan17a.cpp.o: In function loop': C:\Users\RAPHAE~1.GUA\AppData\Local\Temp\build2873752566763016210.tmp/sketch_jan17a.cpp:15: undefined reference to ChipTemp::celsius()’
C:\Users\RAPHAE~1.GUA\AppData\Local\Temp\build2873752566763016210.tmp/sketch_jan17a.cpp:16: undefined reference to ChipTemp::deciCelsius()' C:\Users\RAPHAE~1.GUA\AppData\Local\Temp\build2873752566763016210.tmp/sketch_jan17a.cpp:17: undefined reference to ChipTemp::fahrenheit()’
C:\Users\RAPHAE~1.GUA\AppData\Local\Temp\build2873752566763016210.tmp/sketch_jan17a.cpp:18: undefined reference to `ChipTemp::deciFahrenheit()’

My code:

 #include <ChipTemp.h>

ChipTemp chipTemp;

void setup()
{ Serial.begin(9600);
  Serial.println("Celsius deciCelsius Fahrenheit deciFahrenheit");
}

void loop()
{ delay(1000);
  Serial.print(chipTemp.celsius()); Serial.print(" ");
  Serial.print(chipTemp.deciCelsius()); Serial.print(" ");
  Serial.print(chipTemp.fahrenheit()); Serial.print(" ");
  Serial.println(chipTemp.deciFahrenheit());
}

The CCP:

#include "ChipTemp.h"
#include <WProgram.h>

chipTemp::ChipTemp()
{
}

inline void ChipTemp::initialize()
{ ADMUX = 0xC8; // select reference, select temp sensor
  delay(10); // wait for the analog reference to stabilize
  readAdc(); // discard first sample (never hurts to be safe) 
}

inline int ChipTemp::readAdc()
{ ADCSRA |= _BV(ADSC); // start the conversion 
  while (bit_is_set(ADCSRA, ADSC)); // ADSC is cleared when the conversion finishes   
  return (ADCL | (ADCH << 8)); // combine bytes
}

int ChipTemp::deciCelsius()
{ long averageTemp=0;
  initialize(); // must be done everytime
  for (int i=0; i<samples; i++) averageTemp += readAdc();
  averageTemp -= offsetFactor;
  return averageTemp / divideFactor; // return deci degree Celsius
}

int ChipTemp::celsius()
{ return deciCelsius()/10;
}

int ChipTemp::deciFahrenheit()
{ return (9 * deciCelsius()+1600) / 5;
}

int ChipTemp::fahrenheit()
{ return (9 * deciCelsius()+1600) / 50; // do not use deciFahrenheit()/10;
}

My H

#ifndef ChipTemp_H
#define ChipTemp_H

// ATmega328 temperature sensor interface
// Rev 1.0 Albert van Dalen
// Based on "InternalTemp"
// Requires 166 ... 204 bytes program memory
// Resolution 0.1 degree

// Calibration values, set in decimals
static const float offset = 335.2; // change this!
static const float gain = 1.06154;

static const int samples = 1000; // must be >= 1000, else the gain setting has no effect

// Compile time calculations
static const long offsetFactor = offset * samples;
static const int divideFactor = gain * samples/10; // deci = 1/10

class ChipTemp
{
public:
  ChipTemp();
  int deciCelsius();
  int celsius();
  int deciFahrenheit();
  int fahrenheit();
 
private:  
  inline void initialize();
  inline int readAdc();
};

#endif

Thank’s for help =)

chipTemp::ChipTemp()

Case matters!

i changed the .cpp and get the same error:

the cpp

#ifndef ChipTemp_H
#define ChipTemp_H

// ATmega328 temperature sensor interface
// Rev 1.0 Albert van Dalen
// Based on "InternalTemp"
// Requires 166 ... 204 bytes program memory
// Resolution 0.1 degree

// Calibration values, set in decimals
static const float offset = 335.2; // change this!
static const float gain = 1.06154;

static const int samples = 1000; // must be >= 1000, else the gain setting has no effect

// Compile time calculations
static const long offsetFactor = offset * samples;
static const int divideFactor = gain * samples/10; // deci = 1/10

class ChipTemp
{
public:
  ChipTemp();
  int deciCelsius();
  int celsius();
  int deciFahrenheit();
  int fahrenheit();

private:  
  inline void initialize();
  inline int readAdc();
};

#endif

i changed the .cpp and get the same error:

the cpp

Really?

this is the cpp!

#include "ChipTemp.h"
#include <WProgram.h>

ChipTemp::ChipTemp()
{
}

inline void ChipTemp::initialize()
{ ADMUX = 0xC8; // select reference, select temp sensor
  delay(10); // wait for the analog reference to stabilize
  readAdc(); // discard first sample (never hurts to be safe) 
}

inline int ChipTemp::readAdc()
{ ADCSRA |= _BV(ADSC); // start the conversion 
  while (bit_is_set(ADCSRA, ADSC)); // ADSC is cleared when the conversion finishes   
  return (ADCL | (ADCH << 8)); // combine bytes
}

int ChipTemp::deciCelsius()
{ long averageTemp=0;
  initialize(); // must be done everytime
  for (int i=0; i<samples; i++) averageTemp += readAdc();
  averageTemp -= offsetFactor;
  return averageTemp / divideFactor; // return deci degree Celsius
}

int ChipTemp::celsius()
{ return deciCelsius()/10;
}

int ChipTemp::deciFahrenheit()
{ return (9 * deciCelsius()+1600) / 5;
}

int ChipTemp::fahrenheit()
{ return (9 * deciCelsius()+1600) / 50; // do not use deciFahrenheit()/10;
}

I put ChipTemp::ChipTemp() it is wrong?

I put ChipTemp::ChipTemp() it is wrong?

Not now.

When I compile your code, the only "error" I get is

Binary sketch size: 2692 bytes (of a 30720 byte maximum)

is possible you see the print screen?

i do not know what happens, if it is correct, what could be?

Well I can still see the same error in your main code. As PaulS says case matters.

hummm good =) the error changed to

C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp: In member function 'void ChipTemp::initialize()':
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:10: error: 'ADMUX' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:11: error: 'delay' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp: In member function 'int ChipTemp::readAdc()':
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:16: error: 'ADCSRA' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:16: error: 'ADSC' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:16: error: '_BV' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:17: error: 'bit_is_set' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:18: error: 'ADCL' was not declared in this scope
C:\Users\raphael.guarita\Desktop\arduino-1.0\libraries\ChipTemp\ChipTemp.cpp:18: error: 'ADCH' was not declared in this scope

What board are you compiling for?

You explicitly include WProgram.h, which does not exist for 1.0? Why?

You should be including Arduino.h!!!!

i’m compiling to Arduino UNO,

i tried use the Wprogram.H because u see here to debbuging

Debugging
Remember #include <WProgram.h>

You will get a series of errors if you've forgot to include the WProgram, and trying to use some of the Arduino functions or datatypes.
It is only necessary to include the WProgram.h in you library .h, your .cpp will include it because it includes your header.

Delete object file and recompile between each alteration of header and/or source

When changes are made in the header or the source, those changes are not automatically incorporated in the object file of you library. To be sure that your changes are compiled and used, delete the LED13.o and recompile a sketch in the Arduino IDE.

Learn to interpret the Arduino IDE debugger / compiler.

It can be a timesaver to take an hour and causing error deliberately, so you know what the error messages are caused by for later reference.

i get from: http://arduino.cc/playground/Code/Library#WProgram !!!

WOW with #include <Arduino.h> library works like a cute man!!

why i can’t use the WProgram ??

Thank’s

why i can't use the WProgram ??

Because it no longer exists seems like a good enough reason to me.

hehehe np, i just want to learn, if it is not important to learn, i do not care too, =)

PaulS - Many thank's for your greatful help! Grumpy_Mike thank's for you too =)