The Great Bottle Opener Giveaway

Home Brew Forums > Home Brewing Beer > DIY Projects > Monitoring/controlling with Linux on the cheap

Reply
 
LinkBack Thread Tools
Old 04-20-2011, 04:15 PM   #1
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default Monitoring/controlling with Linux on the cheap

There are numerous controller solutions on the market. Some of them are really, really nice, but, they aren't cheap either. With this economy and a kid in college, it has to be cheap (or free) before I will consider it. While I don't have a pile of cash sitting around (thanks to UF), I do have a few old POS laptops that have nothing to do but reminisce of days gone by. Rather than collect dust, I'm putting one (or more) of them to work.

This article requires the following:

  • A working install of Linux.

  • A working knowledge of Linux. You don't need to be an expert, but you do need to understand mounting file systems and what not. This is not a tutorial on how to use Linux.

  • A 1-wire adapter. I'm using the serial port version (DS9097U-XXX), but there are USB versions that work with this also. I recommend buying at least two (to have one for "play").

  • 1-wire temperature sensors and switches. I'm using DS18S20 for temperature sensors, and DS2406 for switching. You can buy them most anywhere (Jameco, Digi-Key, etc). Make sure you order the TO-92 packaging unless you have ninja soldering skills. If you don't want to make your own sensors/switches, you can order them pre-assembled from numerous sources (here, here, here). That (assembled) 8 relay board from Hobby Boards for ~$70 is one heck of a deal.

  • You can get a few free ones from Maxim: here. Enter the part number (DS18S20), click GO, then select the "Sample Now" button on the items you're interested in. Do the same for the DS2406 and any other 1-wire device you want a free sample of. Not all items are available for sample so poke around. Don't be greedy - accept the default quantity of 2 and be happy.


I did this on a fresh install of Fedora 14. However, these procedures should work on most any distribution. Before you install anything though, check to make sure it's not already installed by your distribution (no need to have it twice).

All source that was downloaded was extracted into /usr/src as typical.

Download and install FUSE: http://fuse.sourceforge.net/
Follow the directions in the INSTALL file. From the command line:

Code:
    # ./configure
    # make
    # make install
Download and install owfs: http://sourceforge.net/projects/owfs/files/owfs/2.8p8/
Follow the directions in the INSTALL file. From the command line:

Code:
    # ./configure --prefix=/opt/owfs
    # make install
You can run owfs in a number of different ways (google it), but I choose to run the client/server model. Since I want all this mess started and mounted on startup, I edit my /etc/rc.local file to achieve that as such:
Code:
    #
    # fire up the 1-wire stuff
    #
    /opt/owfs/bin/owserver -d /dev/ttyS0 -F -p 1961
    /opt/owfs/bin/owfs -s localhost:1961 -m /mnt/1wire -F --allow_other
