我们正在尝试测试一个简单的DS18B20温度探头的读数。即将到来的读数,但都是-127.0度。我们不确定从这里去哪里。该引脚位于数字引脚8中,因为它可以为项目提供更好的数字和数据点。由于引脚不足,无法将其移至模拟状态。另外,我们正在使用Arduino Nano作为动力源。
我们尝试添加一个字符串temp,因为完成代码需要使用hat来添加一个float temp,但这似乎不适用于该字符串temp。我们已经尝试了每种方法,并且分别进行了尝试,但这些方法似乎仍无法解决当前的问题。
#define ONE_WIRE_BUS 8 // Temperature sensor pin
#define MOSI 11 // SD
#define MISO 12
#define SCK 13
#define CS 10
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp = 0.0;
String time_str = "";
String data_str = "";
//String temp = "";
int temperature = 0;
digitalWrite(HBRIDGE, LOW); // turn the LED off by making the voltage LOW
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
buckVoltage = analogRead(BUCK_IN);
hbridgeVoltage = analogRead(HBRIDGE_IN);
negativeData = hbridgeVoltage - buckVoltage;
Serial.println(negativeData);
delay(500);
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
DateTime c = rtc.now();
String seconds = "";
if (c.second() < 10) {
seconds = '0' + c.second();
}
else {
seconds = c.second();
}
time_str = String(c.month()) + '/' + String(c.day()) + "/" +
String(c.year()) + "," +
String(c.hour()) + ":" + String(c.minute()) + ":" +
seconds;
data_str = String(temp) + ',' + String(positiveData) + ',' +
String(negativeData);
Serial.println(time_str + ',' + data_str);
f.println(time_str + ',' + data_str);
f.close();
从理论上讲,我们的结果应读取所测试物质的温度,但结果无意义,对它们无意义,因为每次都只能读取负数。