-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the relevant conversion time. #38
Comments
You send the start conversion cmd and time until the bus line goes low.
El El jue, 20 jun. 2024 a la(s) 13:08, LMY ***@***.***>
escribió:
… For example, I want to get the corresponding times in the table below one
by one.
image.png (view on web)
<https://github.com/cpetrich/counterfeit_DS18B20/assets/102800660/b3e5861a-6aae-43c8-92b3-5083929306ff>
—
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXBW4NB3LMEL2Z7HNY4DELZIL465AVCNFSM6AAAAABJUILIBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBRGA3DCNBTGY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Can you suggest a sample code? The code conversion times I wrote before were not quite correct. I almost cried from torture o(╥﹏╥)o |
This is the code I wrote yesterday. Although I found that there are many potential bugs in the writing, I still don’t know how to modify it.
|
You don’t know how requestTemperatures() operates. Could just wait 1s to be
sure.
Get the onewire ds18b20 example, and after request the temp, instead
delay(800) do a loop doing digitalRead() of the bus til is low.
El El jue, 20 jun. 2024 a la(s) 13:48, LMY ***@***.***>
escribió:
… Use this function: *https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/65112b562fd37af68ed113c9a3925c09c4529e14/DallasTemperature.cpp#L411
<https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/65112b562fd37af68ed113c9a3925c09c4529e14/DallasTemperature.cpp#L411>*
This is the code I wrote yesterday. Although I found that there are many
potential bugs in the writing, I still don’t know how to modify it.
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress DS18B20_ID;
void setup() {
Serial.begin(9600);
unsigned long initStartTime = micros();
sensors.begin();
unsigned long initEndTime = micros();
Serial.print("Initialization Time: ");
Serial.print(initEndTime - initStartTime);
Serial.println(" us");
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
command.trim();
if (command == "GET") {
unsigned long waitStartTime = micros();
delayMicroseconds(550);
unsigned long waitEndTime = micros();
unsigned long convStartTime = micros();
sensors.requestTemperatures();
unsigned long convEndTime = micros();
unsigned long readCmdStartTime = micros();
float temperature = sensors.getTempCByIndex(0);
unsigned long readCmdEndTime = micros();
unsigned long readRegStartTime = micros();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
unsigned long readRegEndTime = micros();
Serial.print("Wait for Bus Release Time: ");
Serial.print(waitEndTime - waitStartTime);
Serial.println(" us");
Serial.print("Trigger Conversion Time: ");
Serial.print(convEndTime - convStartTime);
Serial.println(" us");
Serial.print("Send Read Command Time: ");
Serial.print(readCmdEndTime - readCmdStartTime);
Serial.println(" us");
Serial.print("Read Register Value Time: ");
Serial.print(readRegEndTime - readRegStartTime);
Serial.println(" us");
} else {
Serial.println("Unknown command.");
}
}
}
—
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXBW4NPQF7MQEZUHIQNS6TZIMBUTAVCNFSM6AAAAABJUILIBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBRGEZDSMJSGY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Please help me see if this code is written appropriately. Thank you.
|
|
Through a new attempt, I discovered a rather difficult problem. When trying to measure the temperature conversion time, a manual delay must be added between the initialization command and the conversion command. However, this leads to errors in judgment or inaccurate delays. I would like to seek help on how to solve this problem. I tried monitoring the high and low signals of the DQ line, but it seems that the pins of the Arduino Uno do not support this. |
show complete code and point where is your problem ... please show also output from Serial Monitor |
I tried several methods but none of them worked very well The only time it succeeded was to display the time it took to read the temperature. |
Please paste actual code to review |
1
2
3
4
|
El El sáb, 22 jun. 2024 a la(s) 11:27, LMY ***@***.***>
escribió:
#include <OneWire.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// https://github.com/milesburton/Arduino-Temperature-Control-Library
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[9];
byte addr[8];
float celsius, fahrenheit;
unsigned long initStartTime = micros(); // 记录初始化开始时间
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
unsigned long initEndTime = micros(); // 记录初始化结束时间
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
unsigned long waitStartTime = micros(); // 记录等待DS18B20释放总线开始时间
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
// delay(1000); // maybe 750ms is enough, maybe not
// Instead of delay
while ( digital.Read(10) == 1 ) ;
… // we might do a ds.depower() here, but the reset will take care of it.
unsigned long waitEndTime = micros(); // 记录等待DS18B20释放总线结束时间
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
unsigned long readCmdStartTime = micros(); // 记录发送读数据命令开始时间
|
I need a program to help me read the corresponding time in the table |
This is because every time you use method with ending "byIndex" DallasTemperature library scans bus for your device |
Thank you, I'm trying it hard and feel like this is the final solution I want |
Ok write down here if you found problem with this. |
Very good project, but I want to ask outside the line: How to modify the code to obtain the conversion time of each DS18B20 and print it out?
The text was updated successfully, but these errors were encountered: