Mi GRSNS
Mi GRSNS

Reputation: 3

setting rpi-gpio pin on high after running a python script

I'm building a photogrametry setup with raspberry pi and stepper motor. The python script runs fine, but i got a problem with setting a pin to high after the script ran through.

The stepper driver has an enable input, which diasables the motor with high input, so i set the pin (gpio26) on high on boot with pigpio, this works fine. While running the python script, the pin is set on low, so the stepper can proceed, after proceeding i want to set the pin on high again.

i tried following commands:

os.system('pigs w 26 1') and subprocess.call("pigs w 26 1", shell=True)

for a moment they work, but after exiting the script the pin is set on low again. It's like the commands are resetted after the script stops.

Where is my fault?

Thank you

Edit: Here is the gpio related code:

import os, sys
import subprocess
from time import sleep
from gpiozero import DigitalOutputDevice as stepper

def InitGPIO():
    try:
        global step_pul                     #pulse
        global step_en                      #enable
        step_pul=stepper(21)
        step_en=stepper(26)
        print ("GPIO initialisiert.")
    except:
        print ("Fehler bei der GPIO-Initialisierung.")
        
def motor_step():
    SPR=40000           #steps per rotation
    step_count = SPR
    delay = .000025
    for x in range(step_count):
        step_pul.on()
        sleep(delay)
        step_pul.off()
        sleep(delay)
        
InitGPIO()
step_en.off()

for i in range(1):
    #camTrigger(1)
    motor_step()   

#os.system('sudo -u root -S pigs w 26 1')
subprocess.call("pigs w 26 1", shell=True)

When i type pigs w 26 1 in the shell, it works...

Upvotes: 0

Views: 433

Answers (1)

AKX
AKX

Reputation: 169338

To make my comment an answer:

Gpiozero only resets the pins it touches, so if you don't initialize or touch pin 26 with gpiozero (i.e. replace step_en.off() with pigs w 26 0 and don't even initialize step_en), it shouldn't also reset the pin:

import os
import time

import gpiozero

step_pul = gpiozero.DigitalOutputDevice(21)


def motor_step():
    SPR = 40000  # steps per rotation
    step_count = SPR
    delay = .000025
    for x in range(step_count):
        step_pul.on()
        time.sleep(delay)
        step_pul.off()
        time.sleep(delay)


# Enable motor
os.system("pigs w 26 0")

for i in range(1):
    # camTrigger(1)
    motor_step()

# Disable motor
os.system("pigs w 26 1")

Upvotes: 0

Related Questions