GithubHelp home page GithubHelp logo

Comments (12)

fivdi avatar fivdi commented on June 12, 2024

What type of system is the error occurring on? A Raspberry Pi 0, 1, 2, 3 or 4? A BeagleBone? Something else?

If a Raspberry Pi with a 40-pin GPIO header is being used please ensure that the SPI1 peripheral is not activated for usage as activating SPI1 will reserve GPIO20 for SPI thus making it unusable for other purposes.

Please post a complete (but short) program that can be run and used to reproduce the error rather than snippets of code.

Please post the content of /boot/config.txt

from onoff.

fivdi avatar fivdi commented on June 12, 2024

If GPIO20 is configured as an output and later configured as an input, calling writeSync for GPIO20 will result in an EPERM error. This is to be expected as it's not permitted to call writeSync for a GPIO configured as an input.

For example, running this program:

const Gpio = require('onoff').Gpio;

const relay2 = new Gpio(20, 'out');
const input = new Gpio(20, 'in');

function a() {
  relay2.writeSync(1);
}

a();

results in this EPERM error:

internal/fs/utils.js:259
    throw err;
    ^

Error: EPERM: operation not permitted, write
    at Object.writeSync (fs.js:694:3)
    at Gpio.writeSync (/home/pi/onoff/node_modules/onoff/onoff.js:243:8)
    at a (/home/pi/onoff/t.js:7:10)
    at Object.<anonymous> (/home/pi/onoff/t.js:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -1,
  syscall: 'write',
  code: 'EPERM'
}

Perhaps your program is configuring GPIO20 first as an output, then as an input and the calling writeSync

from onoff.

fivdi avatar fivdi commented on June 12, 2024

@rajanlagah Any news on this one?

from onoff.

rajanlagah avatar rajanlagah commented on June 12, 2024

I do have
var relay2 = new Gpio(20, 'out'); and then

function enable( ){
    if(stage == 1){
        relay2.writeSync(1);
    }
    if(stage == 2){
        liveD.writeSync(1);
    }
    if(stage == 3){
        relay2.writeSync(0);
    }
    if(stage == 4){
        liveD.writeSync(1);
    }
    if(stage < 4){
        setTimeout(enable(stage+1),500)
    }
}

As you can see i am performing only writeSync

from onoff.

fivdi avatar fivdi commented on June 12, 2024

As mentioned above, please post a complete (but short) program that can be run and used to reproduce the error rather than snippets of code.

I'm afraid I can't provide any help without a complete (but short) program that can be used to reproduce the error.

Edit: This line of code is most likely not doing what you think it is doing:

        setTimeout(enable(stage+1),500)

from onoff.

rajanlagah avatar rajanlagah commented on June 12, 2024
const LCD = require('lcdi2c');
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var liveA = new Gpio(21, 'out');
var liveB = new Gpio(26, 'out');
var liveC = new Gpio(19, 'out');
var liveD = new Gpio(13, 'out');
var relay1 = new Gpio(16, 'out');
var relay2 = new Gpio(20, 'out'); 

function enable( ){
    if(stage == 1){
        relay2.writeSync(1);
    }
    if(stage == 2){
        liveD.writeSync(1);
    }
    if(stage == 3){
        relay2.writeSync(0);
    }
    if(stage == 4){
        liveD.writeSync(1);
    }
    if(stage < 4){
        setTimeout(enable(stage+1),500)
    }
}

enable()

This is my short code

from onoff.

fivdi avatar fivdi commented on June 12, 2024

What is the output of that program when you run it?
Were is stage defined?

from onoff.

rajanlagah avatar rajanlagah commented on June 12, 2024

var blinkInterval = "" // setInterval(blinkLED, 500); //run the blinkLED function every 250ms
var stepNumber = 0;

function blinkLED() { //function to start blinking
  if (stepNumber == 0) {

        relay2.writeSync(1);
    vending = true;
    console.log("Turned off card");
    stepNumber = 1;

  } else if(stepNumber == 1){

    relay2.writeSync(0);
    stepNumber = 2;
    console.log("Turned on card");
    endBlink();
  }
}

function endBlink() { //function to stop blinking

  clearInterval(blinkInterval); // Stop blink intervals

  relay2.writeSync(0);
  console.log("Completed routine");
}

setTimeout(endBlink, 1000*60*5);

function enable( ){
    blinkInterval = setInterval(blinkLED, 500);
}
enable()

Another way of doing that but having same issue

from onoff.

rajanlagah avatar rajanlagah commented on June 12, 2024

What is the output of that program when you run it?
Were is stage defined?

Yes yes it was a global variable

later we did this
function enable( stage=1){

from onoff.

fivdi avatar fivdi commented on June 12, 2024

What is the output of this program when you run it?

from onoff.

rajanlagah avatar rajanlagah commented on June 12, 2024
internal/fs/utils.js:259
    throw err;
    ^

Error: EPERM: operation not permitted, write
    at Object.writeSync (fs.js:694:3)
    at Gpio.writeSync (/home/pi/onoff/node_modules/onoff/onoff.js:243:8)
    at a (/home/pi/onoff/t.js:7:10)
    at Object.<anonymous> (/home/pi/onoff/t.js:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -1,
  syscall: 'write',
  code: 'EPERM'
}

THIS

from onoff.

fivdi avatar fivdi commented on June 12, 2024

That is not the output. That was copied that from here. I'm afraid I can't provide any further help, good luck.

from onoff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.