First let me start by saying Hi. I am sure I'm not the first with this problem but after a lot of searching the net and going bugeyed reading datasheets, I thought I would give this a try. I am trying to use a DS18B20 to read temp (ground breaking, right! lol) I am using an Arduino UNO R3, IDE v1.8.3 and I am having several problems. First, when wired for external power, 9 bit res, I am able to read the ID of the device (ok first hurtle) but am getting all FF's when reading the scratchpad.
ROM = 28 FF E6 3B 90 15 1 B7 CRC OK!
Chip = DS18B20
Data = 0 FF FF FF FF FF FF FF FF FF CRC=C9 CRC Failed! No more devices.
ROM = 28 FF E6 3B 90 15 1 B7 CRC OK!
Chip = DS18B20
Data = 0 50 5 4B 46 7F FF 7F 10 FF CRC=FF CRC OK! Temperature = 85.00 Celsius, 185.00 Fahrenheit
No more devices.
On the rare occasions I do get a valid data packet, the temp is crazy high. After putting a scope on the data line I noticed there was a period of time when the data line was at 2.5v(? could this be a collision between the Arduino & the DS18B20). I have made some modifications to the circuit (changing value of pullup resistor, place resistor between Arduino data pin and the DS18B20 with some success but still get very high temp readings. these seem to be valid reading by the DS18B20 since the crc checks out. The DS18B20 works on another device it originally came with so it's not that. Noone else I have checked mentions modifying the circuit so I may be compensation for some other defect. I have attached a copy of the sketch I am running. Any help would be greatly appreciated.
What does this mean? When what is wired? and what "external" power? Do you mean it is not parasite powered?
I've been running your sketch on a Teensy 3.0 for about ten minutes now and it hasn't failed once.
ROM = 28 56 A8 0 4 0 0 11 CRC OK!
Chip = DS18B20
Data = 0 71 1 58 46 7F FF F 10 54 CRC=54 CRC OK! Temperature = 23.06 Celsius, 73.51 Fahrenheit
No more devices.
If you get all FF from the scratchpad it indicates a wiring error - since you were able to read the ROM you probably have a bad connection rather than completely incorrect.
If you get 85C as a temperature and the real temperature is not 85C, it indicates that you haven't given the device long enough to do a temperature conversion since the device was first powered up. The temperature is initialized to 85C on power up.
The fact that you appear to have got the 85C on the second try suggests to me that it is the wiring to the power and/or the ground that is flaky. Check it very carefully.
You do not need a resistor between the DS18B20 and pin 10 on the Arduino. You do need to have a 4.7k pullup resistor between the DS18B20 data pin and +5V (or +3.3V for a 3.3V processor).
Hi Pete. "When Wired for external power" means I am using 3 wires and feeding it 5v from the arduino. I have suspected the breadboard and jumper wires and your input just makes me more skeptical of their quality. I will look into another setup for future testing. As for the delay(100), I just wanted to see the bytes one at a time when I was troubleshooting this. Thanks for your input. I'll let you know how I make out.
I wondered if you were using a breadboard. I've run into problems with flaky wiring on breadboards before and once I even had a bad connection within the breadboard itself. The more I think about that 85C result plus knowing you're using a breadboard, the more I am convinced you've got a problem with the power wiring.
Try replacing just the ground and power wires and see if it fixes the problem.
OK! Thanks for the input Pete. I got it working by reconfiguring for parasite power, but I still can't get it to work on external power. It may not be an issue but I would like to have as many bullets in my gun incase parasite power fails on long wire runs.
Yes Pete that is exactly how I'm powering it. USB->Arduino->DS18B20. Why? Is there something about powering it from the Arduino that may be causing my problem?
BTW. Note that when you use parasite power, both the Gnd and Vcc leads of the DS18B20 are connected to Arduino ground and in that configuration it works. when you use non-parasite powered mode, you have an extra wire that connects the DS18B20 Vcc lead to Arduino +5V. That must be where the problem lies - somehow.
Yeah I read that in the datasheet about grounding VCC. As far as connecting the Arduino & external power supply grounds, I would hope that with 30+ years of electronics experience I wouldn't make such a rookie mistake. So my work continues trying to make external power work.
Use a decoupling capacitor across the power rails near to the device for most reliable configuration, and
don't forget the pull-up resistor on the data line.