Show Posts
Pages: [1]
1  Development / Other Software Development / Re: #include documentation on: June 05, 2012, 11:34:59 am
Thanks to everyone I finally got the #include sorted out.  I will post my suggested documentation clarifications here in this section in the hopes that someone updates the documentation.

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>
2  Using Arduino / Programming Questions / Re: Alarm.pde:-1: error: variable or field 'printAddress' declared void on: June 05, 2012, 11:30:22 am
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>
3  Development / Other Software Development / Re: #include documentation on: June 05, 2012, 10:59:45 am
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 ?
4  Using Arduino / Programming Questions / Re: Alarm.pde:-1: error: variable or field 'printAddress' declared void on: June 05, 2012, 10:56:57 am
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 ?
5  Development / Other Software Development / Re: #include documentation on: June 04, 2012, 08:03:49 pm
So... I'm afraid I'm still confused.
I have the .h in " " since they are in the same directory but they don't seem to be recognized by the compiler... so I assume that the "non-standard" stuff requires the use of < > but it doesn't seem to work with these either.

Should I use both?

#include <"OneWire.h">  ???
6  Development / Other Software Development / Re: #include documentation on: June 04, 2012, 06:41:51 pm
Probably best to just point you to the discussion where I am trying to work out this problem.

http://arduino.cc/forum/index.php/topic,108647.0.html

The code, errors and my efforts to fix them are documented there.

They tell me it's probably not the code but a problem with the includes... which I don't seem to be using properly.
7  Development / Other Software Development / #include documentation on: June 04, 2012, 06:30:50 pm
I'm trying to figure out how to use #include (as it doesn't seem to be working "intuitively").

I have my .h include files in the same directory as the sketch and have #include statements with < >.
Someone told me I should uses quotes " " but they still don't work although the .h files open up in tabs when I open the sketch.

Where do the include files go?
When should I use " " or < > ?
Can I use a path?
Is there a library?
How do I reference the library with includes?

The documentation on http://arduino.cc/it/Reference/Include is rather sparse.
8  Using Arduino / Programming Questions / Re: Alarm.pde:-1: error: variable or field 'printAddress' declared void on: June 04, 2012, 06:01:12 pm
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.
9  Using Arduino / Programming Questions / Re: Alarm.pde:-1: error: variable or field 'printAddress' declared void on: June 04, 2012, 05:15:18 pm
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?
10  Using Arduino / Programming Questions / Alarm.pde:-1: error: variable or field 'printAddress' declared void on: June 04, 2012, 04:47:11 pm
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.
Pages: [1]