1-Wire is a device communication bus system designed by Maxim (former Dallas Semiconductor Corp.) and in principle it is just as simple as the name suggests: Simply connect all sensors in series to one signal line and you're done! This example shows that it is actually that simple, as long as you consider one little thing!
DevDuinoDevDuino is a bread board friendly Arduino-compatible board. It was backed and funded on Kickstarter in late 2017. Here are some technical data:
- Screen: 128×64 OLED Display with SSD1306 controller.
- 8-bit AVR (ATmega32u4)
- Operating Voltage = 5V
- Flash Memory = 32 KB (4 KB used by bootloader)
- SRAM = 2.5 KB
- EEPROM = 1 KB
- Clock Speed = 16 MHz
For me it is a very practical board for quick experiments. The integrated screen, the SD card, the on board voltmeter and the Real Time Clock make a lot of things possible. The processor is not very powerful and does not have much memory, so you have to be careful when programming large projects. But you would know that from other MCUs.
Basically, a 1-Wire bus is a single open drain wire with a single pull-up resistor. The pull-up resistor pulls the wire up to 3 or 5 volts. The cool thing is, that a 1-Wire bus can be driven from a single digital I/O pin on a micro controller. This means that you can control 100 or more sensors with only one I/O pin. And that even with cable lengths of up to 100m. For the DS18B20, the schematic for one sensor looks like this:
Multiple sensors are simply connected in series. The pull-up resistor is only needed once:
This looks very simple, and it is simple. The critical point, however, is the pull-up resistor. The more sensors are connected to the 1-Wire bus, or the longer the cables, the lower the resistor value must be chosen. Since the resistor is already integrated on the breakout board I used, the value of the resistor is reduced with each additional sensor, since they are then connected in parallel:
This will automatically reduce the electrical resistance with every connected sensor breakout board. Of course, this will not work with 100 sensors. According to specifications, the resistor can be reduced to 1kOhm for many sensors or long cables. In my setup the parallel resistance of six sensors is only 783Ohm. So I am already a little bit out of spec. Good to know that it still works.
To avoid the problem with the too low resistor value, you can desolder the resistor of some breakout boards:
Then the equivalent circuit looks like this:
In the video you also can see that fetching the temperatures from the sensors takes quite a long time. This is due to the fact that with each new readout the bus is searched for all existing sensors. This was necessary because in my example the sensors are added at runtime (hot-plugging). In a static system, the addresses of the sensors could be used directly to address the sensors without a search. This would be considerably faster.
The DevDuino board runs with 5V levels. But also with 3.3V levels the setup works very well. For example with a M5Stack:
I hope you like this short example and this code can prove to be useful to some of you. Feel free to message me here if you have questions or comments.
Enjoy!
Regards,
Hans-Günther
Comments