I have two python scripts that both need to run to do what I want. Basically the first script is for a server that handles POST requests. It looks like this.
from bottle import Bottle, run, template, get, post, request
app = Bottle()
@app.route('/rotation', method='POST')
def set_rotation():
rotation = request.forms.get('count')
return rotation
if __name__ == '__main__':
run(app, host='145.24.226.121', port=8080)
The second script is to make a steppermotor run. This is the script.
# importeer de GPIO bibliotheek.
import RPi.GPIO as GPIO
# Importeer de time biblotheek voor tijdfuncties.
from time import sleep
# Zet de pinmode op Broadcom SOC.
GPIO.setmode(GPIO.BCM)
# Zet waarschuwingen uit.
GPIO.setwarnings(False)
# Stel de GPIO pinnen in voor de stappenmotor:
StepPins = [4,17,27,22]
# Set alle pinnen als uitgang.
for pin in StepPins:
print "Setup pins"
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, False)
# Definieer variabelen.
StepCounter = 0
# Definieer simpele volgorde
StepCount1 = 4
Seq1 = []
Seq1 = range(0, StepCount1)
Seq1[0] = [1,0,0,0]
Seq1[1] = [0,1,0,0]
Seq1[2] = [0,0,1,0]
Seq1[3] = [0,0,0,1]
# Definieer geadvanceerde volgorde (volgens de datasheet)
StepCount2 = 8
Seq2 = []
Seq2 = range(0, StepCount2)
Seq2[0] = [1,0,0,0]
Seq2[1] = [1,1,0,0]
Seq2[2] = [0,1,0,0]
Seq2[3] = [0,1,1,0]
Seq2[4] = [0,0,1,0]
Seq2[5] = [0,0,1,1]
Seq2[6] = [0,0,0,1]
Seq2[7] = [1,0,0,1]
# Welke stappenvolgorde gaan we hanteren?
Seq = Seq2
StepCount = StepCount2
try:
while True:
for pin in range(0, 4):
xpin = StepPins[pin]
if Seq[StepCounter][pin]!=0:
print "Stap: %i GPIO Actief: %i" %(StepCounter,xpin)
GPIO.output(xpin, True)
else:
GPIO.output(xpin, False)
StepCounter += 1
# Als we aan het einde van de stappenvolgorde zijn beland start dan opnieuw
if (StepCounter==StepCount): StepCounter = 0
if (StepCounter<0): StepCounter = StepCount
# Wacht voor de volgende stap (lager = snellere draaisnelheid)
sleep(.01)
except KeyboardInterrupt:
# GPIO netjes afsluiten
GPIO.cleanup()
I need the rotation value from the first script in the sleep function in the second script. Both scripts need to run so the first script can receive POST requests and the second script can make the steppermotor work. What is the best way to do this and is it even possible with this approach?