Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INPUT_PULLUP on digital input pin #1831

Open
dsanso opened this issue Sep 21, 2023 · 12 comments
Open

INPUT_PULLUP on digital input pin #1831

dsanso opened this issue Sep 21, 2023 · 12 comments

Comments

@dsanso
Copy link

dsanso commented Sep 21, 2023

Hello,

I see all over the place to use pinMode(pinNumber, INPUT_PULLUP);

How do I activate INPUT_PULLUP with johnny-five?

I have an digital input that requires a resistor and arduinos usually contain built-in pull-up resistors.

Thank you.

@dtex
Copy link
Collaborator

dtex commented Sep 22, 2023

Setting pin mode is something you would handle with the IO, so it's not a Johnny-Five thing really, but you can access the IO through the Johnny-Five Board instance:

import { board } from "johnny-five";

const board = new five.Board();

board.on("ready", function() {
  board.io.pinmode(3, board.io.MODES.PULLUP);
});

You say that you see that example all over the place. Can you point me to that? I've seen a few people ask questions like this, and I'm curious where it's all coming from.

@dsanso
Copy link
Author

dsanso commented Sep 22, 2023

I tried your code, it does not seem to work.

I believe a lot of programmers use INPUT_PULLUP instead of regular INPUT mode, as to avoid the noise in having something similar to a floating pin.

Some examples:

@dsanso
Copy link
Author

dsanso commented Sep 22, 2023

To clarify, I am not using it for a button. I am using it and almost all other digital pins to read from an external source.

@dtex
Copy link
Collaborator

dtex commented Sep 22, 2023

Can you share your code?

@dsanso
Copy link
Author

dsanso commented Sep 22, 2023

Can you share your code?

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

const board = new five.Board();

board.on("ready", function () {
  board.io.pinMode(31, board.io.MODES.PULLUP);

  const sensor = new five.Sensor.Digital({
    pin: 31,
  });

  sensor.on("change", function () {
    console.log("Pin value", this.value);
  });
});

The thing is the wire connecting to that pin will sometimes have to be "loose" making it a floating pin. And I need the resistor to "filter out" all the noise.

@dtex
Copy link
Collaborator

dtex commented Sep 22, 2023

I can't test (I'm at work), but I suspect initializing a sensor on that pin will reset it to a normal input. Have you tried setting the pin mode after instantiating the sensor?

@dsanso
Copy link
Author

dsanso commented Sep 22, 2023

It doesn't seem to work even with just using pinInput.read()

@ScreamZ
Copy link

ScreamZ commented Oct 23, 2023

In my experience, I've been able to proceed using the Button library https://github.com/rwaldron/johnny-five/blob/main/docs/button-pullup.md

isPullup: true This has been working for some time on my codebase. I've been able to test it 2 days ago and it was working but when i switched back to the code related to this part, it now glitch

 button.on("up", function() {
    led.off();
  });

triggers constantly, so this is not fixed. The doc seems to write that yes, but when you read at the code, all it it doing is sending a write command to LOW on that pin…

@tbaltrushaitis
Copy link

I should mention that I had some problems that looks like similar to this one in the topic.
But finally we're figured out that root cause of the problem was in failed arduino pin.
I've rechecked this a couple of times and problem with pin is now confirmed

@tbaltrushaitis
Copy link

I suggest in case of any troubles to check all of the modes of a button: isPullup, isPulldown and invert and play with every of those modes to be sure.

@ScreamZ
Copy link

ScreamZ commented Oct 25, 2023

I should mention that I had some problems that looks like similar to this one in the topic. But finally we're figured out that root cause of the problem was in failed arduino pin. I've rechecked this a couple of times and problem with pin is now confirmed
U mean your arduino is damaged ?

I suggest in case of any troubles to check all of the modes of a button: isPullup, isPulldown and invert and play with every of those modes to be sure.

What is is supposed to change ? Its only server code and if its related to the pin physically I'm not sure things will

@tbaltrushaitis
Copy link

tbaltrushaitis commented Nov 6, 2023

U mean your arduino is damaged ?

Yes

What is is supposed to change ? Its only server code and if its related to the pin physically I'm not sure things will

What you mean in "server code"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants