[SOLVED] Spark-dallas-temperature library compatibility with Libraries 2.0

Umm… OK, you lost me. Living library?

A library that is actively maintained

I don’t know of any other library to use for this, so I just commented out everything to do with both OneWire and spark-dallas-temperature. But it still won’t compile!

In file included from lib/spark-dallas-temperature/src/spark-dallas-temperature.cpp:12:0:
lib/spark-dallas-temperature/src/spark-dallas-temperature.h:27:36: fatal error: ../OneWire/OneWire.h: No such file or directory
     #include "../OneWire/OneWire.h"
                                    ^compilation terminated.
make[1]: *** [../build/target/user/platform-6spark-dallas-temperature/src/spark-dallas-temperature.o] Error 1
make: *** [user] Error 2

Where is this error coming from???

I have uploaded the code that compiled perfectly the last time I ran it on 12/23/16 to https://www.filesanywhere.com/fs/v.aspx?v=8b716a875e6170b1a0a8. I’m offering a six-pack of beer to the first person who can get this to compile, and tell me how it’s done.

I think - no I know - I gave you an alternative already

I could also fix your project, but that would be cheating :wink:

But I’ve already removed all references to Dallas* everywhere and it’s still complaining about it. I just tried including DS18B20 and still get the same error. Anyway, you’ve helped me enough in the past that you deserve the bounty.

You also need to remove the include statements and remove the libraries from your project.
I guess you are using Web IDE, right?
If you can post a screenshot of your IDE window with the code/project <> drawer open it’d be easier to see what libs you’ve got imported.

Right.

There's too many to fit in one screen. Is the text version of that OK? This is what I'm currently trying. All the Dallas and OneWire stuff is commented out. Are you saying I need to remove ALL the libraries and then reinclude them?

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>

// This #include statement was automatically added by the Particle IDE.
#include <SparkFun_Photon_Weather_Shield_Library.h>

// This #include statement was automatically added by the Particle IDE.
// #include "OneWire.h"

// This #include statement was automatically added by the Particle IDE.
// #include <spark-dallas-temperature.h>

//  weatherlcd.ino
// Backup is in C:\Program Files\Photon_Weather_Shield-master\WeatherLCDv2.txt
// Version 1.01, 9/23/16
// 1.02, 11/6/16, fixed DST code in SR/SS
// 1.03, 11/20/16 - Changed forecast API provider
// 1.04, 12/17/16 - Added BT auto-reconnect on dropped connection.
// 1.05, 12/23/16 - Added snow depth sensor

// SYSTEM_MODE (AUTOMATIC); // enable wifi + cloud (default)

// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>

#include "application.h"

// This #include statement was automatically added by the Particle IDE.
#include <Sunrise.h>

// This #include statement was automatically added by the Particle IDE.
#include <SparkFunPhant.h>

// This #include statement was automatically added by the Particle IDE.
// #include "OneWire/OneWire.h"
// #include "OneWire.h"

// This #include statement was automatically added by the Particle IDE.
// #include <spark-dallas-temperature.h>

// This #include statement was automatically added by the Particle IDE.
// #include <SparkFun_Photon_Weather_Shield_Library.h> 

#include <SparkFun_Serial_Graphic_LCD.h>

#include "math.h"

No, just these two includes and the respective libraries libraries ...

// This #include statement was automatically added by the Particle IDE.
// #include "OneWire.h"

// This #include statement was automatically added by the Particle IDE.
// #include <spark-dallas-temperature.h>

... unless you have got any other OneWire library (apart from DS18B20) in your project.

I wasn't after your code but only the list of included libraries and file tabs of your project.

I have now tried to build your project and you can stick with the original code if you do this:

1 Like

OK, I'm up to step 5:

And now I'm stuck. Which is the "respective file tab"?


I have my own code in weatherlcd1.ino and then two tabs, both named "spark-dallas-te". ???

Click on the tab and see your browsers address bar.
Or if you hover with the mouse over the file tab your browser should show you the link which tells you.
Or you open the <> drawer and select the wanted file.
Or you just make your window wider then the file tabs should expand too (at least do for me in Chrome)

But since they are ordered .cpp left .h the one you selected should be the .h file.

1 Like

Well hallelujah - that finally worked! I did have to remove and reinstall all my other libraries first though (http, sunrise, lcd, etc.) but after that I finally got a clean compile.

But the irony is that my weather Photon just died, stuck endlessly sending out a pitiful SOS that will never get answered.

But you are still the bounty winner. I never could have figured this out without your help. PM me with your Paypal info, and thanks again.

4 posts were split to a new topic: Errors with ITEADLIB_Nextion

Unfortunately the DS18B20 library did not work (or I was not able to make it work) when trying to make this work in Photon https://learn.adafruit.com/adafruit-1-wire-thermocouple-amplifier-max31850k/wiring-and-test Do you happen to know are there any other alternatives I could try instead of Spark-dallas-temperature-library?

Just changing the "#include “…/OneWire/OneWire.h” to "#include “OneWire.h” in spark-dallas-temperature.h file did not help (see below).

#if defined(ARDUINO) && ARDUINO >= 100
    #include <OneWire.h>
#elif defined(SPARK) or defined(STM32F10X_MD)
    #include "application.h"
    // #include "../OneWire/OneWire.h"
    #include "OneWire.h" 
#endif

Do you know is there something else I could try?

What exactly didn't work?

I tried replacing the DallasTemperature-library with DS18B20 library just by changing the name of included library in the code below. It seems that there are some functions that do not exist in the DS18B20 library that would be needed for the code to work (e.g. “DallasTemperature sensors(&oneWire);”?).

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

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

// 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("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  //outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  // 
  // method 1: by 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"); 

  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  // assigns the seconds address found to outsideThermometer
  //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

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

  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();

  // set the resolution to 9 bit
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(outsideThermometer), DEC); 
  Serial.println();
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    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));
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}

// 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 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");

  // print the device information
  printData(insideThermometer);
  printData(outsideThermometer);
}

DS18B20 lib is not a drop in replacement for the other lib.
A quick look in the provided examples might have given you a clue tho’.

To start with, there is no need to import OneWire lib with it.
And to instantiate a sensor object you just do

DS18B20 sensors(ONE_WIRE_BUS);

BTW, please use the D2 pin names and not this anonymous number notation.

I tried this and get an error

spark-dallas-temperature.cpp:448:16: ‘NAN’ was not declared in this scope

If you tried the DS18B20 lib you should not have the spark-dallas-temperature.cpp included/imported as well.
But the NAN message is easily fixed by adding an #include <math.h>

1 Like