kelly / node-i2c

Node.js native bindings for i2c-dev. Plays well with Raspberry Pi and Beaglebone.
Other
216 stars 91 forks source link

Problem connecting DS1672 (RTC) #15

Closed omkarkhair closed 10 years ago

omkarkhair commented 10 years ago

I'm new to I2C on Node.js and I'm not sure about the address to use, while connecting the RTC with my BeagleBone Black.

I want to periodically read data from the RTC. Here's my code.

var i2c = require('i2c');
var address = 0xD1;
var wire = new i2c(address, {device: '/dev/i2c-1', debug: false});

function read(){
        wire.readBytes(0x00,10,function(err,byte){
                console.log(byte);
        });
}

setInterval(read, 2000);

I am using 0xD1 as the address as per the datasheet, but this gives me a 'Failed to set address' error.

sequoiar commented 10 years ago

try sudo ...

omkarkhair commented 10 years ago

I'm as root on a beaglebone black. Can't sudo.

Also, The address is supposed to be the device address right? The datasheet says the device is at 0xD1 while i2cdetect shows it at 0x68.

Which one should it be?

sequoiar commented 10 years ago

try 0x68

omkarkhair commented 10 years ago

0x68 works. I couldn't just go ahead without an explanation. This might have been obvious, but took me a while when I gave it look again this weekend.

The datasheet uses a 7-bit address which translates to 0xD0, the library adds a 0 prefix to make it 0x68