Go Down

Topic: DS18B20 & onewire.h (Read 17390 times) previous topic - next topic

dc42


So how many bytes can the AVR chip cope with?


If you're talking about the atmega328pu in the Uno, it has 32Kb of program memory but only 2K of RAM. It's the RAM that normally runs out, and unfortunately the Arduino IDE doesn't give any indication of how much your sketch needs.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

strykeroz

Quote
So how many bytes can the AVR chip cope with?
I should do some research as its a really important thing to know....
That question depends on the model of Arduino you are using, but it's not easy to know how much RAM you need as your footprint will change as your code executes.

Arduino Uno has 2KB of SRAM in which to run anything you write, but that should be plenty more than you need for this project many times over so no need to worry on that front.

Glad you got it going.  Cheers , Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

seanlangford

Nick Gammon

Yes you are absolutely correct and I agree with you and I can now implement the changes to my program to use the onewire bus on one pin and rename each index on the bus thanks to the information provided by Strykeroz.
I keep getting mixed up by the function of parasitc mode and normal powered mode and the onewire function.
I don't need to use parasitic mode because the application doesn't require it but I will run the sensors in parallel and use the onewire function for one pin.
Is there any way that if I plug in a temperature/humidity sensor
I know there's 8 bits to a byte but I wasn't sure where the calculations are done and so I was getting mixed up with the function of the scratchpad and the 2KB of SRAM that Strykeroz recently pointed out.

So basically all I need to do is to link each of the DQ pin2 on the DS18B20's all the way up to a single pin on the Arduino and its sorted? I assume the resistors for each of the sensors stay put due to me not using parasitic mode?

MarkT

No, must be one resistor for the whole bus, otherwise you risk overloading the output transistors.  For longer busses you might want to use a lower value resistor (2k2 perhaps) but 4k7 is the normal value used.  I've had 12 DS18B20's on one short bus no problem (powered, not parasite)
[ I won't respond to messages, use the forum please ]

Nick Gammon

I agree with Mark. The single resistor is needed to "pull-up" the bus, so any of the devices can pull it down again. Too many and there is too much power for them to pull it down. With none, there is nothing to pull down.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

seanlangford

The program worked ok in the sense that it prints out the index value (that I can rename) but I'm getting a LOT of erratic readings.
I will try a lower value resistor to 2k2 and see what happens.

I need to install the project and use different wires of varying lengths to connect the sensors to the Arduino for the application.

Won't I have to lower the resistor value again?

I was hoping that I wouldn't have to calculate the resistance value as I never know how long the sensor wire will be.

This is why I wanted to run one sensor from a single pin. I could calculate the maximum length of wire to use before I started to get erratic readings and work from that.

Maybe instead of using a resistor I could just use a piece of wire to create the resistance through the length lol...?

Its ok running it from a breadboard because there's hardly anything to it but I need to field test it!

If I can't get it to work this way I can always just pair the sensors up to 5 pins to at least keep the erratic readings down and hopefully I can still run the other programs for the other types of sensors that won't overload the SRAM.


Nick Gammon

What lengths of wire are you talking about here?

Quote
Maybe instead of using a resistor I could just use a piece of wire to create the resistance through the length lol...?


4.7K? That would be a long wire.

Are you following the datasheet? The resistor is not in series with the wire.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

seanlangford

I know it would be a long wire haha!
I think I can calculate the resistance per mtr of wire that I'm using so it shouldn't be too difficult to work out but if the cost of the wire exceeds the cost to install an RF module then I will have to do that.

My head is pickled lol...

But its fun!

I have got a single 4k7 (yellow, purple, red) resistor after the supply infront of and between DQ(sensor pin2) & VDD(sensor pin3) of the first sensor then all of the other sensors are wired in behind it where the first sensor supplies the power to the second direct from VDD and the data wire DQ...

I hope this is right....

I can't find examples of powered mode with more than one sensor on the bus on the www....

I've probably wired it in wrong or something!

Have you got any clear examples?

Nick Gammon

#23
Jan 24, 2012, 01:54 am Last Edit: Jan 24, 2012, 01:57 am by Nick Gammon Reason: 1

I think I can calculate the resistance per mtr of wire that I'm using so it shouldn't be too difficult to work out but if the cost of the wire exceeds the cost to install an RF module then I will have to do that.


You have lost me here. Why do you need to calculate that? In what way does the cost of the wire influence the project? I mean, assuming you want to run 100m you knew that from the start, right? This isn't something that should be an issue this far into the design, because if you are using RF modules you will have other issues (eg. not having them all transmitting at once, for one thing).

Google "ds18b20 arduino wiring" - there are lots of examples. If you want to confirm you have done it right, post a diagram, this talk about "a ... resistor after the supply infront of and between DQ" is just confusing.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

MarkT

Yup, just common up the GND, Vdd and output pins from all the devices, provide a 4k7 resistor from output line to Vdd and sufficient decoupling (one 100nF per device if they are separated by cable runs).  The OneWire protocol is very clever and does all the magic.
[ I won't respond to messages, use the forum please ]

seanlangford

Yeah thats what I've done.
I've got the resistor between VDD and VQ...

I tried an experiment by pluggin one sensor in at a time. I took out all the wires from the breadboard.

I wired the 1st one in, got a temperature reading fine.
I wired the 2nd one, got a temperature reading fine.
I wired the 3rd one, I got a temperature reading fine but I found that now the temperatures weren't indexed as they should be. Sensor 1 on the bus now serial prints as the C index(1), sensor 2 serial prints as the A index(0) and sensor 3 has just started serial printing the C index(2) which is correct but it wasn't doing that before.....
The last 4 sensors on the bus registerd the same temperature when I tested all of them at the same time lol...
Crazy!

Do you think that the problem may be the fact that I brought 10 of the sensors off ebay and 3 of the sensors came from RS Componants?

I'm not sure but its too late now and I need to call it a day....

I think what I will do is take a pic and post it on here of my wiring just to make sure....

seanlangford


Yup, just common up the GND, Vdd and output pins from all the devices, provide a 4k7 resistor from output line to Vdd and sufficient decoupling (one 100nF per device if they are separated by cable runs).  The OneWire protocol is very clever and does all the magic.


Whats the decoupling capacitor for?


PeterH

That wiring is correct as far as I can see, assuming green=GND, black=Vdd and red=DQ.

Your 4K7 resister is what is recommended in the data sheet.

I haven't tried running that many sensors off a single bus, but it may be that you need to tweak the pullup resister value slightly to support that many devices. I suggest lowering that pullup resistance and see if it helps. (I'd suggest not going below about 1K though.)
I only provide help via the forum - please do not contact me for private consultancy.

Erk

Spec sheets say R values range from 1k to 4.7k depending on the length and the number of devices on the line. Each device pulls down the data line when it communicates so with the 4.7k on there, the line probably isn't being pulled back high fast enough.

Go Up