0

I need help with Meteor 1.5, johnny-five, serialport.

I'm on MacOS. I'm following this guide https://github.com/studiorabota/meteor-johnny-five-tutorial

I made a few changes to the code due to new Meteor version and support NPM.

My NodeJs version v4.6.2

The problem is Meteor connect to the wrong serial port. The following is the error message when I run "meteor":

Available /dev/cu.usbmodem1,/dev/cu.usbserial-A5029U59

Connected /dev/cu.usbmodem1

I need to know how to make Meteor to select the correct port. Please help, thanks in advance.

My Meteor package.json

{
  "name": "j5",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "babel-runtime": "^6.20.0",
    "johnny-five": "^0.11.1",
    "meteor-node-stubs": "~0.2.4",
    "serialport": "^4.0.7"
  }
}

My server/blink.js

// import johnny-five from 'johnny-five';

var JohnnyFive = require("johnny-five");

Meteor.startup(function(){
    board = new JohnnyFive.Board();

    board.on('error', function (error) {
        console.error('Johnny Five Error', error);
    });

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

        var led = new JohnnyFive.Led(13);

        led.blink(500);

    }, "ready"));
});
MarkZ
  • 280
  • 3
  • 14

1 Answers1

2

You can tell johnny-five which serial port to use:

board = new JohnnyFive.Board({ port : '/dev/cu.usbserial-A5029U59' })

More info here: http://johnny-five.io/api/board/#component-initialization

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Thanks. I just tried that and get new error. I20170603-19:58:24.811(8)? 1496491104660 Connected cu.usbserial-A5029U59 I20170603-19:58:24.894(8)? 1496491104678 Error Error: No such file or directory, cannot open cu.usbserial-A5029U59 – MarkZ Jun 03 '17 at 12:01
  • My Arduino IDE is connected to "cu.usbserial-A5029U59" and able to upload firmata firmware without error. – MarkZ Jun 03 '17 at 12:03
  • Is your Arduino IDE active? You probably only want to have one process running that accesses the serial port. Also, I assume that the USB cable to the Arduino (?) is properly plugged in? – robertklep Jun 03 '17 at 12:06
  • I restart my mac, run meteor, got the same error as my first comment on your post. USD is fine. Any idea? Please advice. – MarkZ Jun 03 '17 at 15:28
  • I don't understand why `johnny-five` would log that that device is available, yet when you try to use it, it doesn't exist. Does it still log that serial device name when you don't pass `port`? – robertklep Jun 03 '17 at 15:30
  • 1
    I'll try and check in a bit what happens on my Mac and will let you know. – robertklep Jun 03 '17 at 15:37
  • @MarkZ tried to reproduce but I can't, I tried various combinations of Arduino's and other USB-to-TTL devices. I do get the _"Available"_ list, but when I explicitly pick the second one (because by default it picks the first), it works just fine. What does `ls -al /dev/cu*` return? – robertklep Jun 03 '17 at 15:48
  • @MarkZ hmm now that I look at it more closely, are you sure that you're the full path to the device in the `port` argument? The error message you posted suggests that you're using this: `{ port : 'cu.usbserial-A5029U59' }` (without the `/dev/` prefix) – robertklep Jun 03 '17 at 17:31
  • I'll recheck and try again with the port setting. Will update here. – MarkZ Jun 03 '17 at 19:26
  • Thanks for pointing out the error. Now it works! So, is there any way to get the correct board without specify the port setting? Thanks... – MarkZ Jun 03 '17 at 19:34
  • One more quick question, in order for Meteor to control the board, the control script must be in "server"? Is it possible the board to be on client side and browser action from client to make changes to the board at the client side? – MarkZ Jun 03 '17 at 19:38
  • 1
    Regarding picking the correct board: the problem is that the name of the serial port is not related to the type of device that is connected, so I don't think there's an automatic way to pick "the correct board". About running parts in the client: I'm not very familiar with Meteor, but I'm going to guess that you can't run this code client-side. You'll have to run it server-side and somehow pass messages from client to server to board. – robertklep Jun 03 '17 at 19:41