用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

点击进入授权页面

只需一步,快速开始

  • QQ空间
  • 回复
  • 收藏
  • TA的每日心情
    郁闷
    2018-2-2 17:05
  • 签到天数: 26 天

    [LV.4]偶尔看看III

    本帖最后由 哆啦Knowledge 于 2018-3-13 22:10 编辑

    以下是我的程序


    1. #include <OneWire.h>
    2. #include <DallasTemperature.h>

    3. // 定义DS18B20数据口连接arduino的2号IO上
    4. #define ONE_WIRE_BUS 2

    5. // 初始连接在单总线上的单总线设备
    6. OneWire oneWire(ONE_WIRE_BUS);
    7. DallasTemperature sensors(&oneWire);

    8. void setup(void)
    9. {
    10.   // 设置串口通信波特率
    11.   Serial.begin(9600);
    12.   Serial.println("Dallas Temperature IC Control Library Demo");

    13.   // 初始库
    14.   sensors.begin();
    15. }

    16. void loop(void)
    17. {
    18.   Serial.print("Requesting temperatures...");
    19.   sensors.requestTemperatures(); // 发送命令获取温度
    20.   Serial.println("DONE");
    21.    
    22.   Serial.print("Temperature for the device 1 (index 0) is: ");
    23.   Serial.println(sensors.getTempCByIndex(0));  
    24. }
    复制代码


    但是编译错误
    ::

    Arduino:1.8.5 (Windows 10), 开发板:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
    E:\mBlock\arduino\arduino-builder -dump-prefs -logger=machine -hardware E:\mBlock\arduino\hardware -tools E:\mBlock\arduino\tools-builder -tools E:\mBlock\arduino\hardware\tools\avr -built-in-libraries E:\mBlock\arduino\libraries -libraries C:\Users\user\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10805 -build-path C:\Users\user\AppData\Local\Temp\arduino_build_626187 -warnings=default -build-cache C:\Users\user\AppData\Local\Temp\arduino_cache_909734 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=E:\mBlock\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=E:\mBlock\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=E:\mBlock\arduino\hardware\tools\avr -verbose C:\Users\user\Desktop\sketch_mar13a\sketch_mar13a.ino
    E:\mBlock\arduino\arduino-builder -compile -logger=machine -hardware E:\mBlock\arduino\hardware -tools E:\mBlock\arduino\tools-builder -tools E:\mBlock\arduino\hardware\tools\avr -built-in-libraries E:\mBlock\arduino\libraries -libraries C:\Users\user\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10805 -build-path C:\Users\user\AppData\Local\Temp\arduino_build_626187 -warnings=default -build-cache C:\Users\user\AppData\Local\Temp\arduino_cache_909734 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=E:\mBlock\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=E:\mBlock\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=E:\mBlock\arduino\hardware\tools\avr -verbose C:\Users\user\Desktop\sketch_mar13a\sketch_mar13a.ino
    Using board 'mega' from platform in folder: E:\mBlock\arduino\hardware\arduino\avr
    Using core 'arduino' from platform in folder: E:\mBlock\arduino\hardware\arduino\avr
    Detecting libraries used...
    "E:\mBlock\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR   "-IE:\mBlock\arduino\hardware\arduino\avr\cores\arduino" "-IE:\mBlock\arduino\hardware\arduino\avr\variants\mega" "C:\Users\user\AppData\Local\Temp\arduino_build_626187\sketch\sketch_mar13a.ino.cpp" -o "nul"
    "E:\mBlock\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR   "-IE:\mBlock\arduino\hardware\arduino\avr\cores\arduino" "-IE:\mBlock\arduino\hardware\arduino\avr\variants\mega" "-IC:\Users\user\Documents\Arduino\libraries\OneWire" "C:\Users\user\AppData\Local\Temp\arduino_build_626187\sketch\sketch_mar13a.ino.cpp" -o "nul"
    "E:\mBlock\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR   "-IE:\mBlock\arduino\hardware\arduino\avr\cores\arduino" "-IE:\mBlock\arduino\hardware\arduino\avr\variants\mega" "-IC:\Users\user\Documents\Arduino\libraries\OneWire" "-IC:\Users\user\Documents\Arduino\libraries\DallasTemperature" "C:\Users\user\AppData\Local\Temp\arduino_build_626187\sketch\sketch_mar13a.ino.cpp" -o "nul"
    "E:\mBlock\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR   "-IE:\mBlock\arduino\hardware\arduino\avr\cores\arduino" "-IE:\mBlock\arduino\hardware\arduino\avr\variants\mega" "-IC:\Users\user\Documents\Arduino\libraries\OneWire" "-IC:\Users\user\Documents\Arduino\libraries\DallasTemperature" "C:\Users\user\Documents\Arduino\libraries\OneWire\OneWire.cpp" -o "nul"
    "E:\mBlock\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR   "-IE:\mBlock\arduino\hardware\arduino\avr\cores\arduino" "-IE:\mBlock\arduino\hardware\arduino\avr\variants\mega" "-IC:\Users\user\Documents\Arduino\libraries\OneWire" "-IC:\Users\user\Documents\Arduino\libraries\DallasTemperature" "C:\Users\user\Documents\Arduino\libraries\OneWire\OneWire.cpp" -o "C:\Users\user\AppData\Local\Temp\arduino_build_626187\preproc\ctags_target_for_gcc_minus_e.cpp"
    C:\Users\user\Documents\Arduino\libraries\OneWire\OneWire.cpp:85:24: fatal error: WConstants.h: No such file or directory
    #include "WConstants.h"
                            ^
    compilation terminated.
    使用库 OneWire 在文件夹: C:\Users\user\Documents\Arduino\libraries\OneWire (legacy)
    使用库 DallasTemperature 在文件夹: C:\Users\user\Documents\Arduino\libraries\DallasTemperature (legacy)
    exit status 1
    为开发板 Arduino/Genuino Mega or Mega 2560 编译时出错。

    粗略看一下,大概是因为这个


    C:\Users\user\Documents\Arduino\libraries\OneWire\OneWire.cpp:85:24: fatal error: WConstants.h: No such file or directory
    #include "WConstants.h"
                            ^
    compilation terminated.

    但是怎么解决
    我的问题解决了,谢谢,大概的方法就是更新一下库函数。在项目>管理库里面更新一下,找到新的下载。

    请看http://www.sizhlro2018.com/forum ... ;tid=112&extra=

    在项目>库函数里面找最新版本的OneWire就可以了



    QQ图片20180313220116.png

    发新帖
    发表评论
    高级模式  
    您需要登录后才可以回帖 登录 | 立即注册  
    关闭

    推荐主题 上一条 /2 下一条