Closed floinay closed 2 years ago
Raspberry pi 2 B Hi, i try turn on/off Pin with your library, gpio.write(true) work, but gpio.write(false) not working. Also i check this functionality with python - works done, but i want use nodejs nodejs code:
const gpiop = require('rpi-gpio').promise; const gpio = require('rpi-gpio'); const Gpio = require('onoff').Gpio; // const RELAY_PIN = 17; console.log(RELAY_PIN); let relayPinValue = false; gpio.setMode(gpio.MODE_BCM); const delaySeconds = async (seconds) => new Promise(resolve => setTimeout(() => resolve(), seconds * 1000)); async function relayTest() { await gpiop.setup(RELAY_PIN, gpio.DIR_OUT); while (true) { console.log(relayPinValue); try { await gpiop.write(RELAY_PIN, relayPinValue); } catch (e) { console.log(e); } relayPinValue = !relayPinValue; await delaySeconds(3); } } relayTest();
python code:
import RPi.GPIO as GPIO import time channel = 17 # GPIO setup GPIO.setmode(GPIO.BCM) GPIO.setup(channel, GPIO.OUT) def motor_on(pin): GPIO.output(pin, GPIO.HIGH) # Turn motor on def motor_off(pin): GPIO.output(pin, GPIO.LOW) # Turn motor off if __name__ == '__main__': try: motor_on(channel) time.sleep(1) motor_off(channel) time.sleep(1) GPIO.cleanup() except KeyboardInterrupt: GPIO.cleanup()
Sorry this my error, relay 5v, the GPIO power was not enough to turn it off
Raspberry pi 2 B Hi, i try turn on/off Pin with your library, gpio.write(true) work, but gpio.write(false) not working. Also i check this functionality with python - works done, but i want use nodejs nodejs code:
python code: