[英]Arduino Nano - Error stating '___' was not declared in the scope
[英]How to resolve the error: ‘yield’ was not declared in this scope from DallasTemperature library (Arduino)
我正在尝试从温度传感器收集温度,但遇到此错误:
/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:在成员函数“void DallasTemperature::blockTillConversionComplete(uint8_t)”中:/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:446:13:错误'yield' 未在此范围中声明 yield(); ^
/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp:在成员函数'bool DallasTemperature::recallScratchPad(const uint8_t*)'中:/home/myuser/sketchbook/libraries/DallasTemperature/DallasTemperature.cpp1:543:1错误:>'yield' 未在此范围中声明 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);
}
库版本:
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 的错误...
DallasTemperature-3.9.0 2020-09-02 出来了,我的项目有点老了,我之前第一次创建了它,后来我无法完成它。 我使用的是 3.8.0 版本,我重新安装它并再次运行。
某些平台没有实现yield
因此您可以从库的代码中删除对它的调用。 调用yield
将控制权交给其他任务,如果没有其他任务,反正都是多余的。
删除它可以通过在文件顶部提供一个空的实现来完成。
如果您确定您的董事会应该支持它。 您可能使用了错误的软件堆栈。 尝试下载官方Arduino IDE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.