Connecting the 1-wire sensors directly to the RPi does allow to test various concepts... I does not, however, suffices the needs of home automation. There are two reasons:
To check if a RPi-based system can at all fit my automation needs, I have built 2 testing modules based on Maxim's DS2382-100 and DS2382-800.
All that you see here is an effect of mixing and digesting examples found on the net. I have repeatedly concluded that I have not clue about what I am doing. At the end, however, I have managed to design and make a PCB, solder the elements and run the modules. Nevertheless - beware! ...and if you find errors, please let me know.
The first step was making a PCB project. On the www.temperatur.nu forum I have found an scheme of an example RPi extension. One can also buy a ready board at www.m.nu. Looking through the pictures and analyzing the list of the elements I managed to 'decode' what fits into what. Don't laugh. This is the first time I ever noticed that there is a difference between a capacitor and a resistor. Designs found at www.abelectronics.co.uk. helped a lot. Finally my schemes look as follows:
In case of the board using DS2482-100 I have decided to provide pins (here – SV1), which allow changing the I2C address. Such a possibility should - if needed - use more than one module at the same time.
I have spent a lot of time thinking, how all the wires should be connected. Should the modules be powered through a microUSB plug, should I use RJ.. plug for I2C. At the end I chose screw terminals. They fit well to all the rest of connections around.
Here are the images of my boards:
The photos of boards shown at the beginning differ slightly from the images above. I have found and corrected some errors. As an example - the P6E6.8A has been replaced by SMBJ6.0A, which was unavailable to me at the time of first soldering.
The boards in the DIN cases look as follows:
All who - similar to me - have had fear for soldering should know that making a PCB is extremely easy and very rewarding. The boards you see above are the first in my life. A thin soldering wire, borrowed iron, half an hour spend watching the EEVBlog... and that's it. The whole thing is not hard at all... and the joy of entering a mysterious terrain of electronics is priceless (even if one does not understand everything...).
The modules you see above are powered from an external 5VDC source. The 1-wire communication and GND are protected with DS9503P. The 5VDC wire powering the 1-wire network is protected with a polyfuse (1206L050YR) and a transil diode (SMBJ6.0A).
In order to test the capacity of the modules I still need to build the network - i.e. place the sensors around my house.
Now a bit of theory and programming. DS2482 are bridges between I2C and 1-wire networks. On the side of the RPi the pins 1 (3.3VDC), 3, 5 (SDA and SCL of I2C) and 6 (GND) are used. It is also necessary to install software related to I2C itself and changing the scripts. The Rpi should no longer control the 1-wire communication by itself (through GPIO4) but should use the I2C instead. The needed commands are:
nano /etc/modprobe.d/raspi-blacklist.conf
and adding „#” before „blacklist i2c-bcm2708”, then:
nano /etc/modules
and adding at the bottom „i2c-dev”. In the next step install the tools related to I2C:
apt-get install i2c-tools
After you restart your RPI and enter:
i2cdetect -y 1
you should see a table showing the found devices which use I2C.
For OWFS to read sensors connected to DS2482 you need:
/opt/owfs/bin/owfs --i2c=ALL:ALL --allow_other /mnt/1wire/
(owfs might install into other directory like: /usr/bin/owfs)
The found DS2482 bridges and sensors can be found in the /mnt/1-wire directory.
You will be better off reading and following a great tutorial presented at http://wiki.temperatur.nu.
On the PHP side It was necessary to modify the scripts:
<?php if ($MainDir = opendir('/mnt/1wire/bus.0')) { while (false !==($MainDirItem = readdir($MainDir))){ if (preg_match('/[0-9]{2}./', $MainDirItem)) { $TempFile = fopen("/mnt/1wire/$MainDirItem/temperature", "r"); if (!$TempFile) { echo "...some problems with temp. file opening..."; } else { $Temperature = fgets($TempFile); echo "Temperature of ".$MainDirItem." = "; echo $Temperature."°C"; } } } }
So much for now. If you are interested in making a PCB, please take a look at Appendix 1 - making a PCB.