DS18B20 multiple sensors

GoForSmoke:
There are parallel to serial shift registers. You can read a whole line of bits from the pins on chained shift registers (1 CS on the master to CS chip 1 chains to CS chip 2, etc) as SPI serial at 2 MHz. But, hardware SPI may use pins that 1-wire does so maybe use soft-SPI and 1 MHz speed.

The 1-wire stuff is only in software already, so you can pick any pin you want for it.

(gasperinn) That's cool on the 22 connected. How long is the bus physically?

afremont:

GoForSmoke:
There are parallel to serial shift registers. You can read a whole line of bits from the pins on chained shift registers (1 CS on the master to CS chip 1 chains to CS chip 2, etc) as SPI serial at 2 MHz. But, hardware SPI may use pins that 1-wire does so maybe use soft-SPI and 1 MHz speed.

The 1-wire stuff is only in software already, so you can pick any pin you want for it.

That says yes, hardware SPI can live with 1-wire. 2 buses can cross on a single chip. :smiley:

(gasperinn) That's cool on the 22 connected. How long is the bus physically?

OP:
How can i wire multiple DHT22 sensors on Arduino Mega board? Becouse DHT22 data cable has to be each on its own pin, so therefore i have to use as many resistors as there are DHT22 sensors or is there any other way to wire it up?

He can wire the DHT22's through a resistor each to the parallel-in side of 3 daisy-chained shift registers on an SPI bus and read, semi-process and store the states of all the DHT22's as bits at SPI speed, 2MB/sec. To read and store 24 bits through SPI would take only 24 cycles, 1.5 usec and you have all your DHT22 lines as digital states. If you do that 1000x a second, you have loads of time to copy the data to SPI between captures, 976 cycles out of 1000.

@afremont, @GoForSmoke, i dont know, every sensor is physically cca. 15m away from the Arduino board, and it is wired with standard UTP network cable :slight_smile:

@GoForSmoke, i don't realy understand how do you meen, do you maybe have any shematic picture or something like that? :blush:

afremont:
Time to look at the datasheet, it tells all. The only difference is that you have to supply extra power when a temp conversion (or EEPROM write) is in progress. The datasheet shows how to do it, it's simple; it takes an extra i/o pin though. You just enable the pin after issuing the conversion command. That in turn bypasses the pull-up resistor on the data line (Q) so that the device has plenty of power to do the temp conversion or write to its EEPROM. Look at the datasheet, they have a nice write-up on how it all works.

Is that for parasite mode only?

gasperinn:
@GoForSmoke, i don't realy understand how do you meen, do you maybe have any shematic picture or something like that? :blush:

Using SPI bus shift registers, it would connect like in the Daisy chain SPI configuration here:
Daisy chain SPI configuration

The 3 SPI slaves would be 3 8-bit parallel to serial shift registers. A sensor would hook to each input pin which is not shown in the wikipedia diagram. The registers read the digital state from the sensor and on command, copies those as bits. Then the bits are shifted out of the chips and read by the master in as fast as 1.5 microseconds.

The register has its own power line, some people power leds off them on external power.

GoForSmoke:

afremont:
Time to look at the datasheet, it tells all. The only difference is that you have to supply extra power when a temp conversion (or EEPROM write) is in progress. The datasheet shows how to do it, it's simple; it takes an extra i/o pin though. You just enable the pin after issuing the conversion command. That in turn bypasses the pull-up resistor on the data line (Q) so that the device has plenty of power to do the temp conversion or write to its EEPROM. Look at the datasheet, they have a nice write-up on how it all works.

Is that for parasite mode only?

Yes it is.

afremont:

GoForSmoke:

afremont:
Time to look at the datasheet, it tells all. The only difference is that you have to supply extra power when a temp conversion (or EEPROM write) is in progress. The datasheet shows how to do it, it's simple; it takes an extra i/o pin though. You just enable the pin after issuing the conversion command. That in turn bypasses the pull-up resistor on the data line (Q) so that the device has plenty of power to do the temp conversion or write to its EEPROM. Look at the datasheet, they have a nice write-up on how it all works.

Is that for parasite mode only?

Yes it is.

Then a common power line could save an I/O pin ... is that per device?

