Pages: [1]   Go Down
Author Topic: Alarm.pde:-1: error: variable or field 'printAddress' declared void  (Read 3503 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new and trying run the sample code for the Dalas OneWire devices.
I have tried several of the examples (Alarm, address_finder and others) and they all end up with the same type of errors.
Alarm.pde:-1: error: variable or field 'printAddress' declared void
Alarm.pde:-1: error: 'DeviceAddress' was not declared in this scope
Alarm.pde:-1: error: variable or field 'printTemperature' declared void
Alarm.pde:-1: error: 'DeviceAddress' was not declared in this scope
Alarm.pde:-1: error: variable or field 'printData' declared void
Alarm.pde:-1: error: 'DeviceAddress' was not declared in this scope

"OneWire does not name a type
I am using the latest versions of the libraries from the Dallas site and the latest Arduino software (v 1.0.1)
I have the .h files in the same folder as the sketch.

Code:
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

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

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  
  // locate devices on the bus
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // search for devices on the bus and assign based on an index.
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  Serial.print("Device 0 Alarms: ");
  printAlarms(insideThermometer);
  Serial.println();
  
  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();

  Serial.print("Device 1 Alarms: ");
  printAlarms(outsideThermometer);
  Serial.println();
  
  Serial.println("Setting alarm temps...");

  // alarm when temp is higher than 30C
  sensors.setHighAlarmTemp(insideThermometer, 30);
  
  // alarm when temp is lower than -10C
  sensors.setLowAlarmTemp(insideThermometer, -10);
  
  // alarm when temp is higher than 31C
  sensors.setHighAlarmTemp(outsideThermometer, 31);
  
  // alarn when temp is lower than 27C
  sensors.setLowAlarmTemp(outsideThermometer, 27);
  
  Serial.print("New Device 0 Alarms: ");
  printAlarms(insideThermometer);
  Serial.println();
  
  Serial.print("New Device 1 Alarms: ");
  printAlarms(outsideThermometer);
  Serial.println();
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
}

void printAlarms(uint8_t deviceAddress[])
{
  char temp;
  temp = sensors.getHighAlarmTemp(deviceAddress);
  Serial.print("High Alarm: ");
  Serial.print(temp, DEC);
  Serial.print("C/");
  Serial.print(DallasTemperature::toFahrenheit(temp));
  Serial.print("F | Low Alarm: ");
  temp = sensors.getLowAlarmTemp(deviceAddress);
  Serial.print(temp, DEC);
  Serial.print("C/");
  Serial.print(DallasTemperature::toFahrenheit(temp));
  Serial.print("F");
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}

void checkAlarm(DeviceAddress deviceAddress)
{
  if (sensors.hasAlarm(deviceAddress))
  {
    Serial.print("ALARM: ");
    printData(deviceAddress);
  }
}

void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  // Method 1:
  // check each address individually for an alarm condition
  checkAlarm(insideThermometer);
  checkAlarm(outsideThermometer);
/*
  // Alternate method:
  // Search the bus and iterate through addresses of devices with alarms
  
  // space for the alarm device's address
  DeviceAddress alarmAddr;

  Serial.println("Searching for alarms...");
  
  // resetAlarmSearch() must be called before calling alarmSearch()
  sensors.resetAlarmSearch();
  
  // alarmSearch() returns 0 when there are no devices with alarms
  while (sensors.alarmSearch(alarmAddr))
  {
    Serial.print("ALARM: ");
    printData(alarmAddr);
  }
*/

}


Moderator edit: [code] [/code] tags added.
« Last Edit: June 04, 2012, 04:48:38 pm by Coding Badly » Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3434
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have the .h files in the same folder as the sketch.
In that case, your includes should be double quotes rather than less/greater than:

Code:
#include "SomeLibrary.h"
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for this information.
I changed my examples and the verify got further (looks like it's a multiple pass compiler)...

Now I get:
Alarm.cpp.o: In function `__static_initialization_and_destruction_0':
Alarm.cpp:16: undefined reference to `OneWire::OneWire(unsigned char)'
Alarm.cpp:19: undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'
Alarm.cpp.o: In function `printAlarms(unsigned char*)':
Alarm.cpp:105: undefined reference to `DallasTemperature::getHighAlarmTemp(unsigned char*)'

(many more like this...)

I can't believe that I'm having this much trouble with the manufacturer provided "Examples".

BTW, what's the difference between the < > and " " ?  Where does it look for includes?
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3434
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for this information.
I changed my examples and the verify got further (looks like it's a multiple pass compiler)...

Now I get:
Alarm.cpp.o: In function `__static_initialization_and_destruction_0':
Alarm.cpp:16: undefined reference to `OneWire::OneWire(unsigned char)'
Alarm.cpp:19: undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'
Alarm.cpp.o: In function `printAlarms(unsigned char*)':
Alarm.cpp:105: undefined reference to `DallasTemperature::getHighAlarmTemp(unsigned char*)'

(many more like this...)
Looks like you don't have the actually source files for the library in your folder. Why not simply add the entire folder, unmodified, to your libraries folder?

Quote
I can't believe that I'm having this much trouble with the manufacturer provided "Examples".
Not sure why you seem to have disdain towards the developers, It's not a problem with their code.

Quote
BTW, what's the difference between the < > and " " ?  Where does it look for includes?
http://msdn.microsoft.com/en-us/library/36k2cdd4(v=vs.80).aspx
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for this help.

The Arduino IDE doesn't seem to have a problem finding the .h files since it opens them up in separate tabs with the sketch window automatically when I open the sketch.

A "Library" folder sounds like a good idea.  Where is it?  The documentation is silent on this subject (and also silent on the use of " " ... it only covers the < > and the one example it gives shows part of a path which is odd).

I don't have "disdain" towards the developers.  I am just frustrated that there are not better instructions.  If they are putting together "Examples", I would expect them to be more complete.  I always assume that it is my problem and lack of understanding, not theirs. I am sure that as soon as I am as smart as the developers, everything will work just fine.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In http://arduino.cc/en/Reference/Libraries

you will find:

"Contributed Libraries

If you're using one of these libraries, you need to install it first. To do so, download the library and unzip it. It should be in a folder of its own, and will typically contain at least two files, one with a .h suffix and one with a .cpp suffix. Open your Arduino sketchbook folder. If there is already a folder there called libraries, place the library folder in there. If not, create a folder called libraries in the sketchbook folder, and drop the library folder in there. Then re-start the Arduino programming environment, and you should see your new library in the Sketch > Import Library menu. "
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3434
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(and also silent on the use of " " ... it only covers the < > and the one example it gives shows part of a path which is odd).
That's because you typically use angle brackets when you download and use a library with Arduino's provided utilities. Unless you are making your own library or modifying one, there isn't a need for double quotes. If you are making your own library, it's assumed that you have some experience with C/C++, where the include directive is a basic concept.
« Last Edit: June 05, 2012, 09:39:02 am by Arrch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems to me that there should be some straightforward way to handle #include but I am having a very difficult time figuring it out and the documentation is very sparse.

So far, very helpful people have told me that I need to have a "libraries" folder in the same folder as my sketches.  So on my Mac, the Arduino IDE puts my sketches in a folder: Documents/Arduino
I have my sketches in this folder... the first is a sample project "Alarm" which is in: Documents/Arduino/Alarm
I created a folder: Documents/Arduino/libraries
I put the OneWire .h files in: Documents/Arduino/libraries/OneWire
I have these lines in the "Alarm" sketch:

#include <OneWire/OneWire.h>
#include <OneWire/DallasTemperature.h>

From what I have been told, this should work, but it doesn't.  I get these errors:
Alarm:1: error: variable or field 'printAddress' declared void
Alarm:1: error: 'DeviceAddress' was not declared in this scope
Alarm:2: error: variable or field 'printTemperature' declared void
Alarm:2: error: 'DeviceAddress' was not declared in this scope
... etc.

Is there some clear, complete documentation somewhere on how to use the #include ?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <OneWire/OneWire.h>
#include <OneWire/DallasTemperature.h>
You shouldn't need the 'OneWire/' part.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I put the OneWire .h files in: Documents/Arduino/libraries/OneWire

I have these lines in the "Alarm" sketch:

#include <OneWire/OneWire.h>
#include <OneWire/DallasTemperature.h>



You need not just the .h files but the associated .cpp files as well in the same folder as the .h files

Further, I believe that you have tried to combine two libraries into a single directory.  You should have a

Documents/Arduino/libraries/OneWire

which would contain
Documents/Arduino/libraries/OneWire/OneWire.h
Documents/Arduino/libraries/OneWire/OneWire.cpp

and

Documents/Arduino/libraries/DallasTemperature

should contain
Documents/Arduino/libraries/DallasTemperature/DallasTemperature.h
Documents/Arduino/libraries/DallasTemperature/DallasTemperature.cpp

and then your includes should look like:

#include <OneWire.h>
#include <DallasTemperature.h>
« Last Edit: June 05, 2012, 11:03:29 am by wanderson » Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3434
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there some clear, complete documentation somewhere on how to use the #include ?

http://arduino.cc/en/Guide/Environment#libraries
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just installed the two libraries on my machine and noticed, a couple of issues that will cause you problems.

First, the DallasTemperature library is a beta, which means that it may (probably will) contain bugs that prevent it from working as describe in some cases.  Further, the zip file I obtained does not correctly name the subdirectory for the files.  It created a directory called dallas-temperature-control.  That directory will need to be renamed to DallasTemperature

After properly installing your sketchbook structure should have the following

Code:
.:
Alarm
libraries

./Alarm:
Alarm.ino

./libraries:
DallasTemperature
OneWire

./libraries/DallasTemperature:
change.txt
DallasTemperature.cpp
DallasTemperature.h
examples
keywords.txt
README.TXT

./libraries/DallasTemperature/examples:
Alarm
AlarmHandler
Multiple
Simple
Single
Tester
WaitForConversion
WaitForConversion2

./libraries/DallasTemperature/examples/Alarm:
Alarm.pde

./libraries/DallasTemperature/examples/AlarmHandler:
AlarmHandler.pde

./libraries/DallasTemperature/examples/Multiple:
Multiple.pde

./libraries/DallasTemperature/examples/Simple:
Simple.pde

./libraries/DallasTemperature/examples/Single:
Single.pde

./libraries/DallasTemperature/examples/Tester:
Tester.pde

./libraries/DallasTemperature/examples/WaitForConversion:
WaitForConversion.pde

./libraries/DallasTemperature/examples/WaitForConversion2:
WaitForConversion2.pde

./libraries/OneWire:
examples
keywords.txt
OneWire.cpp
OneWire.h

./libraries/OneWire/examples:
DS18x20_Temperature
DS2408_Switch
DS250x_PROM

./libraries/OneWire/examples/DS18x20_Temperature:
DS18x20_Temperature.pde

./libraries/OneWire/examples/DS2408_Switch:
DS2408_Switch.pde

./libraries/OneWire/examples/DS250x_PROM:
DS250x_PROM.pde

Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks to everyone for your help.
I finally got the code to successfully verify.

I would suggest that the #include documentation (http://arduino.cc/en/Reference/Include) be updated... something like:

#include
You can add libraries from third parties by downloading and unzipping the libraries into a folder called "libraries" which should be created in the same folder as your sketches. (On a Mac, the default is: Documents/Arduino/ and the folder should be created Documents/Arduino/libraries).  There should be a separate sub-directory of libraries for each contributed library (Documents/Arduino/libraries/yourlibrary). These sub-directories should contain .h and .cpp files.  

After you restart the Arduino IDE, these libraries will show up under the menu Sketch - Import Library - Contributed section.
 (I don't know where the other built-in libraries are but I guess I don't need to know.)

You can use these libraries by choosing the menu option Sketch - Import Library and choosing a library.  This will put the statement at the start of your sketch:
#include <yourlibrary.h>
Logged

Pages: [1]   Go Up
Jump to: