I’m working on a project to control and log the temperature of our 10x30m high tunnel (i.e. a greenhouse). The photon is controlling 8 car relays which in turn forms two H-bridges to control wiper motors. These motors rolls upp a steel wire which opens some quite large doors for ventilation. That part is working great.
What’s not working so great is my temperature sensors. The sensors is connected one by one to pin A1, A2 and A3. No pin is used for more than one sensor. They are powered from the 3.3v pin and connected to GND. Between data and 3.3V is a 4.7k resistor.
These are placed on 10-20 meter long cables (they’re marked ELQXBE 4x0,5 with four solid copper wires, 0,5mm2). About half of my readings are correct but half fail the CRC-check. The “data” is sometimes just FF FF FF … and sometimes something looking a bit more meaningsful but still failing the CRC-check.
I’m using the ds18b20 sensor and the OneWire library. Is there something I can do in code to make this a bit more robust? Or in hardware? Can I do something about the resistor? Am I using the wrong type of cable?
Any help i appreciated!
I assume you are working with a photon which is 5v tolerant ?
In that case you could start by moving the resistor and sensor VCC to 5V(vin if using USB), that gives you a bit more noise margin.
Are the cables twisted pair ?
10-20meters in a non noisy enviroment should not be a problem with twisted pair and 5V.
You can also lower the resistor and see if it helps, something in the area of 1-2.5Kohm
Can you post a link to the library you are using?
I had lots of problems with 15 meter cabling to ds18b20’s. Here are some steps I took to fix the issue:
- I changed the timings used in hotaman’s OneWireSpark library. You can see mine here. Hotaman’s timings always worked for me with short wires, but they are the absolute minimum recommended by Maxim. All I’ve done is extend the timings so they are somewhere between the minimum and maximum recommended by Maxim.
- I put the sensors in parasite power mode, even though they are hooked up in three wire mode. Not sure this did much, but for me it reduced the likelihood of getting bad readings errors
This has made them work well over the last week. I have about 35 of them in an outdoor ag setting with no bad readings in ~10 days.
The next change I will make is to use a different resistor value. 4k7 is what all the tutorials say, but if you get into Maxim’s docs on reliable long-range 1-wire, you’ll find that they sometimes recommend down to 1k resistors, especially for 3V networks.
The cable is unfortunaltly not twisted pair. I could change this but I’ll try some of your other sugestions first:
5V. can I power the onewire net with 5V as long as I’m not connecting the data line to A3? (seems not to be 5-volt tolerant?).
I use the onewire library in the web ide (copied to a local file). Seems to be the same as you are using, @hwestbrook. I was thinking of fiddling with the timing but it felt a bit overwhelming. I’ll try your version!
I’ll try lowering the resistor.
I’ll give it a try tonight or tomorrow and let you know how it works out. Thanks again.
I’ve implemented a retry mechanism and as long as I allow 20 retries 99% of the readings end up ok. If I can improve that by a magnitude It’s perfectly enogh for my purpose.
Good catch, A3 is not 5V tolerant even when not used as analog.
If you are not using A3 then yes you can use 5V, just make sure the pins are not used as analogpins…
If you need A3, you can still increase the sensor VCC to 5V and see if it helps, just dont move the pullup resistor to 5V.
It’ seems to be working perfectly now.
Moving VCC and the pullup to 5V made huge difference. I tried changing the timer first but I couldn’t really se any improvement from it.
Again, thanks both of you!