netphreak
Posts: 4
Joined: Mon Nov 19, 2012 10:12 pm

1-wire and/or i2c - beginner help...

Mon Nov 19, 2012 10:41 pm

Hello!

I am planning a combined solar/wood heating system in my old house. Quite a job picking the right part for it, but that belongs elsewhere.

What I seek here, is some basic guidelines on building a control/monitoring system running on a rPi :)

Alright, my needs should be fairly simple for many of you in here, but I'm a little lost: I need about 12 temperature sensors (measuring water and air temperatures between 4 and 100 °C), and store the temperatures in a MySQL database. Since I'm a limited software programmer, I intend to use Cron to execute a PHP script, and send commands to a relay when measured temperatures goes higher or lower than whats desired. The sensors could be up to 25 meters from the rPi itself.

Now, I could head over to hobby-boards.com (please remove the link if not allowed here), and buy a 1-wire USB adaptor, sensors and two relays, and build it all for the 1-wire bus - but is it the best way to go? I know there's built in i2c support on some pins of the rPi... But reading up on i2c is hard for me with limited knowledge :oops: And - I've read some cons about the 1-wire bus when it comes to "timing", and it being flaky?

Any links or help would be greatly appreciated!

rooster
Posts: 100
Joined: Thu Aug 02, 2012 8:09 pm

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 11:38 am

netphreak wrote:Hello!

I am planning a combined solar/wood heating system in my old house. Quite a job picking the right part for it, but that belongs elsewhere.

What I seek here, is some basic guidelines on building a control/monitoring system running on a rPi :)

Alright, my needs should be fairly simple for many of you in here, but I'm a little lost: I need about 12 temperature sensors (measuring water and air temperatures between 4 and 100 °C), and store the temperatures in a MySQL database. Since I'm a limited software programmer, I intend to use Cron to execute a PHP script, and send commands to a relay when measured temperatures goes higher or lower than whats desired. The sensors could be up to 25 meters from the rPi itself.

Now, I could head over to hobby-boards.com (please remove the link if not allowed here), and buy a 1-wire USB adaptor, sensors and two relays, and build it all for the 1-wire bus - but is it the best way to go? I know there's built in i2c support on some pins of the rPi... But reading up on i2c is hard for me with limited knowledge :oops: And - I've read some cons about the 1-wire bus when it comes to "timing", and it being flaky?

Any links or help would be greatly appreciated!
Hi

this all worked fine for me

http://www.raspberrypi.org/phpBB3/viewt ... 22#p214222

which links to

http://www.trainelectronics.com/Raspber ... index.html

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 1:50 pm

I don't know much about I2C either but your plans sound to me like something perfectly suitable for a 1-Wire network.

On the RasPi you have a choice of using the GPIO based software driver, although other have it working I would be wary of using that over the distances you are talking (up to 25m from the RasPi will probably mean a total network length of 30-40m in practice as you will never be taking the direct route from one sensor to the next).

Another option if you have a spare USB port is a DS9490R which will be more than capable of the sort of network you are considering.

If you don't have a spare USB port then you could consider one of the RPI2 modules I sell (see the link in my signature) which are i2c connected and plug into the expansion header.

As far as the relay outputs are concerned you have the option of either connecting them to the RasPi's GPIOs (via a suitable buffer of some kind) or building/buying something based on the DS2408 1-Wire IC which gives you 8 digital inputs/outputs that you can use to control relays.

HTH,
Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

netphreak
Posts: 4
Joined: Mon Nov 19, 2012 10:12 pm

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 6:25 pm

Thank you for your replies :)

repton - do I understand correctly - if I use the software based connection on the rPi, the cable length is limited compared to using RPI2 or DS9490R? I have measured distances more thorough now, and it's considerably longer runs than 25 meter, unless I use a 1-wire hub and a "star topology" (which would mean more cabling work).

Do you know the total distance limit for RPI2 or DS9490R?

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 8:02 pm

netphreak wrote:repton - do I understand correctly - if I use the software based connection on the rPi, the cable length is limited compared to using RPI2 or DS9490R? I have measured distances more thorough now, and it's considerably longer runs than 25 meter
You understand perfectly, yes. I would probably be wary of using the kernel based master with anything more than about 10-15m total cable run.
netphreak wrote:Do you know the total distance limit for RPI2 or DS9490R?
I have an RPI2 I'm testing here and it is working fine with a total of 125m of cat5, if I add any more though it starts playing up. That is just with big coils of cat5e on a desk though with no nearby sources of interference though, in the real world you might not get quite that far. Maybe 100m is a sensible maximum length in the real world but it will always depend on how the cable is routed. I don't know about the limit for a DS9490R as I've not tested one with long cables but I would think it would be fine up to around 100m too.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

netphreak
Posts: 4
Joined: Mon Nov 19, 2012 10:12 pm

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 8:42 pm

Thanks, great to learn this now and not later in the process :)

With a 1-wire hub and a star topology - then I count cable length for "each corner of the star", and not the total anymore? Distance to each corner should not exceed 100m or so? Or still total length of all cables? Sorry, I'm sure there's much better ways to ask this question :oops:

RPI2 - will it complicate in any way that it uses I2C in any way?

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 9:03 pm

netphreak wrote:With a 1-wire hub and a star topology - then I count cable length for "each corner of the star", and not the total anymore? Distance to each corner should not exceed 100m or so? Or still total length of all cables?
The DS2409 based hubs effectively work as a switch so the software switches in one leg at a time and so the cable length is "per leg" and not the total length of all cables. The issue with this is that the DS2409 is discontinued and so these hubs are hard to come by now.

Hobby Boards have recently brought out a new hub based around a custom 1-Wire IC. I assume this works on a similar principle but I've never used one and I don't know what software supports it.

Whatever hub you use it will need your software to support it, so check before you buy.
netphreak wrote:RPI2 - will it complicate in any way that it uses I2C in any way?
It depends what software you intend to use. The RPI2 is fully supported by OWFS, as far as I know nothing else supports I2C based masters (like the RPI2) at the moment.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

netphreak
Posts: 4
Joined: Mon Nov 19, 2012 10:12 pm

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 9:11 pm

Thanks, OWFS it is.

Can I use I2C slave devices in a combination with 1-wire sensors on RPI2? Otherwise I may be better off getting the USB controller...

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 9:27 pm

netphreak wrote:Thanks, OWFS it is.

Can I use I2C slave devices in a combination with 1-wire sensors on RPI2? Otherwise I may be better off getting the USB controller...
You can, the RPI2 is simply one device on your I2C bus and you can connect others too. For example on one of my RasPi's I have an I2C RTC module from ABElectronics with an RPI2 stacked on top of it and it works perfectly. If I use i2cdetect to scan the bus it shows two devices, the DS1307 on the RTC and the DS2482 on the RPI2.

The only challenge you might have is connecting everything up. My example above works because ABE's RTC module has a GPIO header with long pins that allows you to stack other stuff on top of it. The RPI2 module however doesn't, so have a think about how you will connect it all up before you make your decision.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

9403kevin
Posts: 3
Joined: Tue Nov 13, 2012 12:40 am

Re: 1-wire and/or i2c - beginner help...

Tue Nov 20, 2012 9:55 pm

I'm doing something fairly similar...

I've used 4 x DS2482-100 1-wire bus masters (with different i2c addresses) on the i2c bus (with 3v3 to 5v level shifters) to give me 4 separate 1-wire networks, which should hopefully each be able to work upto 100m each. Depending on what topology suits your network you might only need 1 or 2.

owfs seems to work perfectly out of the box with the DS2482-100.

I'm then controlling the 16 relays using two PCF8574's I/O expanders (also on the i2c bus - but this time on the 3v3 part).

Regards,

Kevin

p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Re: 1-wire and/or i2c - beginner help...

Tue Nov 27, 2012 6:01 pm

I'm afraid that DS2482-100 will not work with 100m cable. Maybe with external optional MOSFET(but not sure if owfs supports it yet). It lacks internal active pullup resistor.
As for "strength" the best one is DS2482 serial to 1wire converter it has active pullup.
There is also DS2482-800 with has 8 outputs connected through a hub to one 1-wire bus and has active pullup.

Generally the for measuring temperature there is nothing better and cheaper than 1-wire and DS18B20 maybe it's not the fastest bus but the temperature it's enough.

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Tue Nov 27, 2012 9:37 pm

p4trykx wrote:I'm afraid that DS2482-100 will not work with 100m cable. Maybe with external optional MOSFET(but not sure if owfs supports it yet). It lacks internal active pullup resistor.
Yes it will, I have one working flawlessly here with a couple of sensors on the end of 125m of Cat5e, and that is without the external MOSFET.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Re: 1-wire and/or i2c - beginner help...

Wed Nov 28, 2012 12:52 am

I think I based my knoledge on this http://www.maximintegrated.com/app-note ... vp/id/4206
But it's good to know that DS2482-100 works with long buses.
I was wondering if there is some speed advantage with having 4 ..-100 instead of one -800. I know that DS2482-800 has one 1-wire bud and has to switch between 8 channels. So 4 DS2482-100 should be faster?

There is also new chip DS2483 which comes with integrated level converter and latest owfs version will support it(I tested on cvs version). However it's hard to get I only got some samples from Maxim.

AndyNC
Posts: 42
Joined: Thu Aug 30, 2012 7:04 am

Re: 1-wire and/or i2c - beginner help...

Fri Nov 30, 2012 9:28 pm

Hi,
Sorry if I'm hijacking this thread but some of the subject matter seems similar and some of the answers would help other who are trying to get owfs working with RPI and a DS2482-100.

I've bought and built an RPI2 host adapter. I've plugged it in and with the i2c driver installed, when I do "sudo i2cdetect -y 0" I see the device 18 in the i2c address list. So I believe the drivers are all installed and working.
I installed owfs and it worked with the FAKE line in the owfs.conf in that owdir gave sensible results and also the httpd worked in that I could browse the fake tree. So I beleive owfs was installed and functioning correctly.
BUT obviously I don't want to look at fake data so I edited owfs.conf adding device = /dev/i2c-0 and commented out the FAKE lines and restarted the server but it Failed. I don't know where a log file would reside so I couldn't diagnose any further. I then added server = port ????, (I can't remember which port number but is was the same as the server port lower down in the conf file) and the /etc/init.d/owserver restart worked OK but the owdir did not return anything.

My conclusion is that I need some help with a couple of correct lines to add to the owfs.conf to make it work for the RPI and where I can find the log file so I can see the cause of error.

I google the web and I can't find a owfs.conf example for the RPI.


Many thanks

Andy

Edit: I'm running:
Linux raspberrypi 3.2.27+ #160 PREEMPT Mon Sep 17 23:18:42 BST 2012 armv6l GNU/Linux

p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Re: 1-wire and/or i2c - beginner help...

Fri Nov 30, 2012 9:32 pm

Did you load the module i2c-dev ?

Code: Select all

modprobe i2c-dev
Try this

Code: Select all

sudo owfs --debug --i2c=/dev/i2c-0:ALL /mnt/owfs/ 

AndyNC
Posts: 42
Joined: Thu Aug 30, 2012 7:04 am

Re: 1-wire and/or i2c - beginner help...

Fri Nov 30, 2012 10:16 pm

Many thank for your reply

I had uninstalled owfs so I've just reinstalled with

Code: Select all

sudo apt-get install owfs 
which gave no error .
I restored the conf file to use FAKE and

Code: Select all

/usr/bin/owdir
gives

Code: Select all

xxxxx@raspberrypi ~$ /usr/bin/owdir
/10.67C6697351FF
/05.4AEC29CDBAAB
/bus.0
/uncached
/settings
/system
/statistics
/structure
/simultaneous
/alarm
lsmod gives

Code: Select all

xxxxx@raspberrypi ~$ lsmod
Module                  Size  Used by
i2c_dev                 5587  0
snd_bcm2835            19889  0
snd_pcm                74834  1 snd_bcm2835
snd_seq                52536  0
snd_timer              19698  2 snd_seq,snd_pcm
snd_seq_device          6300  1 snd_seq
snd                    52489  5 snd_seq_device,snd_timer,snd_seq,snd_pcm,snd_bcm2835
snd_page_alloc          4951  1 snd_pcm
spidev                  5136  0
spi_bcm2708             4401  0
i2c_bcm2708             3542  0
I then did mkdir /etc/owfs
and then

Code: Select all

xxxxx@raspberrypi ~$ sudo owfs --debug --i2c=/dev/i2c-0:ALL /mnt/owfs
DEBUG MODE
libow version:
        2.8p15
FUSE library version: 2.9.0
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.17
flags=0x0000047b
max_readahead=0x00020000
   INIT: 7.18
   flags=0x00000011
   max_readahead=0x00020000
   max_write=0x00020000
   max_background=0
   congestion_threshold=0
   unique: 1, success, outsize: 40
unique: 2, opcode: GETATTR (3), nodeid: 1, insize: 56, pid: 6543
getattr /
   unique: 2, success, outsize: 120
unique: 3, opcode: GETXATTR (22), nodeid: 1, insize: 65, pid: 6543
   unique: 3, error: -38 (Function not implemented), outsize: 16
unique: 4, opcode: OPENDIR (27), nodeid: 1, insize: 48, pid: 6543
   unique: 4, success, outsize: 32
unique: 5, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 6543
getdir[0]
   unique: 5, success, outsize: 440
unique: 6, opcode: LOOKUP (1), nodeid: 1, insize: 56, pid: 6543
LOOKUP /10.67C6697351FF
getattr /10.67C6697351FF
   NODEID: 2
   unique: 6, success, outsize: 144
unique: 7, opcode: LOOKUP (1), nodeid: 1, insize: 56, pid: 6543
LOOKUP /05.4AEC29CDBAAB
getattr /05.4AEC29CDBAAB
   NODEID: 3
   unique: 7, success, outsize: 144
unique: 8, opcode: LOOKUP (1), nodeid: 1, insize: 46, pid: 6543
LOOKUP /bus.0
getattr /bus.0
   NODEID: 4
plus loads more similar.
But still I get

Code: Select all

xxxxx@raspberrypi  /usr/bin/owdir
/10.67C6697351FF
/05.4AEC29CDBAAB
/bus.0
/uncached
/settings
/system
/statistics
/structure
/simultaneous
/alarm
Which is the FAKE results.

I put back

Code: Select all

device = /dev/i2c-0
server = port 4304
into the conf file and restarted the server and now /usr/bin/owdir gives nothing.

So I believe I need something in the conf file.

Many thanks

Andy

off to bed now, early start in the morning.

p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Re: 1-wire and/or i2c - beginner help...

Fri Nov 30, 2012 10:57 pm

I just tested the p15 from apt-get.It works for me. Try doing exactly like this ;-)
get the owfs.conf I attached. For some reason when I delete /etc/owfs.conf owfs does not start at all.
make sure i2c-dev i2c_bcm2708 are loaded

Code: Select all

sudo mkdir /mnt/owfs
 

sudo owfs --i2c=/dev/i2c-0:ALL /mnt/owfs/
sudo ls /mnt/owfs
sudo cat /mnt/owfs/bus.0/interface/settings/name
Also this is my i2cdetect

Code: Select all

 pi@raspberrypi ~ $ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --      
Attachments
owfs.conf.zip
(632 Bytes) Downloaded 187 times

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Sat Dec 01, 2012 11:15 am

I think there is perhaps some confusion here about OWFS.

There are two different ways of using OWFS that are maybe getting confused here.

If you run the "owfs" binary then you will end up with the filesystem mounted somewhere, usually /mnt/owfs, and you can then in theory list and read the files in there with the normal tools like "ls" and "cat".

If you run the "owserver" binary then the filesystem isn't mounted as such and you can then use the owfs utilities such as "owdir" and "owread" to list and read the data.

You only need to be running one or other of these depending on how you wish to access the data.

I installed my OWFS from the source rather than the package, but I found the owfs.conf that it came with was fine and needed no changes at all for the RasPi. Once installed you should need to do no more than:

sudo owserver --i2c=/dev/i2c-0:ALL

to get it started and then owdir and owread should let you see whatever is connected.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Sat Dec 01, 2012 11:20 am

AndyNC wrote:So I believe I need something in the conf file.
Looking at the sequence of commands in that post it looks like you have installed owfs correctly, but then you're trying to use owdir before starting owserver.

You're then starting owfs, and trying to use owdir again.

See my post above which (hopefully) explains the difference between owfs and owserver. If you start owserver instead of owfs then owdir should show the correct data. I can only assume that owdir is using the fake details due to not being able to find a running owserver process to talk to.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

AndyNC
Posts: 42
Joined: Thu Aug 30, 2012 7:04 am

Re: 1-wire and/or i2c - beginner help...

Thu Dec 06, 2012 1:19 pm

Many thanks for your responses.
Let me tell you where I'm coming from and where I want to go so you help me a little more.

I had for many years a pic webserver running with various sensors and a DS2482-100 running. I used the dallas c code and mangaged to get it to work reliably. The c-code was low level including register manipulations.

I want to replicate this on the Raspberry Pi.

I have purchased and buld the RPI2 from Sheepwalk and now need to interface to it.
I have tried C code but I get poor results and want to prove that the hardware works by using a 3rd party software such as owfs but as you can read, without much success.
Have read you comments, Paul, I found that the standard Raspbian apt-get owfs installs and starts owserver, owhttpd and owftpd.

For my application I want to have my own code running collecting and logging data. I would prefer to write the I2C part in C but I'm having problems with the C interface which could my understanding, my code or the hardware.
Having said that a good first step is to prove the system using owfs.

So my question is there a way, without compiling the packages, get one of the owfs systems running ie owserver or owfs.

Many thanks

Andy

p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Re: 1-wire and/or i2c - beginner help...

Thu Dec 06, 2012 1:44 pm

I think the compiles version which comes with the package is compiled with /etc/owfs.conf as a source of configuration and I had problems with overriding it.


However I think that compiling your own owfs is fairly easy it takes maybe 30 minutes. You just need
install libfuse-dev
But first run apt-get autoremove owfs

Owfs is fairly stable. I've run it on a router for years. However with DS2480B.

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Thu Dec 06, 2012 10:50 pm

AndyNC wrote:So my question is there a way, without compiling the packages, get one of the owfs systems running ie owserver or owfs.
I've not installed it from the packages so I can't help there.

I installed mine from source, which once the source was unpacked, was as easy as:

./configure
make
make install
/opt/owfs/bin/owserver --i2c=/dev/i2c-0:ALL
/opt/owfs/bin/owdir

(all as root, obviously)

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

AndyNC
Posts: 42
Joined: Thu Aug 30, 2012 7:04 am

Re: 1-wire and/or i2c - beginner help...

Fri Dec 07, 2012 12:40 pm

Hi Paul and Patrick,

I've installed from the compiled version and it did not work first time.

I re-compiled and installed and it works. The first failure may have been finger trouble or brain fade.
Many thanks for you help.


Now the next part is to access using C. I'm going to open another thread for this.
Cheers
Andy

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: 1-wire and/or i2c - beginner help...

Sat Dec 08, 2012 9:50 am

AndyNC wrote:I re-compiled and installed and it works. The first failure may have been finger trouble or brain fade.
Many thanks for you help.
You're welcome. I'm glad you have got it to work as I don't like it when people who buy my products can't get them working...

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

Ronsraspberries
Posts: 3
Joined: Mon Aug 07, 2017 12:20 pm

Re: 1-wire and/or i2c - beginner help...

Sun Aug 13, 2017 1:44 pm

Tech has progress some in the last 5 years but the question remains about the best 1-wire products for a < 3m length sensors for humidity and temp in a high humidity environment. I have some programming experience and will work with python but the USB was easy to use but is no longer made what master / slave sensors should I get for a personal project. I want to run an exhaust fan and humidifier in a root cellar based on temp and RH in the root cellar. I will be getting a RPI 3 B+.

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 6 guests