Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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.

Manish2208
@Manish2208
how to use multiple buttons to control multiple o/p using johnny -five?
Donovan Buck
@dtex
@misterzirillo It supports a few expanders, but not that particular one and no I2C multiplexers that I'm aware of. I think you're the first person to ask about it. There's a good infrastructure there to build upon, but it would require a champion to come in and write the code.
@Manish2208 What is "o/p"? Also, it is better to ask your questions on Github. Gitter doesn't see a lot of action and I will never respond to DM's for support.
Jake Harris
@jake-harris
Would anyone be interested in a quick tutoring session for hire? I'm able to make some servos sweep() but not step() or to(). Not quite sure what I'm doing wrong.
Donovan Buck
@dtex
I'm not available for hire, but I know the Servo class pretty well and can probably help. Can you a) Share your code and b) Describe what's happening?
Jake Harris
@jake-harris
Thanks so much for responding. I was just about to come here and post back: I was unable to step() without first setting the servo position (e.g. using the constructor props or center(), etc.)
Donovan Buck
@dtex
That makes sense. Standard servos don't provide feedback, so if you haven't set the position J5 can't know the position to step from. It's operating with NaN as the current position so I suspect it's just failing silently.
Danilo Gacevic
@danilogacevic
Hi. Is it possible to program controllino with J5 ? If anyone tried it..
Donovan Buck
@dtex
Not out of the box, but it isn't a Johnny-Five issue. Firmata would need to be modified to run on the Controllino. Totally doable I'm sure, but I don't really know how much work it would be.
Danilo Gacevic
@danilogacevic
Ok, thank you.
Donovan Buck
@dtex
@danilogacevic the repo you’ll want to open an issue on is firmata/arduino
Danilo Gacevic
@danilogacevic
@dtex But firmata/firmata.js is the repo that should be modified ?
mg-snake
@mg-snake
anyone know what I'm doing wrong with using interchange? i try running interchange install and it says interchange is not recognized
:(
trying to get a led strip working with johnny five
mg-snake
@mg-snake
i installed interchange globablly
so shouldnt it be here? C:\Program Files\nodejs\
this is in my PATH
Joshua Scott Oxner
@Bohemus307
Is there a way to access a ph sensor that is connected via usb to a rpi3 with Johnny-five?