rwaldron / io-plugins

Documentation and discussion point for IO Plugins
117 stars 21 forks source link

Docs on i2cConfig do not match johnny-five.io docs #11

Open ugate opened 8 years ago

ugate commented 8 years ago

johnny-five.io docs show i2cConfig([milliseconds]) whereas the io-plugins wiki README.md show the correct signature of i2cConfig(options)

aabm00 commented 7 years ago

Hi.

I have tried to use:

var five = require("johnny-five");
var board = new five.Board({ port: "/dev/ttyATH0"});

board.on("ready", function() {

  var i = 0;

  options = {
    'address' : 8,
    'delay' : 2000
  };

  this.i2cConfig(options); // --> THE DELAY DOESN'T WORK
  this.i2cRead(8, 27, function(bytes) {
    console.log(i++);
    console.log("Bytes read: ", bytes);
  });
});

An the delay doesn't work !!!

fivdi commented 7 years ago

@aabm00 from the post above and https://github.com/rwaldron/johnny-five/issues/1287 it looks the goal is to read 27 bytes from the device at address 8 every 2 seconds. Maybe something like this would work:

var five = require("johnny-five");
var board = new five.Board({ port: "/dev/ttyATH0"});

board.on("ready", function() {
  var i = 0;

  setInterval(function () {
    this.i2cReadOnce(8, 27, function(bytes) {
      console.log(i++);
      console.log("Bytes read: ", bytes);
    });
  }, 2000)
});

Note that i2cReadOnce rather than i2cRead is being called here.

soundanalogous commented 7 years ago

@aabm00 What are you trying to do with the delay? The delay value actually passes a delay value to the firmware running on the Arduino and is applied just after the end of a write to request values from a register. Here is where it happens in the firmware: https://github.com/firmata/arduino/blob/master/examples/StandardFirmata/StandardFirmata.ino#L196.

aabm00 commented 7 years ago

Hi

Thanks @fivdi it works fine. Just what i wanted

@soundanalogous What I want to do is control the frequency I am receiving data in the master from the slave, just as @fivdi solution. I thought that 'delay' parameter in the options object applied to the this.i2cConfig (options) was just for that, controlling the frequency the master is receiving data from the slave, but it has not any effect, probably I missunderstood the real function of the delay parameter in i2cConfig

Thanks you both

aabm00 commented 7 years ago

Hi

I found another way to set the interval

var five = require("johnny-five");
var board = new five.Board({ port: "/dev/ttyATH0"});

board.on("ready", function() {
  var i = 0;
  var self = this;

  this.io.setSamplingInterval(2000);
  this.i2cConfig();

  this.i2cRead(8, 27, function(bytes) {
    console.log(i++);
    console.log("Bytes read: ", bytes);
  });
});
fivdi commented 7 years ago

Yeah, that'll also do it. It is however a global setting for all devices. Not all IO plugins implement setSamplingInterval.

fivdi commented 7 years ago

@aabm00 Can this issue be closed? If so, please hit the Close issue button at the bottom of the page :).

aabm00 commented 7 years ago

It wasn't open by me. i think I can't close it.

fivdi commented 7 years ago

@aabm00 Yes, you're right. Sorry about the confusion. This issue is related to documentation. Although the documentation has changed since @ugate reported this issue, it's still confusing.

ugate commented 7 years ago

@fivdi It looks like the docs have changed since the issue was opened. It's better than it was, but one shows i2cConfig([milliseconds] | options) while the other shows i2cConfig(options)