Go Down

Topic: [SOLVED] OneWire.h not playing nice with other libraries (Read 118 times) previous topic - next topic

JohnnyKnowing

May 28, 2015, 11:31 pm Last Edit: May 31, 2015, 12:19 am by JohnnyKnowing Reason: Updating to solved
Hello Arduinoites!

I would love your help in figuring out how I can either fix, or work around an issue that I am running into with using the OneWire library.

I am creating a system to control the lights on my hydroponics system.  I have a working program that integrates an RTC and a 64x128 LCD screen with some buttons that allow me to set the on and off times from the unit itself.

The problem that I am running into is that I now want to add some thermometers to the system.  I got some onewire thermometers Vktech-Waterproof-Digital-Temperature and have got them working using the OneWire.h and DallasTemperature.h libraries using some of the example sketches.

However, when I combine integrate the example sketch into my original sketch I get an error that a particular function in the OneWire.h was not declared (more on this is a sec).

I did a lot of commenting out of my code and narrowed it down to two specific commands from the Adafruit_SSD1306.h and the RTClib.h.

Here is the relevant section of the code, it includes the top part of the sketch, along with the function that problem is occurring in

Code: [Select]



/////////////Time///////////
#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeAlarms.h>
RTC_DS1307 RTC;

/////////LCD/////////////////////
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


////////Temp////////////////////////


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

#define ONE_WIRE_BUS_PIN 8

OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

DeviceAddress Probe01 = { 0x28, 0xD7, 0x25, 0x89, 0x06, 0x00, 0x00, 0xEE };
DeviceAddress Probe02 = { 0x28, 0xCC, 0x92, 0x40, 0x04, 0x00, 0x00, 0xB6 };



////////////////////////////////////////////////////////////

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   Serial.print(" F: ");
   Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}






When I run this code as is I get this error:

Hydro-Control2.0:20: error: variable or field 'printTemperature' declared void
Hydro-Control2.0:20: error: 'DeviceAddress' was not declared in this scope
variable or field 'printTemperature' declared void

particularly it is the DeviceAddress that is giving me trouble, because it has been declared (at least I hope that it is).

The plot thickens when I comment out these parts of the above code

Code: [Select]

//RTC_DS1307 RTC;


//Adafruit_SSD1306 display(OLED_RESET);



when I comment out those lines it compiles just fine and the thermometers work well.

I have tried commenting out just one of the two lines but it still give me the same error, so it is not either one of them in particular.  


I found someone else with a similar problem but their solution did not work for me.

Any advice would be amazing.  at the moment I am assuming that the librarys do not play nice with each other and I should set up a two arduino solution.

Thanks!


PaulS


Nick Gammon

Try adding a function prototype for printTemperature like this:

Code: [Select]

void printTemperature(DeviceAddress deviceAddress);   // function prototype
void printTemperature(DeviceAddress deviceAddress)
{
...
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

JohnnyKnowing

Thanks.  I will give it a try when I get home

JohnnyKnowing

I suggest that you visit http://snippets-r-us.com with your snippets.
Thanks.  My code was too big so picked it the relevant parts,  the above code does run on its own but I now know how to include the entire sketch and libraries to my post.   Thanks

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

JohnnyKnowing

Thank you all for your help so far,

Here is the update

Currently, with the code as it was, I get these errors

Code: [Select]
Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Uno"

Hydro-Control2.0:40: error: variable or field 'printTemperature' declared void
Hydro-Control2.0:40: error: 'DeviceAddress' was not declared in this scope
Hydro-Control2.0.ino: In function 'void loop()':
Hydro-Control2.0:134: error: 'printTemperature' was not declared in this scope
variable or field 'printTemperature' declared void



If I add the function prototype (Thanks Nick) like so:

Code: [Select]

void printTemperature(DeviceAddress deviceAddress);
void printTemperature(DeviceAddress deviceAddress)
{


I get these errors:

Code: [Select]


Hydro-Control2.0.ino: In function 'void loop()':
Hydro-Control2.0:134: error: 'printTemperature' was not declared in this scope
'printTemperature' was not declared in this scope


This seemed to fix the "DeviceAddress" error but I am still getting the "printTemperature not declared" error. 

I have attached the sketch (with the function prototype added) and the needed libraries. I would love any advice on what to do next

Thanks!
Johnny

PaulS

#7
May 30, 2015, 03:48 pm Last Edit: May 30, 2015, 03:49 pm by PaulS
The function prototype has to come BEFORE the first call to the function.

And, you can't call a function that takes an argument without supplying an argument.

JohnnyKnowing

Thank you for pointing out the missing argument (oops).

What is the best place to put the function prototype?  When I put it above the setup function it does not seem to help.

Either way, when I take out everyting in the code except for the lines pertaining to the temp and onewire, it compiles just fine.

Code: [Select]

////////Temp////////////////////////


#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_PIN 8
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

DeviceAddress Probe01 = { 0x28, 0xD7, 0x25, 0x89, 0x06, 0x00, 0x00, 0xEE };
//DeviceAddress Probe02 = { 0x28, 0xCC, 0x92, 0x40, 0x04, 0x00, 0x00, 0xB6 };
//DeviceAddress Probe03 = { 0x28, 0x4D, 0x8D, 0x40, 0x04, 0x00, 0x00, 0x78 };
//DeviceAddress Probe04 = { 0x28, 0x9A, 0x80, 0x40, 0x04, 0x00, 0x00, 0xD5 };
//DeviceAddress Probe05 = { 0x28, 0xE1, 0xC7, 0x40, 0x04, 0x00, 0x00, 0x0D };



void setup() { 

  ///////////Temp Setup////////////
  // start serial port to show results
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
 
  // Initialize the Temperature measurement library
  sensors.begin();
 
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  //sensors.setResolution(Probe02, 10);

}
 
//////////////////////////////////////////////////////////////////////////////

void loop() {

  printTemperature(Probe01);

}

//////////Temp/////////////////////////////////////

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   Serial.print(" F: ");
   Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}



Any suggestions?

JohnnyKnowing


I have happy to report that, thanks to all your help and suggestions, I got the sketch working.

I tried moving all of my functions above the loop function and that helped the function prototype work, which fixed my errors

Thanks again!  :smiley-yell:

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy