Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

DS18B20 only finds one sensor

Status
Not open for further replies.

MrDEB

Well-Known Member
Using the software uart and two DS18B20 sensors the code only finds one sensor.
I connected both sensors seperatly to see if they actually work. =Both work
Wondered if both had same ID number= different ID #'s
Next to try is putting a delay between sensor read. ?? Maybe a quirk with software uart??
Code:
DEVICE = 18F2420
CLOCK = 8

// import modules...
INCLUDE "DS18B20.bas"
INCLUDE "convert.bas"
INCLUDE "suart.bas"
INCLUDE "internalOscillator.bas"

// on display temperature event...
EVENT OnDisplayTemp()
   DIM TempA AS SHORTINT
   DIM TempB AS WORD
   DIM Index AS BYTE
  
   RomID = SearchRomID
   GetTemp(TempA, TempB)
   UART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C")
  
   // display ROM ID...
   UART.Write(" ($")
   Index = 3
   REPEAT
      UART.Write(HexToStr(SearchRomID(Index),2))
      DEC(Index)
   UNTIL Index = 0
   UART.Write(")",13,10)
END EVENT
  
// program start...
uart.SetBaudrate(sbr9600)
uart.setmode(umtrue)
uart.settx(portb.7)
SetPin(PORTC.2)

// if we have some DS1820 devices connected to the bus,
// then display temperature for each one...
IF Count > 0 THEN
   WHILE true
      ConvertAll              
      FindAll(OnDisplayTemp)
      DELAYMS(1000)
   WEND
ENDIF
 
This is an example straight from the Swordfish install. It is pretty much guaranteed to work.

So.....

Two DS18B20 sensors with identical serial numbers? Go bet on the lottery if this happens. Dallas guarantees that it cannot.

A quirk in the software UART that somehow causes the sensors not be read? Not sure how you picture that happening...unless you set the UART TxD or RxD pins to the same pin as the Onewire data pin.

Do you have the proper value of pullup resistor connected? I suspect not.
 
The sensors were purchased on Ebay so quality?
I connected the sensors separately to verify numbers and if they work =all ok and different numbers
using TAP28 and the C.2 port with a 10k pullup resistor between 5v+ and data pin. Maybe change out to ??
Reason I questioned the software is if I change the baud rate lower than 9600 then all I get are ?????????
Go higher than 9600 I get nothing. Yes I changed both the code and PICKIT2 setting to match.
My next step is go back to the data sheet for the sensors to verify
 
Data sheet says a 4.7k Changed out resistor but still only reads one sensor.
Using the code to read multiple sensors, I removed the one sensor that was indicated on the UART disply. Still had unreadable sensor connected and ran program again
Sensor reads ok with a different rom number as it should.NOTE I have one sensor laying on bench and other in ice bath.
Going to hack at this after dinner. Venison steak Smells good!!
 
Your problems with the serial interface may fall back on your insistence on using the internal oscillator. The timing requirements for RS232 communications are tight. The tolerances on the internal oscillator may fall outside the requirements for successful communications. Maybe saving 14 cents isn't worth all the trouble you've had when attempting to use the internal oscillator?

Tayda crystal.jpg


tayda cap.jpg
 
So I do owe MrDEB an apology.

I connected a couple DS18B20 sensors in parallel with the correct 4k7 resistor, and only one sensor was read using the software UART routines for output (see comment below).

Time for troubleshooting. First stop...the Swordfish Basic forum page to see if there were updates to any of the OneWire modules. None that I could find. Another Swordfish example is a OneWire search program. It will just output a list of OneWire devices and their ROM-IDs. Again, only one sensor reported.

