These are chat archives for nebrius/raspi-io

29th
Apr 2015
ajfisher
@ajfisher
Apr 29 2015 02:37
@mihirkk an obvious question but you've got firmata loaded onto the Mega yes? Can you connect over serial (from the RPi), reset the mega and see the firmware version message?
mihirkk
@mihirkk
Apr 29 2015 13:24
i am creating separate board instances,
i also tried new five.Boards([A,B])
eventually will tie them through mqtt
mihirkk
@mihirkk
Apr 29 2015 13:29
--havnt tried the following option
but we could use mqtt-serial for the arduinos
can this be a power shortage issue
bcoz currently RPi is connected to my laptop USB port
mihirkk
@mihirkk
Apr 29 2015 13:41
This message was deleted
Laptop
|
USB
|
RPi
|--------------|---------------------|
USB1 -- USB2 -- USB3
Wifi -- ArduinoMega - ArduinoUno+GRBL
mihirkk
@mihirkk
Apr 29 2015 13:58
also in the setup i have connected a 16channel servo controller via i2c ports to the RPi,
the servos are on the PCA9685 and powered with external power supply
mihirkk
@mihirkk
Apr 29 2015 14:36

@ajfisher : yes i have StdFirmata on the Mega
also
if i only use the mega via j5, the blink eg works
if i only use the RPi using j5+raspi-io, it works
if i only use gbl/serialPort, it works

i am not being able to use them together / simultaneously

@Mega firmware version: will update in a while

Luis Montes
@monteslu
Apr 29 2015 15:01
@mihirkk are you trying to use 2 J5 instances in the same node process?
mihirkk
@mihirkk
Apr 29 2015 16:30
i am requiring (johnny-five) in three files
and creating new five.board in three diff files
Luis Montes
@monteslu
Apr 29 2015 16:31
right, but launching each separately?
mihirkk
@mihirkk
Apr 29 2015 16:31
sry did not follow
one sec
this is my main file
and these are the diff board files
Luis Montes
@monteslu
Apr 29 2015 16:34
That may be the problem, I think you'll want to pass a id into the board opts for each
that way you can address them with the components to get the right board
mihirkk
@mihirkk
Apr 29 2015 16:36
i did try that
using new five.boards[{id:'A',port:'/ttyACM0'},{id:"B",port:'/ttyUSB0'}];
but the arduino_mega connect j5 board timesout
before the ready event
Luis Montes
@monteslu
Apr 29 2015 16:38
maybe the baud rate? You have 115200 specified, but i think the default in standardfirmata is 57600
mihirkk
@mihirkk
Apr 29 2015 16:38
sry will just try it
it did cross my mind
brb
mihirkk
@mihirkk
Apr 29 2015 18:05
the following is working
mainly using a single j5 instance via 'new five.Boards[{id:"A"},{id:"B"}] to initialize both the RPi and Mega
remote.js
var five = require('johnny-five');
var raspio = require('raspi-io');
var Q = require('q');
var sp = require("serialport");
var grbl = require('grbl');

module.exports = function(){
    var rpi,mega,unoGrbl;

    var d = Q.defer();

    var j5b = new five.Boards([
        {
            id:"RPi",
            io:new raspio,
            repl:false
        },
        {
            id:"Mega",
            port:"/dev/ttyUSB0",
            repl:false
        }
    ]);

    setTimeout(function(){
        var m = grbl({
            p:'/dev/ttyACM0'
        },function(machine){
            unoGrbl = machine;
            machine.on('data', function (data){
                console.log("machine: " + data);
            });
            machine.write("?"+'\n');

        });
    },3000);

    var cnt =0;
    j5b.on('ready',function(){
        this.each(function(b){
            cnt++;
            if(b.port == '/dev/ttyUSB0'){
                mega=b;
            }else{
                rpi = b;
            }
            if(cnt==2){
                setTimeout(function(){
                    d.resolve({
                        "r":rpi,
                        "m":mega,
                        "g":unoGrbl
                    })
                },3000);
            }
        })

    });
    return d.promise;
};
index.js
var r = require('./remote');
var five = require('johnny-five');

var remote;

r().then(function(all){
    all.g.write("$$"+'\n');
    var l = getLed(all.m,13);
    l.strobe(100);
});

var getServo = function(board,ch){
    var s = new five.Servo.Continuous({
        board:board,
        controller: "PCA9685",
        address: 0x40,
        pin:ch
    });
    s.center();
    return s;
};
var getLed = function(board,ch){
    var l = new five.Led({
        board:board,
        pin:ch
    });
    return l;
};
mihirkk
@mihirkk
Apr 29 2015 18:11
thanks a ton guys :smile:
Bryan Hughes
@nebrius
Apr 29 2015 18:14
glad you got it working!