Hi yall!
I have a Raspberry Pi 4b and a stepper motor driver(&stepper motor by breadboard) connected using GPIO pins. I was trying to make some adjustments in my code but my loop caused the motor to run nonstop so I scrapped it and went back to my original code. I tried to run it but I kept getting an error message which is weird since I've using the same code for over a year now and I didn't move any of my pins so idky there are issues now. I tried googling solutions but the word "ubuntu" keeps popping up, I have no idea what that is and I don't think I have it on my pi(sorry I'm a noob and this pi was given to me).
Does anyone know how to fix this error? Any tips or tricks are appreciated!
Here's my error message:Here's my spec:Here's my code:
I have a Raspberry Pi 4b and a stepper motor driver(&stepper motor by breadboard) connected using GPIO pins. I was trying to make some adjustments in my code but my loop caused the motor to run nonstop so I scrapped it and went back to my original code. I tried to run it but I kept getting an error message which is weird since I've using the same code for over a year now and I didn't move any of my pins so idky there are issues now. I tried googling solutions but the word "ubuntu" keeps popping up, I have no idea what that is and I don't think I have it on my pi(sorry I'm a noob and this pi was given to me).
Does anyone know how to fix this error? Any tips or tricks are appreciated!
Here's my error message:
Code:
File "/home/cmrlab/sm", line 28, in <module> GPIO.setup(standby_pin, GPIO.OUT) # Setup standby pin as outputRuntimeError: Not running on a RPi!Code:
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"NAME="Raspbian GNU/Linux"VERSION_ID="11"VERSION="11 (bullseye)"VERSION_CODENAME=bullseyeID=raspbianRPi.GPIO=0.7.0Code:
# -*- coding: utf-8 -*-#!/usr/bin/env python3import timefrom time import sleepimport RPi.GPIO as GPIO#Variable blockmode_pins = (24,23,22,17) # Modes pins, be careful at the sequence, see driver manualstandby_pin = 27 # Standby motor pinstep_pin = 22 # Step motor pindir_pin = 17 # Direction motor pinmicrostep = {'full': (0,0,0,0), 'half': (1,0,1,0), '1/4': (0,1,0,1), '1/8': (1,1,1,0), '1/16': (1,1,1,1), '1/32': (0,1,0,0), '1/64': (0,1,1,1), '1/128': (1,0,0,0), '1/256': (1,1,0,0) }#GPIO setup blockGPIO.setmode(GPIO.BCM) # Declare using BCM notationGPIO.setwarnings(False) # Warning messages at true or true as you wantGPIO.setup(standby_pin, GPIO.OUT) # Setup standby pin as outputGPIO.setup(24, GPIO.OUT) GPIO.setup(23, GPIO.OUT)GPIO.setup(22, GPIO.OUT)GPIO.setup(17, GPIO.OUT)# Change resolution functiondef change_resolution(resolution): GPIO.output(standby_pin,0) # Standby on i = 0 for i in range(4): GPIO.setup(mode_pins [i], GPIO.OUT) GPIO.output(mode_pins [i], microstep[resolution][i]) # Push stepmode to the driver GPIO.output(standby_pin,1) # Standby offdef test_mode(resolution, steps, step_sleep_delay): i = 0 print ("Mode_1 status = ", GPIO.input(24)) print ("Mode_2 status = ", GPIO.input(23)) print ("Mode_3 step status = ", GPIO.input(22)) print ("Mode_4 dir status ", GPIO.input(17),'\n') print ("Mode:",resolution," ", "Steps:",steps) change_resolution(resolution) if GPIO.output(17, 0) != 0 : GPIO.output(17, 0) while i <= steps: if i <= steps/2: GPIO.output(22, GPIO.HIGH) sleep(step_sleep_delay) GPIO.output(22, GPIO.LOW) elif i > steps/2: GPIO.output(17, 1) GPIO.output(22, GPIO.HIGH) sleep(step_sleep_delay) GPIO.output(22, GPIO.LOW) i = i+1 time.sleep(3.5)test_mode("full",400, 0.0036) #setting step mode ; number of steps ; and delay between steps (less = more smoothly)GPIO.output(22,GPIO.HIGH)Statistics: Posted by alxzhu — Tue Feb 13, 2024 10:27 pm — Replies 2 — Views 92