Wpi issues in function node for controling gpio pins from function node

hey,
I have an issue with wpi.setup();

var wpi = context.global.wpi;

wpi.setup();

17.12.2019, 20:18:43node: Move!function : (error)

"TypeError: Cannot read property 'Setup' of undefined"

can anyone help me with some info?
Thx

What is wpi ?

We really need more info if you want assistance.

here is my cod in the Move! function node to control gpio pins

var front = 18;
var back = 16;

var right =11;
var left = 13;

var led1 = 1;

var wpi = context.global.wpi;

wpi.setup();

wpi.pinMode(front, wpi.modes.OUTPUT);
wpi.pinMode(back, wpi.modes.OUTPUT);
wpi.pinMode(right, wpi.modes.OUTPUT);
wpi.pinMode(left, wpi.modes.OUTPUT);
wpi.pinMode(led1, wpi.modes.OUTPUT);

wpi.digitalWrite(front, wpi.LOW);
wpi.digitalWrite(back, wpi.LOW);
wpi.digitalWrite(right, wpi.LOW);
wpi.digitalWrite(left, wpi.LOW);
wpi.digitalWrite(led1, wpi.LOW);

if (msg.payload == "Forward"){
console.log("Forward");
wpi.digitalWrite(back, wpi.HIGH);
wpi.digitalWrite(back, wpi.LOW);
wpi.digitalWrite(right, wpi.LOW);
wpi.digitalWrite(left, wpi.LOW);
wpi.digitalWrite(led1, wpi.LOW);
} else if (msg.payload == "Reverse"){
console.log("Reverse");
wpi.digitalWrite(front, wpi.LOW);
wpi.digitalWrite(back, wpi.HIGH);
wpi.digitalWrite(right, wpi.LOW);
wpi.digitalWrite(left, wpi.LOW);
wpi.digitalWrite(led1, wpi.LOW);
} else if (msg.payload == "Right"){
console.log("Right");
wpi.digitalWrite(front, wpi.LOW);
wpi.digitalWrite(back, wpi.LOW);
wpi.digitalWrite(right, wpi.HIGH);
wpi.digitalWrite(left, wpi.LOW);
wpi.digitalWrite(led1, wpi.LOW);
} else if (msg.payload == "Left"){
console.log("Left");
wpi.digitalWrite(front, wpi.LOW);
wpi.digitalWrite(back, wpi.LOW);
wpi.digitalWrite(right, wpi.LOW);
wpi.digitalWrite(left, wpi.HIGH);
wpi.digitalWrite(led1, wpi.LOW);
} else{
console.log("Stop");
wpi.digitalWrite(front, wpi.LOW);
wpi.digitalWrite(back, wpi.LOW);
wpi.digitalWrite(right, wpi.LOW);
wpi.digitalWrite(left, wpi.LOW);
wpi.digitalWrite(led1, wpi.LOW);
}

return msg;

Where did you get the

var wpi = context.global.wpi;

wpi.setup();

from ?

Maybe wpi is a node version of the old wiring-pi C library????

I saw it in a youtube video.
How can i control gpio pins in function node?
I have no knowledge in using raspberry gpio pins unfortunately and i need it for my license project

Have you considered using...

node-red-node-pi-gpio

Gives you input and output capability to control the Pi's GPIO pins.

Can you post a link to the video?

@dynamicdave That won't let them control pins within a function node

I've just read the thread in more detail and can now see what the person is trying/hoping to do.

Right - found this

@vv3Ak

have you done this step

Even then it might not work as wiring-pi project has been discontinued so you might have to use the normal Pi nodes as @dynamicdave has mentioned

This is what I'd do... although I've not tried it.

ScreenShot045

PS: I've never had to control the Pi's GPIO pins as I use a Wemos D1 Mini (ESP8266) to interface to external devices (as I think it's safer - no chance of destroying your valuable RPi).

PPS: Oops - forgot to include the LED as one of the outputs in the sketch.

And that would - if only there was a consistent pin numbering scheme for Pi :slight_smile:
http://wiringpi.com/pins/

I'm going to try this later when i get home.
Thx for helping

Hello,
the wiring-pi didn't work, I resolved it with function with 4 outputs.
Thank you for helping

1 Like