I don't know if you can save an i/o pin, but you can sure save running an extra wire to all the devices. In parasite mode, the device draws power thru the data pin. The Vcc pin of the device is tied to ground so that the device "knows" that it is in parasite mode. Enough power can be drawn thru the pullup resistor to do most things. However, temp conversions and EEPROM writing need more power than can be sucked thru the resistor in a short time. This is where the microcontroller toggles a pin connected to a transistor that "pulls up" the data line to Vcc bypassing the resistor. Now the sensor on the other end of the wire has all the juice it needs to do the conversion. The datasheet for the sensor goes into great detail about all this.

I would rather the wire than a pin and a wire or many pins and many wires. Using the pin for extra power only when the device works will need a wire regardless and might need many of both.

Why would you need a pin to supply power if you're not running off a pullup?

Is the point of parasite power to reduce power consumption for battery operation?

The dallas 1-wire bus is made up of either 2 or 3 wires with the sensors attached along the bus. One bus wire is ground and one is the data line. The third (optional) wire is to carry a full 5V to the devices. Since the data bus uses a pullup resistor, power can be sourced from the bus by the device. If you ground the normally 5V supply pin on the device, it will draw power from the data line.

Since the data line on the bus has a pullup on it, only a limited amount of current can be supplied to the device. This is fine until the device needs to execute a CONVERT command to sample the temp and measure it. This requires more current than can be drawn thru the data line. So back at the head end of the bus (where the microcontroller is) after issuing a CONVERT command enables full power to the data line by bypassing the pullup resistor. The device can then draw as much current as it needs. After the CONVERT command is finished, the microcontroller disables the pullup bypass so that communications can take place on the data line. This saves running the 5V power wire to each device.

I don't know what you mean about many wires, all devices can reside on one bus. Please just download the document, it explains it all much better.

afremont:
The dallas 1-wire bus is made up of either 2 or 3 wires with the sensors attached along the bus. One bus wire is ground and one is the data line. The third (optional) wire is to carry a full 5V to the devices. Since the data bus uses a pullup resistor, power can be sourced from the bus by the device. If you ground the normally 5V supply pin on the device, it will draw power from the data line.

Since the data line on the bus has a pullup on it, only a limited amount of current can be supplied to the device. This is fine until the device needs to execute a CONVERT command to sample the temp and measure it. This requires more current than can be drawn thru the data line. So back at the head end of the bus (where the microcontroller is) after issuing a CONVERT command enables full power to the data line by bypassing the pullup resistor. The device can then draw as much current as it needs. After the CONVERT command is finished, the microcontroller disables the pullup bypass so that communications can take place on the data line. This saves running the 5V power wire to each device.

I don't know what you mean about many wires, all devices can reside on one bus. Please just download the document, it explains it all much better.

I see that no extra pin is needed. The data pin goes OUTPUT HIGH during the conversion only.

If the device has a conductive chassis you would only need 1 wire.

GoForSmoke:

afremont:
The dallas 1-wire bus is made up of either 2 or 3 wires with the sensors attached along the bus. One bus wire is ground and one is the data line. The third (optional) wire is to carry a full 5V to the devices. Since the data bus uses a pullup resistor, power can be sourced from the bus by the device. If you ground the normally 5V supply pin on the device, it will draw power from the data line.

Since the data line on the bus has a pullup on it, only a limited amount of current can be supplied to the device. This is fine until the device needs to execute a CONVERT command to sample the temp and measure it. This requires more current than can be drawn thru the data line. So back at the head end of the bus (where the microcontroller is) after issuing a CONVERT command enables full power to the data line by bypassing the pullup resistor. The device can then draw as much current as it needs. After the CONVERT command is finished, the microcontroller disables the pullup bypass so that communications can take place on the data line. This saves running the 5V power wire to each device.

I don't know what you mean about many wires, all devices can reside on one bus. Please just download the document, it explains it all much better.

I see that no extra pin is needed. The data pin goes OUTPUT HIGH during the conversion only.

If the device has a conductive chassis you would only need 1 wire.

There appears to be a communications gap here, I guess I'm not explaining it effectively. I'd like to think that I know how this stuff works considering I successfully implemented a SEARCH ROM function in PIC assembler about 10 years ago. It's in the public domain, and I wrote it straight from the Dallas flow chart. I have some 1-wire temp sensors on one of my boards right here in front of me and I have used both methods to power the devices in the past.

