【问题标题】:How to resolve the error: ‘yield’ was not declared in this scope from DallasTemperature library (Arduino)如何解决错误:DallasTemperature 库 (Arduino) 在此范围内未声明“yield”
【发布时间】:2021-01-15 06:14:34
【问题描述】:

我正在尝试从我的温度传感器收集温度,但我遇到了这个错误:

/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:在成员函数‘void DallasTemperature::blockTillConversionComplete(uint8_t)’中: /home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:446:13:错误:“yield”未在此范围内声明 屈服(); ^

/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:在成员函数‘bool DallasTemperature::recallScratchPad(const uint8_t*)’中: /home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:543:11:错误:>'yield' 未在此范围内声明 产量();

这是我的代码,基于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);
    }

库版本:

  • OneWire-2.3.5
  • DallasTemperature-3.9.0
    (我当然尝试过重新导入它们)

DallasTemperature.cpp 中的代码似乎与错误有关:

// 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;
  
}

我来到这里是因为我在 Google 上没有发现涉及“yield()”和 DallasTemperature 的错误...

【问题讨论】:

  • 你为什么板编译?
  • Arduino Mega 2560 @Juraj
  • 什么板包版本?你有旧版本的 IDE 吗?
  • IDE 2:1.0.5 如果我没记错的话。我不知道如何获得板子版本,对不起。

标签: c++ c arduino


【解决方案1】:

DallasTemperature-3.9.0 于 2020 年 9 月 2 日发布,我的项目有点老,我之前第一次创建它,后来我无法完成它。我使用的是3.8.0版本,我重新安装了它,它又可以工作了。

【讨论】:

    【解决方案2】:

    某些平台没有实现yield,因此您可以从库的代码中删除对它的调用。调用yield会将控制权交给其他任务,如果你没有其他任务,无论如何都是多余的。

    可以通过在文件顶部提供一个空实现来删除它。

    如果您确定您的董事会应该支持它。比您可能使用了错误的软件堆栈。尝试下载official Arduino IDE。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多