1

I'm trying to gather temperature from my temperature sensor and i'm facing this error :

/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp: In member function ‘void DallasTemperature::blockTillConversionComplete(uint8_t)’: /home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:446:13: error: ‘yield’ was not declared in this scope yield(); ^

/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp: In member function ‘bool DallasTemperature::recallScratchPad(const uint8_t*)’: /home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:543:11: error: >‘yield’ was not declared in this scope yield();

This is my code, based on https://www.instructables.com/id/How-to-use-DS18B20-Temperature-Sensor-Arduino-Tuto/ :

    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    #define ONE_WIRE_BUS 8
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature tempSensor(&oneWire);
    
    void setup()
    {
      Serial.begin(9600);
    }
    
    void loop()
    {
      tempSensor.requestTemperatures();
      float temperatureC = tempSensor.getTempCByIndex(0);
      Serial.println(temperatureC);
    }

Librairies versions:

  • OneWire-2.3.5
  • DallasTemperature-3.9.0
    (I've tried to re-import them of course)

Code in DallasTemperature.cpp where the error seems to refer :

// Sends command to one or more devices to recall values from EEPROM to scratchpad
// If optional argument deviceAddress is omitted the command is send to all devices
// Returns true if no errors were encountered, false indicates failure
bool DallasTemperature::recallScratchPad(const uint8_t* deviceAddress) {
  
  if (_wire->reset() == 0)
    return false;
  
  if (deviceAddress == nullptr)
    _wire->skip();
  else
    _wire->select(deviceAddress);
  
  _wire->write(RECALLSCRATCH,parasite);

  // Specification: Strong pullup only needed when writing to EEPROM (and temp conversion)
  unsigned long start = millis();
  while (_wire->read_bit() == 0) {
    // Datasheet doesn't specify typical/max duration, testing reveals typically within 1ms
    if (millis() - start > 20) return false;
    yield();
  }
  
  return _wire->reset() == 1;
  
}

I'm here because I found nothing about an error involving "yield()" and DallasTemperature on Google...

Stimou
  • 11
  • 3

2 Answers2

0

DallasTemperature-3.9.0 came out on 2020-09-02, my project was a little older, I first created it before and I couldn't finish it since. I was using 3.8.0 version, I re-installed it and it worked again.

Stimou
  • 11
  • 3
-1

Some platforms do not implement yield so you can remove the call to it from the code of the library. Calling yield passes control to other tasks, if you do not have other tasks, it is redundant anyway.

Removing it can be done by providing an empty implementation at the top of the file.

If you are sure that your board should support it. Than it is possible that you are using a wrong software stack. Try to download the official Arduino IDE.

Artium
  • 5,147
  • 8
  • 39
  • 60
  • yield() is in core as an empty function declared weak. scheduling libraries can re-implement it. https://github.com/arduino/ArduinoCore-avr/blob/2f67c916f6ab6193c404eebe22efe901e0f9542d/cores/arduino/Arduino.h#L38 – Juraj Sep 30 '20 at 07:32
  • https://github.com/arduino/ArduinoCore-avr/blob/2f67c916f6ab6193c404eebe22efe901e0f9542d/cores/arduino/hooks.c#L19 – Juraj Sep 30 '20 at 07:36
  • @Juraj Not all platforms implement it. For example Digistump's attiny85 platform does not have it implemented: https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr – Artium Sep 30 '20 at 08:17
  • But thanks for the info, i'll remove the inaccurate info regarding the Scheduler library. – Artium Sep 30 '20 at 08:20
  • that is why I asked for details in comments – Juraj Sep 30 '20 at 08:44