I2C with AutobahnJS and crossbar on Arduino Yun

#1

Hi,

I’m currently trying to run some I2C sensors on my Arduino Yun with Autobahn|JS and crossbar.io. After some days of trying to make all the things run, I can finally read/write signals to the Arduino Pins. Unfortunetly I didn’t find any examples using I2C. I’m sure it should be possible, because the StandardFirmataYun sketch has some function including I2C. The Problem is that I don’t know how to use it. I tried many different things like:

var i2cread = function (args) {
var addr = 0x28;
arduino.pinMode(addr, firmata.I2C);
arduino.pinMode(addr, firmata.I2C_CONFIG);
arduino.pinMode(addr, firmata.I2C_REQUEST);
arduino.pinMode(addr, firmata.I2C_READ);
var xx;
try {
xx = arduino.digitalRead(0x28);
} catch (e) {
console.log(e);
throw e;
}
return xx;
//firmata.I2C_CONFIG();
/firmata.i2cWrite(0x28, 0x2D, 0);
firmata.i2cWrite(0x28, 0x2D, 8);
firmata.i2cWrite(0x28, 0x31, 8);
firmata.i2cRead(0x28, 0xB2, function(data) {
var x = data[1];
args[0] = x;
console.log(x);
});
/

        return args[0];
    }
    session.register("io.crossbar.examples.yun.i2cr", i2cread);

``

Thank you,
-Adrian

0 Likes

#2

I think that it should be someting with sysex:

arduino.sysex(‘I2C_REQUEST’, [0x58, ‘I2C_READ’, 1, 1, 1, 1]);
arduino.on(‘sysex’, function(e){
console.log("Data 2: ", e.command);
console.log("data : " + JSON.stringify(e.data));
});

``

it works for s simple led blink example, but unfortunetly not for I2C. With this code it just never enters the arduino.on sysex function
Maybe someone knows what I make wrong?

Thanks
-Adrian

0 Likes

#3

Sorry, I have no idea. Probably ask on Firmata related mailing lists?

···

Am Montag, 23. November 2015 11:19:28 UTC+1 schrieb adrian mainka:

I think that it should be someting with sysex:

arduino.sysex(‘I2C_REQUEST’, [0x58, ‘I2C_READ’, 1, 1, 1, 1]);
arduino.on(‘sysex’, function(e){
console.log("Data 2: ", e.command);
console.log("data : " + JSON.stringify(e.data));
});

``

it works for s simple led blink example, but unfortunetly not for I2C. With this code it just never enters the arduino.on sysex function
Maybe someone knows what I make wrong?

Thanks
-Adrian

0 Likes