Skip to content

Instantly share code, notes, and snippets.

@kmpm
Last active June 13, 2019 21:01
Show Gist options
  • Save kmpm/4445289 to your computer and use it in GitHub Desktop.
Save kmpm/4445289 to your computer and use it in GitHub Desktop.
OWFS on Raspberry Pi using i2c

OWFS on Raspberry PI using i2c

This is based on a default "wheezy" install.

Prepare

First, install all neccesary tools and some good to have ones. When this was written 2012-01-03 it wasn't neccesary to compile your own owfs. The one from the repositories work fine.

Install

#good to have debs
sudo apt-get install i2c-tools owfs ow-shell

Configure

     sudo nano /etc/modprobe.d/raspi-blacklist.conf

And make sure you comment out then line blacklist i2c-bcm2708 so that it looks like

#blacklist i2c-bcm2708

Add i2c-dev to the end of /etc/modules file if it's not already listed.

Load the modules manually instead of restarting.

sudo modprobe i2c-bcm2708
sudo modprobe i2c-dev

Edit /etc/owfs.conf and remove any othter server: FAKE... or whatever is default. Instead add a line with for i2c like below.

#server: FAKE = DS18S20,DS2405

server: i2c = ALL:ALL

Test

If everything is connected as it should a 18 should turn up when you run i2cdetect -y 0|1 where you use 0 for the first version of the Raspberry PI board and 1 for the second. This is because they have moved the GPIO pins from i2c port 0 to port 1 on the second generation of the boards

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     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: -- -- -- -- -- -- -- --

Restart the the owfs server service so it rereads the config.

sudo service owserver restart
[ ok ] Restarting 1-Wire TCP Server: owserver.

Try to do list what owfs found. Since I am using a DS2481-800 which has 8 different 1-wire busses it will list these if everything works. Note, this display does not show any devices.

pi@raspberrypi ~ $ owdir
/bus.9
/bus.7
/bus.6
/bus.5
/bus.4
/bus.3
/bus.2
/bus.1
/bus.0
/uncached
/settings
/system
/statistics
/structure

Node on the Pi

This is completely up to you but because I use node together with owfs I need this Install node from precompiled to save LOADS OF TIME

wget http://nodejs.org/dist/v0.10.20/node-v0.10.20-linux-arm-pi.tar.gz

cd /usr/local
sudo tar xzvf ~/node-v0.10.20-linux-arm-pi.tar.gz --strip=1
var OwfsClient = require('owfs').Client;
var owfs = new OwfsClient('127.0.0.1', 4304);
var cache = {};
var count=0;
var found=0;
var keylist="";
function refresh() {
console.log("cache", cache);
console.log(found);
console.log(keylist);
found=0;
keylist="";
try{
owfs.dir('/', function(directories){
directories.forEach(refreshDevice);
});
}
catch(err) {
console.log("owfs error", err);
}
}
function refreshDevice(path) {
owfs.read(path + "/temperature", function(result){
if(typeof(cache[path])==='undefined'){
cache[path]={};
}
cache[path].temperature=parseFloat(result);
cache[path].update = new Date();
// keylist += path + "=" + result + "\n ";
found++;
});
}
refresh();
setInterval(refresh, 15000);
var easyip = require('easyip');
var service = new easyip.Service();
function update_easyip(){
var key,i;
var sorted=[];
for(key in cache){
if(cache.hasOwnProperty(key)){
sorted[sorted.length]=key;
}
}
count = sorted.length;
service.storage.set(easyip.OPERANDS.FLAGWORD, 0, count);
console.log("count=", count);
sorted.sort();
var index=1;
for(i=0; i<sorted.length; i++){
var nod = cache[sorted[i]];
service.storage.set(easyip.OPERANDS.FLAGWORD, index, Math.round(nod.temperature * 100));
console.log(sorted[i], nod);
index++;
}
};
setInterval(update_easyip, 5000);
service.on('cacheening', function(address){
console.log("easy ip cacheening on", address);
});
service.bind();
@MYeager1967
Copy link

I can't get anything out of the OWFS OneWire setup. I see the board on the bus, and I've followed several tutorials to try to get it to work. With the default configuration, it all works. The moment I try to use the i2c board, I get an exception error (python) about no controller. I've tried:

server: i2c = /dev/i2c-1:0
server: device = /dev/i2c-1:0
server: i2c = ALL:ALL

None of this shit is working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment