by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Donovan Buck
@dtex
I've been able to animate more than one LED in the past. I need to play around and see what's... Oh wait, this code runs on the host computer. Can I ask what kind of computer you are using to run node and Johnny-Five?
Jean-Philippe Côté
@djipco
I'm using macOS Catalina and running the code inside NW.js. In order to do that, I'm using io-firmata:
const five = require("johnny-five");
const SerialPort = require("chrome-apps-serialport").SerialPort;
const Firmata = require("firmata-io")(SerialPort);

(...)

const board = new five.Board({
  io: new Firmata("/dev/cu.usbmodem3101")
});
Jean-Philippe Côté
@djipco
I tried your code and cannot seem to get it working. I always get the following error: TypeError: this.target[Animation.normalize] is not a function
Donovan Buck
@dtex
Whelp, that's a bug. Try this:
const { Animation, Board, Leds} = require("johnny-five");
const board = new Board();

board.on("ready", () => {
  const leds = new Leds([10, 11]);

  const animation = new Animation(leds);

  animation.enqueue({
    easing: "linear",
    duration: 500,
    cuePoints: [0, 1],
    keyFrames: [ [0, 255], [0, 255] ],
    metronomic: true,
    loop: true
  });

  board.wait(12000, () => {
    animation.stop();
  });
});
Donovan Buck
@dtex
It's interesting that you are using NW. I have no idea what kind of performance impact that might have. It is outside my experience.
Jean-Philippe Côté
@djipco
@dtex Thank you so much for your help on this. I tried your revised code and it gives me the exact same result as I had before. That is, one of the LEDs fades smoothly and the other one is erratic.
Seeing that, I tried to run your code directly from Node.js (without NW.js, io-firmata and chrome-apps-serialport) and... it works flawlessly!
Donovan Buck
@dtex
Whew, thanks for checking that out. I was about to build a circuit myself and test. One of these days I'm going to have to learn about NW.js so I can help there too. It seems like half the questions we get are from people using it.
Jean-Philippe Côté
@djipco
I have even more details...
When I run this code (which strips out NW.js and chrome-apps-serialport while keeping io-firmata), it also works flawlessly:
const { Animation, Board, Leds} = require("johnny-five");
const SerialPort = require("serialport");
const Firmata = require("firmata-io")(SerialPort);

const board = new Board({
  io: new Firmata("/dev/cu.usbmodem4101")
});


board.on("ready", () => {

  const leds = new Leds([5, 10]);
  const animation = new Animation(leds);

  animation.enqueue({
    easing: "linear",
    duration: 500,
    cuePoints: [0, 1],
    keyFrames: [ [0, 255], [0, 255] ],
    metronomic: true,
    loop: true
  });

});
So, obviously, something is happening at NW.js's level or with chrome-apps-serialport...
Jean-Philippe Côté
@djipco
chrome-apps-serialport is a package I created by simply updating browser-serialport to support the API changes in v8 of the serialport module. I guess I will have to delve into the code to understand what's going on.
Donovan Buck
@dtex
Thanks for your work on that. My understanding is it's a big improvement in the user experience for peeps on NW.
Jean-Philippe Côté
@djipco

My understanding is it's a big improvement in the user experience for peeps on NW.

Yes, I believe it is. At least, it seems to be for my students.

Jean-Philippe Côté
@djipco

After some digging, I finally found the problem. It seems that chrome.serial does not do any buffering of the data to send and is not happy when you try to send data while it is already sending (which firmata-io does all the time). Once I added buffering inside chrome-apps-serialport the problem went away!

So, with version 1.0.6 of chrome-apps-serialport my original code (using pulse()) now works and your suggested code (using new Animation()) also works. Yeah!

Thanks a lot for your insights @dtex.

Donovan Buck
@dtex
:thumbsup: Glad it's all working now. Still have that bug when passing an array as the target. I'll get that into J5 as an issue.
gianmassa
@gianmassa

Hello, I'm new to Arduino and I'm trying to use Johnny Five with HCSR04
It says I need to install PingFirmdata. I'm trying to follow the link: http://johnny-five.io/api/proximity/#pingfirmata

But when I run npm install nodebots-interchange I get an error:

