arduino接了PCF8574转接板的DS18B20找不到地址怎么办
时间: 2023-05-22 22:02:58 浏览: 58
您可以尝试使用 Arduino 的 DS18B20 库的搜索功能来查找 DS18B20 的地址,同时确保您的转接板连接正常且接线正确。以下是代码示例:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void) {
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void) {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
if (sensors.getDeviceCount() > 0) {
float tempC = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println(" *C");
} else {
Serial.println("No devices found.");
}
delay(1000);
}
此代码将搜索 DS18B20 的地址并显示其温度。希望这可以帮助你解决你的问题!