我的问题是与Arduino纳米感觉BLE和DS18B20传感器(防水版本)没有一起工作。
到目前为止我尝试过的。我对UNO进行了测试,以隔离可能的电源和传感器故障。测试结果如下:
连接DS18B20
Black > GDN
Red > 3V
黄> D2
最后两个通过2k2电阻器连接(2k2代替4k7,因为我使用3V)。
然后,为了排除可能的编码错误,我使用了现成的示例:
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// 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);
/*
* The setup function. We only start the sensors here
*/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
/*
* Main function, get and show the temperature
*/
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.
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}结果?工作得很好。
然后我转到了Nano感觉BLE板。在没有断开传感器的情况下,我只是在船上的一端切换了连接,并附加了GDN、3.3V和D2。
结果,-127。当试图找到DS18B20地址时,结果为none。我怀疑董事会的引脚订单问题或达拉斯/OneWire lib问题。
我还试过其他的语言来处理DS18B20,没有一个能工作,而且我尝试了3-4种。我注意到网络上很少有关于纳米系列的话题,而且没有一个问题得到解决。我还发现了IoT,每个人都有相同的问题。
发布于 2022-12-04 08:33:28
从DS18B20获得-127的问题是因为传感器可能断开,或者没有从板上正确地获得3.3V或300‘t电流。所以确保你的引脚连接正确。你可以用你的DMM测试它通过检查短销和电线之间。有时候这可能是图书馆的问题。您需要安装onewire和达拉斯温度库的最新版本。
https://stackoverflow.com/questions/60885829
复制相似问题