What you mean by the data line "OUTPUT HIGH" during a conversion only? It does precisely what I said, it expects to be able to draw power from the data line in parasite power mode since the regular power pin is grounded. The microcontroller must assure that sufficient power is available by enabling what Dallas calls a "strong pullup". This is just powering the data line by bypassing the pullup resistor, either by a transistor or some other method that usually requires 1 pin to enable. It all boils down to one thing, if you can afford a pin, you can save on wiring. You'll also have to modify your software to work with it. Speaking of the devil, if you look at the 1-Wire Arduino library you will see that the library author allowed for using parasite power mode.

I wish you much luck with your endeavors to use chassis ground as part of your circuitry. You'll certainly learn allot about dealing with EMI.

GoForSmoke:

afremont:
The microcontroller must assure that sufficient power is available by enabling what Dallas calls a "strong pullup".

I dunno about PIC but with AVR I can make a pin pullup by setting it INPUT HIGH. If I'm not using that same pin to read data for a while, I can switch it to OUTPUT and give the line 5V. If I want to, I can switch the same pin to INPUT again. With the ability to switch modes in less than a usec, why do I need an extra pin? I can throw an extra resistor, even 1k on the pin and it won't affect the current from low-tolerance pullup in the AVR (20k-50k, does PIC have built-in pullup resistors?) much but limit the OUTPUT HIGH current lots.

The internal pullups of an AVR or PIC are not strong enough to operate the bus normally. I suppose you could switch the data line pin to output mode and power the bus during a conversion or EEPROM write, but it may not be enough current if you have several sensors and you issue a mass temperature convert. In the case of the OP with 20 sensors, it wouldn't be near enough. You'd need another pin and a transistor.

So there's conditions where one way makes more sense than another. Dat's noice.

This becomes interesting when using breakout boards where the 4.7k resistors are mounted on the board itself... This probably means that one is limited to around 10 or so DS18B20's from DFROBOT (see tinyurl.com/b6h6evz) or similar stuff. If you need more than ~10, one should probably use the discrete sensors instead.

Why would you need "another pin" to supply 5V to the sensors ?

You'd need another wire, to use the 3 wire mode, but you could connect that third power supply wire to +5V in
all sorts of ways without using "another pin".

I guess he would rather spend a pin and extra code than some wire.
That pin would feed the existing data wire with more current through a transistor.
If you've got 2-conductor wire, that will work without another wire and all those connects.
Or if you have a ground chassis (most any car or bike) you could get away with 1 wire.

michinyon:
Why would you need "another pin" to supply 5V to the sensors ?

You'd need another wire, to use the 3 wire mode, but you could connect that third power supply wire to +5V in
all sorts of ways without using "another pin".

Clearly I've missed it again. In parasite power mode, you don't supply power to the Vcc pin of the sensor, it is GROUNDED. The sensor gets its power from the DQ data line, but the 1mA supplied is not enough to power the device during a temperature conversion. The device requires 1.5mA and the 4.7k pullup is too big. Also, you can tell all the devices on the bus to start a temp conversion at the same time so that they overlap the long delay during the conversion (750mS for 12 bits). If you had 20 devices, then you'd need to supply 30mA to the DQ bus by bypassing the pullup in some fashion. At any rate, the Vcc pin isn't being connected to anything but ground when using parasite power mode.

EDIT: Please, I beg both of you to download this document and look at Figure 4 and Figure 5 if nothing else:
http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
Please.

GoForSmoke:
I guess he would rather spend a pin and extra code than some wire.

Well yeah, it's kinda the whole point of having parasite power mode. I didn't invent it, just trying to explain how it works. By using only two wires (DATA and GND aka 1-wire parasite mode), you can often more easily find some way to wedge it into an existing system. For example you can stick these on unused pairs of cat-5 cable. It would be allot messier if you needed another wire. Running cable is not cheap.

You have to keep in mind that none of these devices were created with the home hobbyist in mind. They were designed to solve real world problems in an industrial environment. Sure it's easy to run another 12" wire at home, it's another thing to demand a shielded set of three or four wires run thru a factory when you can just toss some code and an open i/o pin at it and use an empty twisted pair already going right where you need it. Not to mention that if you have an old plant, you probably have some network coax already installed that's not doing anything since the cat-5 was installed. You could use that for 1-wire if you wanted.