Code : Tout sélectionner
import RPi.GPIO as GPIO
ImportError: No module named 'RPi'
Modérateurs : Francois, Manfraid
Code : Tout sélectionner
import RPi.GPIO as GPIO
ImportError: No module named 'RPi'
Ha ben oui en effetManfraid a écrit :Si tu essaye le code sur ton PC et non sur le Pi c'est normal le module RPi.GPIO est propre au raspberry c'est le module qui permet de gérer les GPIO
Code : Tout sélectionner
test.py:46: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(pin,GPIO.OUT)
Je comprend pas ou je dois trouver l'info ?Manfraid a écrit :le programme fait combien de photo ? 1 ou 5
Code : Tout sélectionner
sequence = [1500]*50 # avance de 300pas pour 50 arret
Code : Tout sélectionner
call("raspistill -o myimage_%04d.jpg -tl 3000 -t 22500 -w 800 -h 600", shell=True)
Code : Tout sélectionner
#!/usr/bin/env python
#import pour comportement proche de python3
from __future__ import (unicode_literals, absolute_import,
print_function, division)
#import global
import RPi.GPIO as GPIO
from time import sleep,time
from subprocess import call
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
class MotorPaP(object):
""" class pour la gestion d'un moteur pas a pas
"""
seq = [[GPIO.HIGH,GPIO.LOW,GPIO.LOW,GPIO.LOW],
[GPIO.HIGH,GPIO.HIGH,GPIO.LOW,GPIO.LOW],
[GPIO.LOW,GPIO.HIGH,GPIO.LOW,GPIO.LOW],
[GPIO.LOW,GPIO.HIGH,GPIO.HIGH,GPIO.LOW],
[GPIO.LOW,GPIO.LOW,GPIO.HIGH,GPIO.LOW],
[GPIO.LOW,GPIO.LOW,GPIO.HIGH,GPIO.HIGH],
[GPIO.LOW,GPIO.LOW,GPIO.LOW,GPIO.HIGH],
[GPIO.HIGH,GPIO.LOW,GPIO.LOW,GPIO.HIGH]]
debug = False
def __init__(self,pins=[17,22,23,24],revolution=4096,rpm=10):
"""initialisation de la class avec les pins pour le moteur"""
self.pins = pins
self.rpm = rpm
self.revolution = revolution
#remise a zero des sortie
self.InitOutput()
#temp de pause entre chaque pas
self.pause = 60/(revolution*rpm)
def InitOutput(self):
for pin in self.pins:
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
def ClearOutput(self):
for pin in self.pins:
GPIO.output(pin, GPIO.LOW)
GPIO.cleanup()
def set_all_pins_low(self):
for pin in self.pins:
GPIO.output(pin, GPIO.LOW)
def log(self,msg):
if self.debug:
print(msg)
def _setstep(self,pins):
for i in range(len(self.pins)):
GPIO.output(self.pins[i],pins[i])
def move(self,nbstep,sens=1):
if sens < 0:
self.seq.reverse()
for i in range(nbstep):
p = self.seq.pop(0)
self._setstep(p)
sleep(self.pause)
self.seq.append(p)
if sens < 0:
self.seq.reverse()
StepPins = [17,22,23,24]
PasParTour = 4096
TourParMinute = 1
motor = MotorPaP(StepPins,PasParTour,TourParMinute)
sequence = [1500]*50 # avance de 1500pas pour 50 arret
try:
i = 0
for s in sequence:
motor.move(s)
cmd = "raspistill -o myimage_{:04d}.jpg -w 800 -h 600".format(i)
call(cmd, shell=True)
i +=1
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()