node-rpio icon indicating copy to clipboard operation
node-rpio copied to clipboard

Polling does not work

Open Mrtenz opened this issue 7 years ago • 2 comments

I'm trying to use the poll function but it does not seem to work. Manually polling with setInterval does work.

Here is the code that's not working:

import { init, open, poll, INPUT, PULL_UP } from 'rpio';

// I have to use `gpiomem: false` because I'm using SPI functions
init({
  gpiomem: false,
  mapping: 'gpio'
});

open(21, INPUT, PULL_UP);
poll(21, () => {
  console.log('Foo'); // Never called
});

While using setInterval and read does work:

import { init, open, poll, read, INPUT, LOW, PULL_UP } from 'rpio';

// I have to use `gpiomem: false` because I'm using SPI functions
init({
  gpiomem: false,
  mapping: 'gpio'
});

open(21, INPUT, PULL_UP);
setInterval(() => {
  if (read(21) === LOW) {
    console.log('Foo'); // Called when button is pressed
  }
}, 10);

Am I missing something here or is this a bug in node-rpio?

Mrtenz avatar Oct 26 '18 19:10 Mrtenz

I wonder if it's just that polling isn't supported for SPI. Out of interest, to rule out any hardware or kernel issues, if you just use regular GPIO does it work?

If it's that SPI and polling are incompatible then I'm not sure there is a fix.

jperkin avatar Nov 29 '18 16:11 jperkin

As far as I can see, on SPI master cannot wait for a message to read from a slave (e.g. using poll/epoll/select). Because master hardware must select slave via PIN and then start clocking, after what slave will provide bits serially.

OTOH events can be seen by SPI slaves, when a message from master arrives.

I'm trying to use the poll

What SPI master/slave setup is there and who is reading?

olecom avatar Feb 12 '19 13:02 olecom