Go Down

Topic: Could use some advice on a DS18B20 problem. (Read 304 times) previous topic - next topic

Don-T

I have 6 DS18B20 temperature sensors on one circuit. Five (5) of the sensors work just fine, but the 6th spends half it's time reading 185°f and the other half reading the outside temperature. I have I believe the latest One-Wire and Dallas Temp libraries. I have a delay of 10 seconds (10000) after the sensors.requestTemperatures and before the first sensors.getTempF(S1). I don't think it's the code but this is my first project, I've been working on it for over a year on and off.
I think it's the length of the Cat 5 wire to the outside sensor, which is about 60 feet. I've tried using a small resistor, 1k and 2k, it did not seem to help. I've checked the volts from the Arduino Uno, it was 4.74 volts. I am using the Nextion 3.5 display powered from the Arduino. I tried powering the display separately, again it did not make a difference.
On the Brick-Temperature-DS18B20 site, it showed one wire for 5v, which is what I did. I'm wondering if I should have used a twisted pair of wires and used both wires to supply the 5 volts ?
Any suggests as to what is should do next?
Thank for your help.

here is my code

Code: [Select]

  // started on this 9 jan 2018
 
  #include "Nextion.h"
 
  #include <OneWire.h>
 
  #include <DallasTemperature.h>
 
  #define ONE_WIRE_BUS 8

  #define SENSOR_RESOLUTION 9
 
  OneWire oneWire(ONE_WIRE_BUS);
 
  DallasTemperature sensors(&oneWire);

  int countloop = 0;
  int numberOfDevices;
 
  float ait = 0; // actual inside air temperature
  float aot = 0; // actual outside air temperature
  float pst = 0; // boiler premix supply water temperature
  float prt = 0; // boiler premix return water temperature
  float fst = 0; // floor supply water temperature
  float frt = 0; // floor return water temperature
   
  DeviceAddress S1 = { 0x28, 0xFF, 0xEA, 0xD9, 0x22, 0x17, 0x04, 0x85 };// sensor # 1
  DeviceAddress S2 = { 0x28, 0xFF, 0xBE, 0x24, 0x23, 0x17, 0x04, 0x48 };// sensor # 2
  DeviceAddress S3 = { 0x28, 0xFF, 0x4C, 0x12, 0x23, 0x17, 0x04, 0x2C };// sensor # 3
  DeviceAddress S4 = { 0x28, 0xFF, 0xD9, 0x14, 0x23, 0x17, 0x04, 0x40 };// sensor # 4
  DeviceAddress S5 = { 0x28, 0xFF, 0x97, 0xD9, 0x22, 0x17, 0x04, 0x04 };// sensor # 5
  DeviceAddress S7 = { 0x28, 0xFF, 0xEB, 0x22, 0x23, 0x17, 0x04, 0x06 };// sensor # 7
  //DeviceAddress S8 = { 0x28, 0xFF, 0x43, 0x1B, 0x23, 0x17, 0x04, 0xD0 };// sensor # 8
  //DeviceAddress S10 = {0x28, 0xFF, 0xB7, 0x15, 0x23, 0x17, 0x04, 0x7C };// sensor # 10

  // Declare your Nextion objects - Example (page id = 0, component id = 1, component name = "b0")
  NexText tinsidetemp = NexText(0, 2, "tinsidetemp");       //sensors.getTempF(S1)
  NexText toutsidetemp = NexText(0, 4, "toutsidetemp");     //sensors.getTempF(S2)
  //NexNumber nsettemp = NexNumber(1, 3, "nsettemp");
  //NexText twindspeed = NexText(2, 9, "twindspeed");
  //NexText twinddirection = NexText(2, 10, "twinddirection")
  //NexText tfeelslike = NexText(2, 11, "tfeelslike");
  //NexText tpressure = NexText(3, 7, "tpressure");
  //NexText thumidity = NexText(3, 8, "thumidity");
  //NexText trainfall = NexText(3, 9, "trainfall");
  NexText tpremix = NexText(4, 12, "tpremix");              //sensors.getTempF(S3)
  NexText tsupply = NexText(4, 14, "tsupply");              //sensors.getTempF(S4)
  NexText treturn = NexText(4, 15, "treturn");              //sensors.getTempF(S5)
  NexText tpostmix = NexText(4, 13, "tpostmix");            //sensors.getTempF(S7)
  NexNumber ncounter = NexNumber(0, 9, "ncounter");
  NexNumber nsensors = NexNumber(0, 11, "nsensors");
 

void setup()
{
  // put your setup code here, to run once:
 
 Serial.begin(9600);
 sensors.begin();
 numberOfDevices = sensors.getDeviceCount();
 
}

void loop() {

  countloop++;
  ncounter.setValue(countloop);
  nsensors.setValue(numberOfDevices);
 
  sensors.requestTemperatures();
 
  sensors.setWaitForConversion(true);
 
  delay(10000);

   // the different sensors in F°
  ait = sensors.getTempF(S1); // actual inside air temperature
  aot = sensors.getTempF(S2); // actual outside air temperature
  pst = sensors.getTempF(S3); // boiler premix supply water temperature
  fst = sensors.getTempF(S4); // floor supply water temperature
  frt = sensors.getTempF(S5); // floor return water temperature
  prt = sensors.getTempF(S7); // boiler premix return water temperature
 
  char abc[10];
  dtostrf(ait,6,1,abc);
  tinsidetemp.setText(abc);

  char def[10];
  dtostrf(aot,6,1,def);
  toutsidetemp.setText(def);

  char ghi[10];
  dtostrf(pst,6,1,ghi);
  tpremix.setText(ghi);

  char jkl[10];
  dtostrf(fst,6,1,jkl);
  tsupply.setText(jkl);

  char mno[10];
  dtostrf(frt,6,1,mno);
  treturn.setText(mno);

  char pqr[10];
  dtostrf(prt,6,1,pqr);
  tpostmix.setText(pqr);

 
}