I vaguely remember playing with these modules in the past, and I had every reason to believe they work. Back to the Swordfish Basic forum, not to ask a question but to see any evidence these modules work. Yep, there's a printout showing several different devices found – a solid indication the modules work as described. Just to verify, I compared the posted code to my sample file code just to be sure I didn't miss an update somewhere. Exactly the same, except the posted code used the hardware UART, while my code (and MrDEB's) used the software UART.

Doesn't seem like this should cause a problem, but it's simple enough to test (and easier to test than to write a coherent question)...one letter has to be added in about 6 write statements, or just reload the original, unmodified program.

I recompiled the OneWire search program, loaded it to my board, switched the PICkit 2 cable to the UART connector and saw the expected result. The UART connector on the TAP-28 board is wired so that simply removing it from the 6-pin ICSP connector to the 6-pin UART connector results in the correct connections to use the UART tool.

Made the same few changes to the DS18B20 ReadAll program, compiled and archived the expected results.

image.jpg


So, was this extraordinary troubleshooting? Require any specialized or in-depth knowledge? No. I changed code that I could reasonably assume worked, and it didn't work after my changes. This is baby-step 101 troubleshooting. This is stuff that anybody doing any kind of programming should be able to do without begging for help in a forum.

Why don't the OneWire modules and the software UART module play nicely together? I don't know and I don't particularly care at this point. Figuring out this question would require some more in-depth knowledge. Why don't I care? The Swordfish software UART module is widely known to be crap – useful for debugging, but I wouldn't use it for anything important.

So that brings up the question....why do I used the software UART module if it's crap? I configure the software UART for program output only to the ICSP connector. This allows me to program a chip and instantly switch over to the PICkit UART tool to monitor program output without even moving a cable. Like I said here, and in the article at Digital-DIY where MrDEB learned of the technique, it's a good technique for quick&dirty debugging.

So, I spent an hour setting this up, testing it out, researching it and doing baby step troubleshooting on MrDEB's behalf, and another hour and a half writing this discussion because he didn't take 5 minutes to do rudimentary troubleshooting. I don't think a "thanks", "THANKS" or even a "tHANKS" is going to make up for this waste of time. In fact, I suspect MrDEB will blame me for his problems since he followed something I posted long ago – see link below.

MrDEB, your problems aren't worth my stress and a hastily tossed off "THANKS" isn't going to buy anymore help from me. Little Ghostman has given you some excellent advice and suffered unfairly for his efforts. You might go back and find that advice. Your sucker pool of people willing to help seems just about empty.



Not Quite Trivial - A Tip for using the Software UART with the PICKit 2
 
Last edited:
The inverted output using the software uart is where I was headed next thinking that instead of DEC the index maybe INC? Just a thought. I really like using this handy software uart feature. I to looked over at the Swordfish Forum and that's why I added SETALLDIGITAL but it didn't make any difference. If I can't get this software uart to work by outputting the multiple sensors I will just resort to using the LCD as the project is going to use it anyway. One of the reasons for using the software uart is I intend to add in several computations to determine a refrigeration effiency using outside temp and inside temp. Thanks for the software uart, I was wondering if that was your creation.
I did lots of trouble shooting, reason for ice bath, adding SETALLDIGITAL trying several other sensors etc I don't blame anyone for my troubles as stuff happens.
 
Wow, why bother to even try to explain anything?!? The number of points missed in my post is beyond belief.

What does SetAllDigital do? Do you have a #%^+>€*~ clue? Let me help. It turns off the analog inputs on PortA so they may be used as digital I/O. Are you using any PortA pins in this code? NO. Then it doesn't matter.

Change the DEC to "maybe INC"??? Why don't you try changing it to HIPPOPOTAMUS? Or maybe CHEESECAKEFACTORY? All three options make the same amount of sense. Geez. Go buy the Extra Big Dummies Guide to Basic and get a clue. Try to engage your brain and follow the LOGIC of the commands.

Why are you throwing out the baby with the bath water on this? Yes, I know it's the way you operate, but geez oh grief. The 18F2420 has perfectly excellent HARDWARE UART. There's even a connector on the TAP-28 board that says UART. Damnit.... I just spent an hour and a half explaining above how I tested the code by NOT switching to the software UART and moving the 6-pin PICkit 2 cable from the ICSP connector to the UART connector so I could use the PICkit UART tool to see the output. Do you not read the replies people post to YOUR questions???

image.jpg
 
YES I read all the replies. I experimented and it failed. Tried out the OW search.bas and the software uart still only recognizes one sensor. Just going to use the normal uart instead of the software uart But curious why the software uart will not perform but moving on from here.
Maybe that's my problem, TOO curious why something does what it does. Get too hung up with why and why not. I had already resorted to using the normal uart before seeing the above post as I tried several different other ideas but none worked.
The software uart is a nice program, just wish it worked for this application.
Moving on
 
....I had already resorted to using the normal uart before seeing the above post....

If you had indeed tried this with the hardware UART, perhaps you could have been so kind and thoughtful to post the success of those results? That small courtesy would have saved me two and a half hours wasted for your benefit.. Does the thought not even enter your mind that when you ask a question here, you are asking people to take time to help you?
 
I tried using the hardware uart about an hour before I saw your post #8 and the multi sensors are showing that they do indeed work.
I was still trying to get the software uart to recognize multiple sensors since post #4 but resorted to hardware uart before I saw post #8 and all the work that went into post #6 to discover that my issue with reading multiple sensors is a querk with the software uart.
Now I need to retrace my steps to get the DS18B20 readall.bas to just output only temperature in degrees, edit all references to the software uart etc. Lets call it housecleaning so I am not stumbling over old code that is not needed.
We both learned that the software uart in its form will not work with multiple sensors. WHY?? at this point I am moving on with project. And just for info, I am redoing the beer cooler project using a button press routine to change the temp settings instead of the wacky method I used (ADC method). Your greenhouse controller project inspired me to go a better route.
I can honestly say that Jon inspired me to do better.
 
Venting – Asking For Help in the Forums

If you have a topic that runs pages, and you can't tell what the solution was, perhaps you should follow these comments. Of course, they are just my opinions for what they're worth. But if you can't point the the conclusion, chances are you're abusing the people who are attempting to help you.
 
Someone needs to follow their own advice
http://digital-diy.com/forum/****-chat/venting-asking-for-help-in-the-forums-t3020.html
 
So you posted the link I posted but you don't know how to format it nicely? Is there another point to your post?
 
Status
Not open for further replies.

Latest threads

Back
Top