SHARE
TWEET

Untitled

a guest Mar 2nd, 2017 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import sys
  3. import time
  4. from time import sleep
  5. from RPi import GPIO
  6.  
  7. GPIO.setmode(GPIO.BCM)
  8.  
  9. def aktuelleTemperatur():
  10.    file = open('/sys/bus/w1/devices/28-0516866cffff/w1_slave')
  11.    filecontent = file.read()
  12.    file.close()
  13.  
  14.    stringvalue = filecontent.split("\n")[1].split(" ")[9]
  15.    temperature = float(stringvalue[2:]) / 1000
  16.  
  17.    rueckgabewert = '%6.2f' % temperature
  18.    return(rueckgabewert)
  19.  
  20.  
  21. # Verwendete Pins am Rapberry Pi
  22. A=18
  23. B=23
  24. C=24
  25. D=25
  26. time = 0.001
  27.  
  28. # Pins aus Ausgänge definieren
  29. GPIO.setup(A,GPIO.OUT)
  30. GPIO.setup(B,GPIO.OUT)
  31. GPIO.setup(C,GPIO.OUT)
  32. GPIO.setup(D,GPIO.OUT)
  33. GPIO.output(A, False)
  34. GPIO.output(B, False)
  35. GPIO.output(C, False)
  36. GPIO.output(D, False)
  37.  
  38. # Schritte 1 - 8 festlegen
  39. def Step1():
  40.     GPIO.output(D, True)
  41.     sleep (time)
  42.     GPIO.output(D, False)
  43.  
  44. def Step2():
  45.     GPIO.output(D, True)
  46.     GPIO.output(C, True)
  47.     sleep (time)
  48.     GPIO.output(D, False)
  49.     GPIO.output(C, False)
  50.  
  51. def Step3():
  52.     GPIO.output(C, True)
  53.     sleep (time)
  54.     GPIO.output(C, False)
  55.  
  56. def Step4():
  57.     GPIO.output(B, True)
  58.     GPIO.output(C, True)
  59.     sleep (time)
  60.     GPIO.output(B, False)
  61.     GPIO.output(C, False)
  62.  
  63. def Step5():
  64.     GPIO.output(B, True)
  65.     sleep (time)
  66.     GPIO.output(B, False)
  67.  
  68. def Step6():
  69.     GPIO.output(A, True)
  70.     GPIO.output(B, True)
  71.     sleep (time)
  72.     GPIO.output(A, False)
  73.     GPIO.output(B, False)
  74.  
  75. def Step7():
  76.     GPIO.output(A, True)
  77.     sleep (time)
  78.     GPIO.output(A, False)
  79.  
  80. def Step8():
  81.     GPIO.output(D, True)
  82.     GPIO.output(A, True)
  83.     sleep (time)
  84.     GPIO.output(D, False)
  85.     GPIO.output(A, False)
  86.  
  87. def tmpmgr():
  88.    Temperatur = aktuelleTemperatur()
  89.  
  90. # hier sollte er einen Linkslauf machen
  91.    if Temperatur < ' 110.00':
  92.        
  93.  
  94. # hier sollte er einen Rechtslauf machen
  95.    if Temperatur < ' 98.00':
  96.        
  97.    
  98.  
  99.  
  100.  
  101. while True:
  102.    tmpmgr()
  103.  
  104.  
  105. #EOF
  106.  
  107. Was ich jetzt irgentwie nicht hinbekomme das er sich bewegt.
  108.  
  109. Das reine Schrittmotor Skript ist:
  110.  
  111. from time import sleep
  112. import RPi.GPIO as GPIO
  113.  
  114. GPIO.setmode(GPIO.BCM)
  115.  
  116. # Verwendete Pins am Rapberry Pi
  117. A=18
  118. B=23
  119. C=24
  120. D=25
  121. time = 0.001
  122.  
  123. # Pins aus Ausgänge definieren
  124. GPIO.setup(A,GPIO.OUT)
  125. GPIO.setup(B,GPIO.OUT)
  126. GPIO.setup(C,GPIO.OUT)
  127. GPIO.setup(D,GPIO.OUT)
  128. GPIO.output(A, False)
  129. GPIO.output(B, False)
  130. GPIO.output(C, False)
  131. GPIO.output(D, False)
  132.  
  133. # Schritte 1 - 8 festlegen
  134. def Step1():
  135.     GPIO.output(D, True)
  136.     sleep (time)
  137.     GPIO.output(D, False)
  138.  
  139. def Step2():
  140.     GPIO.output(D, True)
  141.     GPIO.output(C, True)
  142.     sleep (time)
  143.     GPIO.output(D, False)
  144.     GPIO.output(C, False)
  145.  
  146. def Step3():
  147.     GPIO.output(C, True)
  148.     sleep (time)
  149.     GPIO.output(C, False)
  150.  
  151. def Step4():
  152.     GPIO.output(B, True)
  153.     GPIO.output(C, True)
  154.     sleep (time)
  155.     GPIO.output(B, False)
  156.     GPIO.output(C, False)
  157.  
  158. def Step5():
  159.     GPIO.output(B, True)
  160.     sleep (time)
  161.     GPIO.output(B, False)
  162.  
  163. def Step6():
  164.     GPIO.output(A, True)
  165.     GPIO.output(B, True)
  166.     sleep (time)
  167.     GPIO.output(A, False)
  168.     GPIO.output(B, False)
  169.  
  170. def Step7():
  171.     GPIO.output(A, True)
  172.     sleep (time)
  173.     GPIO.output(A, False)
  174.  
  175. def Step8():
  176.     GPIO.output(D, True)
  177.     GPIO.output(A, True)
  178.     sleep (time)
  179.     GPIO.output(D, False)
  180.     GPIO.output(A, False)
  181.  
  182. # Volle Umdrehung    
  183. # Für Linkslauf Steps umdrehen
  184. for i in range (512):    
  185.     Step1()
  186.     Step2()
  187.     Step3()
  188.     Step4()
  189.     Step5()
  190.     Step6()
  191.     Step7()
  192.     Step8()  
  193.     print i
  194.  
  195. GPIO.cleanup()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top