Nick_Pyner

#1
Jan 16, 2020, 12:58 am Last Edit: Jan 18, 2020, 01:31 am by Nick_Pyner
IF you get the correct reading some of the time then, clearly, your code is kosher. The delay of ten seconds has no bearing on anything. It may be what you want, and that is fine, but one second would do.

Everything suggests the 60 foot cable is the problem. You are getting an intermittent "no connection" return. The intermittency may be down to electronic noise in the environment rather than merely the slack-arsed connections it usually implies. I don't think the 4.74v is a problem. CAT5 cable is the popular choice and you should certainly use all the copper available. There has been plenty of discussion on this. One additional recommendation is to use a terminal cap. This did not fix anything for me, probably because I was still using substandard cable.

Here's one for the truly desperate, but might sound pretty good if you have been banging your head against the wall for a year or so:

1. Move your code to a Nodemcu OR add an ESP-01 WiFi module to Uno
2. Use an ESP-01 to read the remotest sensor and transmit via WiFi
3. Use the CAT5 you already have just to supply power to the rig in 2. ESP-01 is a 3.3v device.

Your chance to be the first kid on the block who solves the problem by actually removing it, rather than working around it (!)

Don-T

This is Cat 5 but it's not shield. i think i'll try doubling the wire when it gets a little warmer it's -9 today!

pylon

Quote
This is Cat 5 but it's not shield.
That's not possible, Cat 5 cable is always shielded. Do you mismatch Cat 5 by twisted-pair?

A Cat 5 cable is not the best solution to transport a non-differential 5V signal over almost 20m. In an electrically not so noisy environment I had better results with rather thick loudspeaker cables, but I had only about 8-10m.

I agree with Nick_Pyner to use another MCU near the sixth sensor. Connecting it wireless is one possibility, you have also wired options (Ethernet, RS-485, etc.).

Don-T

i may of stated it wrong. I have unshielded twisted pair cat 5 (UTP) instead of shield twisted pair cat 5 (STP). Sorry about that. i think i'll try twisting the wires together, or some shield wire first. thank you 

Nick_Pyner

OK, I was not aware of unshielded CAT5, and also surprised, but at least it has twisted pairs. There has been plenty of discussion on this matter, which you should check, but I always understood that CAT5 was always shielded. What may be the real prizes are copper/$ and the twisted pairs, and you could be fine with what you have in hand. When I said popular choice, I guess I meant popular choice amongst cheapskates. I'm sure Pylon would not promote rather thick speaker cable as an economic proposition, and you don't have to roll out too much cable of any sort to start thinking about how good an idea it is.

Don-T

 from pylon
 
Quote
I had better results with rather thick loudspeaker cables
wouldn't twisting the pair together be like heaver wire? if i do that as a first step and i get better results, like 70-80% it reads right, then i would know i'm on the right path and replacing the cat 5 with loudspeaker cable would be the next step?

from Nick_Pyner
Quote
here has been plenty of discussion on this matter, which you should check
if you could, do you have a particle thread or 2 in mind. i'd like to read them.

Nick_Pyner

I'm sure a search in the turquoise strip at the top will reveal all.  This one is always coming up with a swag of solutions - except giving up and going wireless! The general consensus for long cable is CAT5 and a 2k pullup resistor.

One thing that has slipped by on this thread: You aren't using parasite power are you? If you are, cease and desist immediately, and use a normal setup.

Don-T

No I'm not using parasite power, that didn't look like a good way to go even to me.

Nick_Pyner

#9
Jan 18, 2020, 01:27 am Last Edit: Jan 18, 2020, 01:28 am by Nick_Pyner
You're dead right about that... :D
I see you are already using a 2k pullup, so I suggest you just try re-organising the use of the cable.

You might casually peruse  http://pdfserv.maximintegrated.com/en/an/AN148.pdf
for information from the horses mouth. I think it is a document actually best read by somebody else, and it was just the page count that motivated me to think in terms of wireless.

Don-T

i saw that article a couple of times but it's way over my head

Nick_Pyner

No surprise, hence my comment.
have you got this stuff working?

Don-T

you're right, the threads I've read are all over the place. Double up the wires, don't double them. Ground the unused wires, don't ground them. So i talked to a buddy who works for a place that might have Cat 5e shield wire. He's going to try and get some for me. Also think I might try a cap next to the sensor that I'm having trouble with. Question what size and type should i get to try?

Nick_Pyner

#13
Jan 23, 2020, 12:48 am Last Edit: Jan 23, 2020, 12:50 am by Nick_Pyner
The plethora of unresolved discussion is the reason for my comment about cutting to the chase and going wireless. And note particularly that, if you need to buy extra cable, an ESP-01 is likely to be cheaper, as well as work first time.

I don't think anybody would say don't double up on the wires, just that they deem it unnecessary, which is OK in their experience. If they do specifically say don't double up, ignore them, and everything else they might say about anything.

I think I used 200n caps, the sort of thing one would use on a proto shield. It did not solve the problem, but that was probably because of the cheapo extension cable I used.  The distances were nowhere near yours, and the solution was move Arduino into a weatherproof box and walk a few extra metres.

Go Up