Arduino-Temperature-Control-Library icon indicating copy to clipboard operation
Arduino-Temperature-Control-Library copied to clipboard

I want to retrieve the exact times of all 0x00 operations from Data:0X22 to Data:0xc2 using the logic analyzer. Below is my code.

Open mayjack0312 opened this issue 7 months ago • 4 comments

This issue is still a timing logic problem. My code is as follows:

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

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
}

void loop() {
  int deviceCount = sensors.getDeviceCount();

  for (int i = 0; i < deviceCount; i++) {
    unsigned long startTime = micros();

    sensors.requestTemperaturesByIndex(i);

    float temperatureC = sensors.getTempCByIndex(i);

    unsigned long endTime = micros();

    float duration = (endTime - startTime) / 1000.0;

    Serial.print("传感器 ");
    Serial.print(i);
    Serial.print(" 温度: ");
    Serial.print(temperatureC);
    Serial.print(" °C, 读取时间: ");
    Serial.print(duration, 3);
    Serial.println(" 毫秒");

    delay(1000);
  }

  delay(5000);
}

The current measurement results include the start and stop commands, but I only want the times for the Data:0x00 operations in the middle section of the loop.

mayjack0312 avatar Jul 09 '24 07:07 mayjack0312