代码不适用于我的d18b20温度传感器

时间:2017-02-17 08:45:51

标签: arduino

arduino的简单代码在页面下方,一切正常(它显示我的温度),但在这个例子中我包括以太网并开始上网,它不再显示温度....串行监视它只显示我温度-127.00,所以它意味着它不起作用。我是编程的新手,所以我很讨厌,也许这是一些平庸的问题和答案,但我不明白,为什么我不能在设置功能中启动以太网。我只需要那个包含mqtt的其他项目,所以我需要以太网。请帮助并感谢您的答案。

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Ethernet.h>

// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 80);


void setup(void)
{ 
Serial.begin(9600); //Begin serial communication
Ethernet.begin(mac, ip);
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}

void loop(void)
{ 
// Send the command to get temperatures
sensors.requestTemperatures();  
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Update value every 1 sec.
delay(1000);
}

0 个答案:

没有答案