PS C:\Users\gianm\documents\Arduino> npm install nodebots-interchange
npm ERR! code ENOGIT
npm ERR! Error while executing:
npm ERR! undefined ls-remote -h -t https://github.com/noopkat/browser-serialport.git
npm ERR!
npm ERR! undefined
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\gianm\AppData\Roaming\npm-cache_logs\2020-04-21T16_15_28_593Z-debug.log

Could somebody help me out?

Thanks!

gianmassa
@gianmassa

Ok, after installing git I was able to install nodebots-interchange, but I still can't use the command interchange.
When I try to run for example interchange --help, I get the following:

interchange : The term 'interchange' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • interchange --help
  • ~~~
    • CategoryInfo : ObjectNotFound: (interchange:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
Jean-Philippe Côté
@djipco

Hello guys!

I'm trying to use this RGB LED module in Johnny-Five and only get shades of red.

When I try this code in Arduino, the module works fine:

void loop() {

  analogWrite(9,  255);
  analogWrite(10, 0);
  analogWrite(11, 0);
  delay(500); 

  analogWrite(9,  0);
  analogWrite(10, 255);
  analogWrite(11, 0);
  delay(500); 

  analogWrite(9,  0);
  analogWrite(10, 0);
  analogWrite(11, 255);
  delay(500); 

}

The code above cycles between red, green and blue.

If I try this code in JavaScript, I only get red:

    let led = new five.Led.RGB({
      pins: [9, 10, 11]
    });

    led.color("#FFFFFF");

It's probably something stupid but I can't figure it out...

Donovan Buck
@dtex
Can we see all the code?
Jean-Philippe Côté
@djipco
Sure... hold on.
Jean-Philippe Côté
@djipco
Hmm... while I was trying to extract the relevant code to send it here, it started working. I'm not sure what I did. I'll do some more digging before sending anything.
Jean-Philippe Côté
@djipco
Once again, the problem was between the chair and the keyboard...
Jean-Philippe Côté
@djipco

Me again. I'm facing a new problem with the Servo object. I have some code (see full example below), that sweeps the servo for a few seconds and then sends it randomly to 0°, 90° or 180°. The code works perfectly fine... until I add a second parameter to the to() method. With this 2nd parameter present, once in a while, it will go to the wrong destination.

Here's the code, it's a bit long but it's a fully working example. You jsut have to hook up a servo on pin #10 (I have an SG-90 servo).

const five = require("johnny-five");
const SerialPort = require("serialport");

let servo;

getPort().then(init).then(start);

function getPort() {

  return SerialPort.list().then(ports => {
    const device = ports.find(port => {
      return port.manufacturer && port.manufacturer.startsWith("Arduino")
    });
    return device.path;
  });

}

function init(port) {
  return new Promise((resolve, reject) => {
    const board = new five.Board(port);
    board.on("ready", resolve);
    board.on("fail", reject);
  });
}

function start() {

  servo = new five.Servo({
    pin: 10,
    center: true
  });

  setInterval(go, 6000);

}

function go() {

  servo.sweep();

  setTimeout(() => {
    servo.stop();
    const target = Math.floor(Math.random() * 3) * 90;
    console.log(target);
    servo.to(target, 1000); // If I remove 2nd param, it works every time!
  }, 4000);

}

Ideas?

Donovan Buck
@dtex
Probably a race condition. Try wrapping servo.to in a process.nextTick
Sidenote, new five.Board(); does the same thing as getPort for you automatically. Is it not working for you?
Jean-Philippe Côté
@djipco
Unfortunately, process.nextTick() does not seem to be working either. 😕 It does the same thing as without it.
I'm using getPort() because I extracted the code from a project that uses a custom IO interface (chrome-apps-serialport). Thanks for the tip, though. 🙂
Donovan Buck
@dtex
I'll try and wire up a servo tonight after work and replicate.
Jean-Philippe Côté
@djipco
Thank you so much for your help on this. It does feel like there might be a bug in the lib. At first, I thought the problem might be with my cheap servo but since it behaves normally without the second param, I've ruled this out. If it does the same thing with yours, we'll have confirmation. Beware, that it happens maybe once every five attempts.
Donovan Buck
@dtex
Okay, I was able to replicate. Digging into it
Donovan Buck
@dtex
And I agree it's a bug
Donovan Buck
@dtex
I think it only happens when the servo is reversing in a sweep and the to value is 0 or 180, so every one out of 3 times it's wrong which is a big clue.
Donovan Buck
@dtex
Ya, servo holds onto its animation object between sweeps and reverse is a state of the animation object. Calling stop does not reset the state of reverse so the values passed to to() get inverted. Here's something to try: Navigate to you project folder/node_modules/johnny-five/lib/animation.js and around line 158 you'll find this.isRunning = false;. On the next line add this.reverse = false;. Does it work as expected now?
Jean-Philippe Côté
@djipco
Yes!! It works!!! 🤘🏻Thanks again for your help on this @dtex.
Can we get this fix into the next 1.x release? Should I submit a PR or will you take care of that?
Donovan Buck
@dtex
I'll submit a PR. I need to make sure there aren't other properties that need to be reset when the animation queue is flushed, and I should add some tests to catch this.
It's also possible that reverse should be a property of the segment instead of the animation, but I need to spend some time on that one.
Jean-Philippe Côté
@djipco
Okay, thank you. Let me know if I can be of any help. Cheers!
Mex Delgado
@rudemex
Hello, how are you? I have a 180 degree MG996R servo, but it turns 270 which is the maximum stop that turns from end to end, so I can control it because if I set [0.180] or [0.270] in the servo API, it only moves me a maximum of 45 degrees, I need to use the maximum degrees, or at least that is 180 degrees perfect.
Donovan Buck
@dtex

@rudemex You probably just need to set your PWM range.

new five.Servo({
  pin: 10,
  pwmRange: [580, 2450]
});

Finding your servos PWM range is a matter of trial and error. This tool might help. One thing worries me though. The J5 default is [600, 2400] which is very generous. I see that you are using a decimal instead of a comma in your array examples above. Is it like that in your code?

Mex Delgado
@rudemex
Hello @dtex, thank you very much for your answer, I will try what you tell me, no, clearly it was a typo hahaha, I understand that those parameters are arrays.
I'll try those values and tell you how it went. Thank you very much.
Donovan Buck
@dtex
Those values are a just an example. I don't really know what your values will be. Use the servo tuner tool to help figure that out.
Mex Delgado
@rudemex
@dtex ok, thanks!!!
Mex Delgado
@rudemex
Thanks @dtex, it worked perfectly.
I have a doubt, how can I make an animation with delay or pause and that the cue point times are different? I mean: from point 0 to 270 is 1500ms, have a pause of 500ms and the time to return from 270 to 0 is 1000ms.
Donovan Buck
@dtex
Well, you could use the Johnny-Five animation class. It was made with this use case in mind. http://johnny-five.io/api/animation/
Mex Delgado
@rudemex
Sure @dtex, I'm using that class, but I'm not finding a way to pass the time from one point to another. Maybe explaining a little bit the project I'm working on, you could help me in a better way to make it happen.
Given the global situation of public knowledge (COVID-19 pandemic), I'm developing a manual open-source ventilation automation, to do this, having so many technologies available, I prefer to use nodejs and the J5 library in order to make a robust and scalable development. Currently I have developed much of the project where I'm setting the breathing cycle times, which then translates into the movement of the motor to push a rocker to press the manual fan.
The problem I am having now is: the time that the servo arrives from 0 to 270, maximum point where it presses completely the bag of the ventilator, the pause that exists between the inspiration and expiration, and the time that the servo arrives from 270 to 0, which retracts the rocker so that the bag re-inflate and begin the cycle again. The idea that these times are variable is by the respiratory frequency that depends on the case of the patient.
Donovan Buck
@dtex
I think you are headed down the wrong path. Johnny-Five is fun, and easy to learn. It is a great tool for learning more about electronics and prototyping things. It is not a good platform for building medical devices.
Mex Delgado
@rudemex
@dtex of that I am sure, This prototype is not intended to replace an intensive care ventilator, but to be an assistant for the staff of critical areas in case they need to manually ventilate a patient for a limited period of time until the necessary ventilator is available, always with the supervision of a medical specialist.
Matt Cirillo
@misterzirillo

Hello Johnnies,

I'm curious if J5 supports any I2C multiplexers such as the TCA9548A. Looking through the docs it appears that it doesn't.