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

v0.0.12 firmware - pin.on('change', function(pinVal){}) not always providing pinVal properly #164

Open
dudleyjosh opened this issue Apr 8, 2016 · 2 comments

Comments

@dudleyjosh
Copy link
Contributor

The simple, single pin example seems to work:

Using external pulldown resistor
img_4843

var tessel = require('tessel');
tessel.ports.A.pin[2].input();
tessel.ports.A.pin[2].on('change', function(pinVal) {
    console.log(pinVal);
});

Using internal pulldown resistor pin.pull('pulldown') mode
img_4841

var tessel = require('tessel');
tessel.ports.A.pin[2].pull('pulldown');
tessel.ports.A.pin[2].input();
tessel.ports.A.pin[2].on('change', function(pinVal) {
    console.log(pinVal);
});

However, if I try to setup multiple pins at once using an array.forEach loop and, in this case, only have pin 2 connected to the button... pinVal output never changes (always 0 when using pulldown, always 1 when using pullup):

[2, 5].forEach(function(pin) {
    tessel.ports.A.pin[pin].input();
    tessel.ports.A.pin[pin].on('change', function(pinVal) {
        console.log(pin, pinVal);
    });
});

See Related conversation on Slack

@dudleyjosh dudleyjosh changed the title pin.on('change', function(pinVal){}) not always providing pinVal properly v0.0.12 firmware - pin.on('change', function(pinVal){}) not always providing pinVal properly Apr 8, 2016
@rwaldron
Copy link
Contributor

rwaldron commented Apr 8, 2016

To clarify a bit about this: the issue doesn't appear until a user program tries to observe more than one interrupt pin (set to input). For example:

var tessel = require('tessel');
var pinMode = 'pulldown';

tessel.ports.A.pin[2].pull(pinMode);
tessel.ports.A.pin[2].on('change', function(pinVal) {
  console.log(pinVal);
});

Is fine:

$ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to bishop.
INFO Building project.
WARN The following items were found in your project directory, but not deployed.
INFO Writing project to RAM on bishop (3.072 kB)...
INFO Deployed.
INFO Running index.js...
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
...

And...

var tessel = require('tessel');
var pinMode = 'pulldown';

[2, 5].forEach(function(pin) {
  tessel.ports.A.pin[pin].pull(pinMode);
  tessel.ports.A.pin[pin].on('change', function(pinVal) {
      console.log(pin, pinVal);
  });
});

Is fine...

$ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to bishop.
INFO Building project.
INFO Writing project to RAM on bishop (3.072 kB)...
INFO Deployed.
INFO Running index.js...
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0

But, then...

var tessel = require('tessel');

[2, 5].forEach(function(pin) {
  tessel.ports.A.pin[pin].input();
  tessel.ports.A.pin[pin].on('change', function(pinVal) {
      console.log(pin, pinVal);
  });
});

Has the following result:

$ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to bishop.
INFO Building project.
INFO Writing project to RAM on bishop (3.072 kB)...
INFO Deployed.
INFO Running index.js...
2 0
5 0
2 0
5 0
2 1
5 1
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0

@dudleyjosh
Copy link
Contributor Author

Something else odd is going on here too? Running the following code:

[2, 5].forEach(function(pin) {
    tessel.ports.A.pin[pin].pull(pinMode);
    tessel.ports.A.pin[pin].on('change', function(pinVal) {
        console.log(pin, pinVal);
    });
});

Console with both pins 2 & 5 connected to the button:

$ t2 run pintest.js
INFO Looking for your Tessel...
INFO Connected to rde.
INFO Building project.
INFO Writing project to RAM on rde (5.12 kB)...
INFO Deployed.
INFO Running pintest.js...
2 1
2 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0
2 1
5 1
2 0
5 0

With pin 2 connected & pin 5 disconnected:

2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0

With pin 5 connected & pin 2 disconnected:

5 1
5 1
5 0
5 1
5 1
5 0
5 1
5 0
5 1
5 0

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

2 participants