Library include error - Web IDE


#23

This library has broken includes ever since the introduction of Libraries v2.0 but since there exist other working libraries and noone ever could explain what the benefit of this lib over the others would be a repair hasn’t been pursued.
The only workaround I found was targetting an old system plus selecting an older version of the lib - but who really wants that when real solutions exist?


#24

what other librarys should I move too?


#25

I am using a photon 0.6.3


#26

I may be a bit biased but this seems to work
https://build.particle.io/libs/DS18B20/0.1.7


#27

are there any differences in coding?


#28

guess a better question is where is a wrie up on the commands?


#29

That lib is rather self explanatory and you could look at the samples provided along with it.


#30

OK im in the process of changing to the DS18B20 library. I have been studying the coding example for multiple sensors . I have a couple of questions.

in these 2 statements

const uint32_t msSampleTime = 2500;
const uint32_t msPublishTime = 30000;

what is the uint32_t ??

in this statement

if (!isnan(temp)) celsius[i] = temp;

what is the ! mean?

thanks steve


#31

These are C/C++ fundamentals

This is an unsigned 32 bit integer (aka. unsigned long).

The ! is the logical NOT operator.


#32

Ah. Thanks


#33

ScruffR, I have been studying your example for multiple sensors and have a few more coding questions. Please forgive me for asking rudimentary questions but I am still on the uphill side of the learning curve.

  1. in the line

float celsius[nSENSORS] = {NAN, NAN}; what is NAN? I have seen that before in the onewire library

  1. I am confused by this line. What does it do?
    if (!isnan(temp)) celsius[i] = temp;

  2. is this returning a value for temp? whats the " _" for?

return _temp;

I am just generally confused by the use of _temp is it the same as temp?

Thanks again steve

This is the code for multiple sensors

#include <DS18B20.h>

const int MAXRETRY = 3;
const int pinOneWire = D2;
const int pinLED = D7;
const uint32_t msSampleTime = 2500;
const uint32_t msPublishTime = 30000;
const int nSENSORS = 2;

DS18B20 ds18b20(pinOneWire);

retained uint8_t sensorAddresses[nSENSORS][8];

float celsius[nSENSORS] = {NAN, NAN};

void setup() {
  pinMode(pinLED, OUTPUT);

  ds18b20.resetsearch();                 // initialise for sensor search
  for (int i = 0; i < nSENSORS; i++) {   // try to read the sensor addresses
    ds18b20.search(sensorAddresses[i]); // and if available store
  }
}

void loop() {
  static uint32_t msSample = 0;
  static uint32_t msPublish = 0;

  if (millis() - msSample >= msSampleTime) {
    msSample = millis();
    for (int i = 0; i < nSENSORS; i++) {
      float temp = getTemp(sensorAddresses[i]);
      if (!isnan(temp)) celsius[i] = temp;
    }
  }

  if (millis() - msPublish >= msPublishTime) {
    msPublish = millis();
    Serial.println("Publishing now.");
    publishData();
  }
}

double getTemp(uint8_t addr[8]) {
  double _temp;
  int   i = 0;

  do {
    _temp = ds18b20.getTemperature(addr);
  } while (!ds18b20.crcCheck() && MAXRETRY > i++);

  if (i < MAXRETRY) {
    //_temp = ds18b20.convertToFahrenheit(_temp);
    Serial.println(_temp);
  }
  else {
    _temp = NAN;
    Serial.println("Invalid reading");
  }

  return _temp;
}

void publishData() {
  char szInfo[64];
  snprintf(szInfo, sizeof(szInfo), "%.1f �C, %.1f �C", celsius[0], celsius[1]);
  Particle.publish("dsTmp", szInfo, PRIVATE);
}

#34

Questions like 1) & 2) are easily investigated via Google tho’
http://www.cplusplus.com/reference/cmath/NAN/
http://www.cplusplus.com/reference/cmath/isnan/

For 3) look here

double getTemp(uint8_t addr[8]) {
  double _temp;
  ...
  return _temp;
}

Would you also be confused if I called _temp like localTemp instead?