Hi all. I hope you can help me this time around. Seems I get problems nobody else gets or knows how to fix
I am using the DS18B20 temp probe. I am getting -127 at random. It will work fine and then give the -127 reading that states it is a communication error. I have tried 3 different probes and 2 different Arduinos so it is not the probe
In the image you can see all will be fine and then at random I will get the -127
Is this a common problem or is there something I can do to stop it from happing. It is not even a very long cable. IT is the normal 1m cable that came with it.
Here is the code. I even call the temp a second time it it is less than 0 just in case but I still get -127 from time to time. Else I get it even more.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Bridge.h>
#define ONE_WIRE_BUS_1 2
OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);
float t1;
char ttemp[8];
void setup(void)
{
//Delay for letting the linux side get a clean boot.
delay(5000);
// Zero out the memory we're using for the Bridge.
memset(ttemp, 0, 8);
sensor_inhouse.begin();
Bridge.begin(Serial);
//Init the t values
Bridge.put("TTEMP", String(0));
}
void loop(void)
{
Bridge.get("TTEMP", ttemp , 8);
sensor_inhouse.requestTemperatures();
t1 = sensor_inhouse.getTempCByIndex(0);
if (t1 < 0) {
sensor_inhouse.requestTemperatures();
t1 = sensor_inhouse.getTempCByIndex(0);
}
//Send all the values to the Linux side
Bridge.put("T1", String(t1));
}
Do you use tree wires for the DS18B20 ?
Do you use a pullup resistor ? which value ?
Is the cable close to the wifi antenna of the Yun ?
How do you power the Yun ?
Why do you use Bridge.begin(Serial) ? I'm used to Bridge.begin(). Using the "Serial" is to have a Bridge via the USB to the computer ?
Does the Bridge.put() accept a String object ? I use a buffer and dtostrf().
The loop() is slowed down by the DallasTemperature calls ? I think that the Bridge.put() should not be called to much, perhaps only every 5 seconds. I think you call it more often than once per second.
Hi. I am not using the Yun. I am Using a Raspberry Pi connected to a Arduino Uno. But I get the same on the Yun and Mega. I just posted the Yun code as it is less complicated. I was in the process to port the Yun Bridge to connect a Arduino with Raspberry Pi. I just Posted that code, don't worry about that. But the communication with the temp probe is the same.
Your code appears to be incomplete but a good recipe for getting 85 all the time.
You do not appear to have set the resolution, which implies the sensor needs 750 ms minimum between readings. You appear to allow no time at all between readings and, on the face of it, I'm surprised you get anything. I understand -127 simply means bad connection, rather than bad code, but there may be a connection if the code is as bad as this.
But I get the same if I just hookup an Arduino and spit the data out to the serial monitor.
This is the best line of the thread and, since this is an Arduino forum, it might be better to just use the Mega to prove you know what you are doing with the DS18B20, as there is no evidence of that yet. Some sensible information is here
WOW thanks for the insult Nick. That helped a lot in solving my problem. Great job man !!!!
If you are saying I am writing bad code then please talk to the people who put the examples up. It was a copy of that example file that is part of the library. There are no delays in there as well.
// 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));
}
I got it working btw. I replaced the one wire library with this version https://github.com/PaulStoffregen/OneWire . So if anybody else has this problem the pick-up the new library and ignore the people who insult you for posting the samples from the library.
Could you fix things ? Go to your projects folder, into the "libraries" folder. Remove every OneWire and DallasTemperature.
Start the Arduino IDE, go in the menu to Sketch / Add library / Manage Libraries.
Use the Library Manager to install OneWire and DallasTemperature.
That is the newest OneWire from Github that is maintained by Paul Stoffregen.
Now you get automatically noted of new versions as well.