Adjust the /dev/ttyS0 term to match the serial port your 1-wire adapter is plugged into (/dev/ttyS0 is serial port #1, etc). You can use any port you want - I chose 1961 because that's my birthyear.

Now you are ready to attach some 1-wire devices. As mentioned above, you can buy them, or, you can make them yourself. I can't say how "hard" it is - only you can decide that. I'd say it's about "medium" on the hard scale. I'm not that good with a soldering iron - I can manage, but I don't do a pretty job of it. It works, but it ain't pretty.

Use these schematics for making your own:click

The DS18S20 temperature sensors are very easy to hook up and use. Two pins to ground, the other to the 1-wire bus line. The DS2406 is a bit more involved, but doable. I used this schematic for my DS2406 switches as I already had those parts laying around here. Aside from the DS2406, these parts are CHEAP. Once you have that circuit working, attach the +/- 5 volts output to a SSR rated to handle your intended load.

Once you have the 1-wire devices connected, cd to the mount point of your 1-wire. For me it's /mnt/1wire:

Code:
[root@x24 1wire]# cd /mnt/1wire/
Get a directory listing:
Code:
    [root@x24 1wire]# ls -l
    total 0
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 10.26CC4F000800
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 10.E1B64F000800
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 12.50547D000000
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 12.6A497D000000
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 alarm
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 bus.0
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 settings
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 simultaneous
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 statistics
    drwxr-xr-x. 1 root root 30 Apr 20 00:59 structure
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 system
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 uncached
    [root@x24 1wire]#
The entries that begin with "10" and "12" are four 1 wire devices that I have hooked up at the time of this writing. Devices that begin with "10" are DS18S20 and those that begin with "12" are DS2406. Those are the "family" id values (the rest of that number is it's address).

The directory structure of a DS18S20:
Code:
    [root@x24 1wire]# cd 10.26CC4F000800/
    [root@x24 10.26CC4F000800]# ls -l
    total 0
    -r--r--r--. 1 root root  16 Apr 20 00:59 address
    -r--r--r--. 1 root root 256 Apr 20 00:59 alias
    -r--r--r--. 1 root root   2 Apr 20 00:59 crc8
    drwxrwxrwx. 1 root root   8 Apr 20 11:42 errata
    -r--r--r--. 1 root root   2 Apr 20 00:59 family
    -r--r--r--. 1 root root  12 Apr 20 00:59 id
    -r--r--r--. 1 root root  16 Apr 20 00:59 locator
    -r--r--r--. 1 root root   1 Apr 20 11:42 power
    -r--r--r--. 1 root root  16 Apr 20 00:59 r_address
    -r--r--r--. 1 root root  12 Apr 20 00:59 r_id
    -r--r--r--. 1 root root  16 Apr 20 00:59 r_locator
    -r--r--r--. 1 root root  12 Apr 20 00:59 temperature
    -rw-rw-rw-. 1 root root  12 Apr 20 11:42 temphigh
    -rw-rw-rw-. 1 root root  12 Apr 20 11:42 templow
    -r--r--r--. 1 root root  32 Apr 20 00:59 type
    [root@x24 10.26CC4F000800]#
To read the temperature, "cat temperature":
Code:
    [root@x24 10.26CC4F000800]# cat temperature
         66.9875
    [root@x24 10.26CC4F000800]#
In the above example, the temperature is 66.9875 degrees (in my fermentation fridge). Here's how you get to that value in a bash script:
Code:
     #
     # the device name of the DS18S20 temperature sensor
     #
     fermilabDev="/mnt/fermiTemp/temperature"

     #
     # read (and log) the temperature of the fridge
     #
     fermilabTemp=$(cat $fermilabDev | tr -d ' ')
     logger -t fermilab "$fermilabTemp degrees"
The DS2406 shows up a bit differently in the file system:
Code:
    [root@x24 1wire]# cd 12.6A497D000000/
    [root@x24 12.6A497D000000]# ls -l
    total 0
    -r--r--r--. 1 root root  16 Apr 20 00:59 address
    -r--r--r--. 1 root root 256 Apr 20 00:59 alias
    -r--r--r--. 1 root root  12 Apr 20 11:48 channels
    -r--r--r--. 1 root root   2 Apr 20 00:59 crc8
    -r--r--r--. 1 root root   2 Apr 20 00:59 family
    -r--r--r--. 1 root root   1 Apr 20 11:48 flipflop.A
    -r--r--r--. 1 root root   3 Apr 20 11:48 flipflop.ALL
    -r--r--r--. 1 root root   1 Apr 20 11:48 flipflop.B
    -r--r--r--. 1 root root  12 Apr 20 11:48 flipflop.BYTE
    -r--r--r--. 1 root root  12 Apr 20 00:59 id
    -rw-rw-rw-. 1 root root   1 Apr 20 11:48 latch.A
    -rw-rw-rw-. 1 root root   3 Apr 20 11:48 latch.ALL
    -rw-rw-rw-. 1 root root   1 Apr 20 11:48 latch.B
    -rw-rw-rw-. 1 root root  12 Apr 20 11:48 latch.BYTE
    -r--r--r--. 1 root root  16 Apr 20 00:59 locator
    -rw-rw-rw-. 1 root root 128 Apr 20 00:59 memory
    drwxrwxrwx. 1 root root   8 Apr 20 11:48 pages
    -rw-rw-rw-. 1 root root   1 Apr 20 11:48 PIO.A
    -rw-rw-rw-. 1 root root   3 Apr 20 11:48 PIO.ALL
    -rw-rw-rw-. 1 root root   1 Apr 20 11:48 PIO.B
    -rw-rw-rw-. 1 root root  12 Apr 20 11:48 PIO.BYTE
    -r--r--r--. 1 root root   1 Apr 20 11:48 power
    -r--r--r--. 1 root root  16 Apr 20 00:59 r_address
    -r--r--r--. 1 root root  12 Apr 20 00:59 r_id
    -r--r--r--. 1 root root  16 Apr 20 00:59 r_locator
    -r--r--r--. 1 root root   1 Apr 20 00:59 sensed.A
    -r--r--r--. 1 root root   3 Apr 20 00:59 sensed.ALL
    -r--r--r--. 1 root root   1 Apr 20 00:59 sensed.B
    -r--r--r--. 1 root root  12 Apr 20 00:59 sensed.BYTE
    -rw-rw-rw-. 1 root root  12 Apr 20 11:48 set_alarm
    drwxrwxrwx. 1 root root   8 Apr 20 11:48 T8A
    drwxrwxrwx. 1 root root   8 Apr 20 11:48 TAI8570
    -r--r--r--. 1 root root  32 Apr 20 00:59 type
    [root@x24 12.6A497D000000]#
To turn the DS2406 switch "on", you do this:
Code:
    [root@x24 12.6A497D000000]# echo "1">PIO.A
and to turn it off:
Code:
    [root@x24 12.6A497D000000]# echo "0">PIO.A
The TO-92 package of the DS2406 has only one switch line, so PIO.B is not usable on this device.
GatorDad is offline
2
People Like This 
Reply With Quote Quick reply to this message
Old 04-20-2011, 04:16 PM   #2
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

To make your life easier, you may want to create sym links to the 1-wire devices. Repeating the above directory structure:

Code:
    [root@x24 1wire]# ls -l
    total 0
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 10.26CC4F000800
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 10.E1B64F000800
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 12.50547D000000
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 12.6A497D000000
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 alarm
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 bus.0
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 settings
    drwxrwxrwx. 1 root root  8 Apr 20 11:39 simultaneous
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 statistics
    drwxr-xr-x. 1 root root 30 Apr 20 00:59 structure
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 system
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 uncached
    [root@x24 1wire]#
The sym links make it easier to refer to the 1-wire devices in your scripts/programs using a logical name, rather than some goofy alpha-numeric that means nothing us humans:

Code:
    [root@x24 mnt]# cd /mnt
    [root@x24 mnt]# ls -l
    total 0
    drwxr-xr-x. 1 root root  8 Apr 20 00:59 1wire
    lrwxrwxrwx. 1 root root 21 Apr 20 00:14 fermiOutsideTemp -> 1wire/10.E1B64F000800
    lrwxrwxrwx. 1 root root 21 Apr 20 00:10 fermiSwitch -> 1wire/12.6A497D000000
    lrwxrwxrwx. 1 root root 21 Apr 14 10:38 fermiTemp -> 1wire/10.26CC4F000800
    lrwxrwxrwx. 1 root root 21 Apr 20 01:05 switch1 -> 1wire/12.50547D000000
    [root@x24 mnt]#

Now, all you need to do is write some scripts (in whatever language you're comfortable with) that does something useful with the above.

Enjoy, and YMMV.
GatorDad is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 04:34 PM   #3
iandh
Feedback Score: 0 reviews
Recipes 
 
Join Date: Jul 2010
Location: San Francisco, CA
Posts: 62
Liked 2 Times on 2 Posts

Default

Nice write up!
I've been thinking of doing the same and using a ti launchpad instead of an adapter. Its $4.50 plus you get some additional IO.

__________________
iandh is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 05:43 PM   #4
Homercidal
Moderator
HBT_MODERATOR.png
Feedback Score: 0 reviews
 
Homercidal's Avatar
Recipes 
 
Join Date: Feb 2008
Location: Reed City, MI
Posts: 22,837
Liked 1900 Times on 1371 Posts
Likes Given: 1045

Default

Excellent! I have started using a 1-wire sensor system with windows and it would be nice to have a Linux option.

I applied for a "free" DS2406 recently and they wanted to charge me $75 for a kit?? Not sure I did it right, but will try again. I kind of made it look like I was interested for my wife's company, who does electronic R&D...

I may play with this info and see what I can do. Might be bugging you for some script help in the future!

__________________
Homercidal is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 05:54 PM   #5
Homercidal
Moderator
HBT_MODERATOR.png
Feedback Score: 0 reviews
 
Homercidal's Avatar
Recipes 
 
Join Date: Feb 2008
Location: Reed City, MI
Posts: 22,837
Liked 1900 Times on 1371 Posts
Likes Given: 1045

Default

Well, I must have done something wrong last time. I was easily able to order a sample for the switch this time. Sweet!

__________________
Homercidal is offline
GatorDad Likes This 
Reply With Quote Quick reply to this message
Old 04-20-2011, 06:40 PM   #6
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

Homercidal,

You did nothing wrong last time - they sell a developer kit too. The link above is to a different area (as you have already found out).

The nice thing about using owfs is that it exposes 1-wire devices as a file system, which, takes almost all the work out of playing with those devices - no bit twiddling. It's frightening simple once it's all setup. Last I checked, owfs wasn't quite ready for prime-time on Windows - it might be worth a checking into though.

Scripting... with owfs, anything that can interface with the file system, can do 1-wire. Bash, python, perl, php, etc. For example, my ferm fridge (Fermilab) is controlled by a simple bash script that gets fired up once every 2 mins by cron. I'm currently working on expanding this control mechanism to a HERMS system, but I'm not done with that yet...

GatorDad is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 06:59 PM   #7
Homercidal
Moderator
HBT_MODERATOR.png
Feedback Score: 0 reviews
 
Homercidal's Avatar
Recipes 
 
Join Date: Feb 2008
Location: Reed City, MI
Posts: 22,837
Liked 1900 Times on 1371 Posts
Likes Given: 1045

Default

I have done a bit of bash scripting in college. I don't think I still have the Unix reference book, but I'll check. LOTS of information on scripting online though.

After seeing how it's done a little bit, it's starting to make some sense and really does seem very simple. I'm mostly interested in using it for controlling, since my temp monitor is already basically set up and working well. What I can see happening is using this to not just control a ferm chamber, but maybe 2 or more AND sending the temps to a file for reference.

I should get all my friends to order samples for me...

__________________
Homercidal is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 07:21 PM   #8
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

Quote:
I should get all my friends to order samples for me...
the ole "you drink my beer, order me some free parts" routine, eh? Works for me.
__________________

cheers & beers,
Chris

Monitor/control with Linux
You know your IPA - do you know your PSA?

GatorDad is offline
 
Reply With Quote Quick reply to this message
Old 04-20-2011, 07:23 PM   #9
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

Quote:
Originally Posted by Homercidal View Post
What I can see happening is using this to not just control a ferm chamber, but maybe 2 or more AND sending the temps to a file for reference.
http://www.mrtg.org/rrdtool/
__________________

cheers & beers,
Chris

Monitor/control with Linux
You know your IPA - do you know your PSA?

GatorDad is offline
 
Reply With Quote Quick reply to this message
Old 04-21-2011, 12:40 AM   #10
GatorDad
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

Here is some PHP code that plays with the device names I used in the examples above. You can run it from the command line, or from a web server. If your language of choice can open, read, write and close a file, it can do 1-wire via owfs:

PHP Code:
<?php

    
// display the temperature
    
displayTemp();        
    
    
// toggle the switch
    
setSwitch("1");
    
sleep(1);
    
setSwitch("0");
    
    exit;
    
    

function 
displayTemp() {
    
//
    // the device name of the temp probe
    //
    
$devTemp "/mnt/fermiTemp/temperature";
    
    
//
    // open the temperature device
    //
    
$fp fopen($devTemp,"r");
    if (
$fp == null) {
        echo 
"error opening $devName\n";
        exit;
    }
    
    
//
    // read the temperature
    //
    
$temp trim(fread($fp,1024));
    
    
//
    // close the file handle
    //
    
fclose($fp);
    
    
//
    // display the temperature
    //
    
echo "The temp is: $temp\n";
}
    
    
function 
setSwitch($state) { 
    
//
    // the device name of the DS2406 switch
    //
    
$devSwitch "/mnt/fermiSwitch/PIO.A";
    
    
//
    // open the temperature device
    //
    
$fp fopen($devSwitch,"w");
    if (
$fp == null) {
        echo 
"error opening $devSwitch\n";
        exit;
    }
    
    
//
    // set the switch state
    //
    
if (fwrite($fp,$state) === FALSE) {
        echo 
"error writing to $devSwitch\n";
        exit;    
    }
    
    
//
    // close the file handle
    //
    
fclose($fp);
    
    
//
    // display the temperature
    //
    
echo "The switch is set to: $state\n";
}

?>
__________________

cheers & beers,
Chris

Monitor/control with Linux
You know your IPA - do you know your PSA?

GatorDad is offline
 
Reply With Quote Quick reply to this message
Reply


Quick Reply
Message:
Options
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Temperature Monitoring and Control with Arduino erock2112 DIY Projects 85 04-05-2011 07:46 PM
Controlling Wort Flow capnr0n DIY Projects 12 03-16-2010 04:00 AM
Temperature Controlled Brewcloset with remote monitoring Mista_Sparkle DIY Projects 1 11-26-2009 07:53 AM
Monitoring temp on the cheap... tireater DIY Projects 20 04-15-2009 07:06 PM
Basic ambient temperature monitoring jasper9 DIY Projects 8 12-31-2008 11:19 PM