How to resolve the error: ‘yield’ was not declared in this scope from DallasTemperature library (Arduino)
How to resolve the error: ‘yield’ was not declared in this scope from DallasTemperature library (Arduino)
我正在尝试从我的温度传感器收集温度,但我遇到了这个错误:
/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();
这是我的代码,基于 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
- 达拉斯气温-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 的错误
有些平台没有实现 yield
因此您可以从库的代码中删除对它的调用。调用yield
将控制权交给其他任务,如果你没有其他任务,反正是多余的。
删除它可以通过在文件顶部提供一个空的实现来完成。
如果你确定你的主板应该支持它。您可能使用了错误的软件堆栈。尝试下载 official Arduino IDE.
DallasTemperature-3.9.0 于 2020-09-02 发布,我的项目有点老,我第一次创建它之前就无法完成。我使用的是 3.8.0 版本,我 re-installed 它再次运行。
我正在尝试从我的温度传感器收集温度,但我遇到了这个错误:
/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();
这是我的代码,基于 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
- 达拉斯气温-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 的错误有些平台没有实现 yield
因此您可以从库的代码中删除对它的调用。调用yield
将控制权交给其他任务,如果你没有其他任务,反正是多余的。
删除它可以通过在文件顶部提供一个空的实现来完成。
如果你确定你的主板应该支持它。您可能使用了错误的软件堆栈。尝试下载 official Arduino IDE.
DallasTemperature-3.9.0 于 2020-09-02 发布,我的项目有点老,我第一次创建它之前就无法完成。我使用的是 3.8.0 版本,我 re-installed 它再次运行。