SlideShare une entreprise Scribd logo
1  sur  2
#!/usr/bin/env python
# Import required libraries
import time
import RPi.GPIO as GPIO
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Define GPIO signals to use
# As input IN1,IN2,IN3,IN4
# As Coils A A B B
StepPins = [22, 23, 24, 25]
# NUM PIN Color
# 1 A Black/NEGRO----| COIL A
# 2 A Brawn/MARRON---/
# 3 B Orang/NARANJA--
# 4 B Yello/AMARILLO-| COIL B
# Set all pins as output
def SetPins():
for pin in StepPins:
print "Setup GPIO%i as output" %(pin)
GPIO.setup(pin,GPIO.OUT)
# Set all pins as output
def PinsOff():
for pin in StepPins:
GPIO.output(pin, False)
# ----------------------------
SetPins()
PinsOff()
# Define simple sequence
SeqFull = []
SeqFull = range(4)
# A A B B
SeqFull[0] = [ 1, 0, 1, 0 ]
SeqFull[1] = [ 0, 1, 1, 0 ]
SeqFull[2] = [ 0, 1, 0, 1 ]
SeqFull[3] = [ 1, 0, 0, 1 ]
# Define advanced sequence
# as shown in manufacturers datasheet
SeqHalf = []
SeqHalf = range(8)
# A A B B
SeqHalf[0] = [ 1, 0, 1, 0 ]
SeqHalf[1] = [ 0, 0, 1, 0 ]
SeqHalf[2] = [ 0, 1, 1, 0 ]
SeqHalf[3] = [ 0, 1, 0, 0 ]
SeqHalf[4] = [ 0, 1, 0, 1 ]
SeqHalf[5] = [ 0, 0, 0, 1 ]
SeqHalf[6] = [ 1, 0, 0, 1 ]
SeqHalf[7] = [ 1, 0, 0, 0 ]
# Define some settings
StepCounter = 0
WaitTime = 0.025
# Choose a sequence to use
Seq = SeqFull
StepCount = len(Seq)
def NextStep(Count,Step,Dir):
Next=int(Step)+int(Dir)
if Next==Count:
Next=0
elif Next==-1:
Next=Count-1
return Next
# Start main loop
StepPerRev=24*(StepCount/4)
GoSteps = StepPerRev+4
CurrentSetp = 0
Dir = 1
Step = 0
while GoSteps != CurrentSetp:
try:
CurrentSetp = CurrentSetp + 1
Step=NextStep(StepCount,Step,Dir)
# Set 4 pin status
for pin in range(4):
if Seq[Step][pin]!=0:
GPIO.output(StepPins[pin], True)
else:
GPIO.output(StepPins[pin], False)
# Wait a sleep time
time.sleep(WaitTime)
except KeyboardInterrupt:
print " break!"
PinsOff()
exit(1)
#
PinsOff()
exit(0)

Contenu connexe

En vedette

En vedette (15)

Analizando la efectividad de ataques de correlación pasivos en la red de ano...
Analizando la efectividad de ataques de correlación pasivos en la red de ano...Analizando la efectividad de ataques de correlación pasivos en la red de ano...
Analizando la efectividad de ataques de correlación pasivos en la red de ano...
 
It's a Kind of Magic
It's a Kind of MagicIt's a Kind of Magic
It's a Kind of Magic
 
Hacking con Python
Hacking con PythonHacking con Python
Hacking con Python
 
Ingenieros y hackers
Ingenieros y hackersIngenieros y hackers
Ingenieros y hackers
 
Pentesting con PowerShell: Libro de 0xWord
Pentesting con PowerShell: Libro de 0xWordPentesting con PowerShell: Libro de 0xWord
Pentesting con PowerShell: Libro de 0xWord
 
Cuarta Edición del Curso Online de Especialización en Seguridad Informática p...
Cuarta Edición del Curso Online de Especialización en Seguridad Informática p...Cuarta Edición del Curso Online de Especialización en Seguridad Informática p...
Cuarta Edición del Curso Online de Especialización en Seguridad Informática p...
 
Configurar y utilizar Latch en Magento
Configurar y utilizar Latch en MagentoConfigurar y utilizar Latch en Magento
Configurar y utilizar Latch en Magento
 
Dorking & Pentesting with Tacyt
Dorking & Pentesting with TacytDorking & Pentesting with Tacyt
Dorking & Pentesting with Tacyt
 
New Paradigms of Digital Identity: Authentication & Authorization as a Servic...
New Paradigms of Digital Identity: Authentication & Authorization as a Servic...New Paradigms of Digital Identity: Authentication & Authorization as a Servic...
New Paradigms of Digital Identity: Authentication & Authorization as a Servic...
 
Índice Pentesting con Kali 2.0
Índice Pentesting con Kali 2.0Índice Pentesting con Kali 2.0
Índice Pentesting con Kali 2.0
 
Cazando Cibercriminales con: OSINT + Cloud Computing + Big Data
Cazando Cibercriminales con: OSINT + Cloud Computing + Big DataCazando Cibercriminales con: OSINT + Cloud Computing + Big Data
Cazando Cibercriminales con: OSINT + Cloud Computing + Big Data
 
Shuabang Botnet
Shuabang BotnetShuabang Botnet
Shuabang Botnet
 
CyberCamp 2015: Low Hanging Fruit
CyberCamp 2015: Low Hanging FruitCyberCamp 2015: Low Hanging Fruit
CyberCamp 2015: Low Hanging Fruit
 
Recuperar dispositivos de sonido en Windows Vista y Windows 7
Recuperar dispositivos de sonido en Windows Vista y Windows 7Recuperar dispositivos de sonido en Windows Vista y Windows 7
Recuperar dispositivos de sonido en Windows Vista y Windows 7
 
CritoReto 4: Buscando una aguja en un pajar
CritoReto 4: Buscando una aguja en un pajarCritoReto 4: Buscando una aguja en un pajar
CritoReto 4: Buscando una aguja en un pajar
 

Plus de Chema Alonso

Plus de Chema Alonso (7)

Foca API v0.1
Foca API v0.1Foca API v0.1
Foca API v0.1
 
Tu iPhone es tan (in)seguro como tu Windows
Tu iPhone es tan (in)seguro como tu WindowsTu iPhone es tan (in)seguro como tu Windows
Tu iPhone es tan (in)seguro como tu Windows
 
Codemotion ES 2014: Love Always Takes Care & Humility
Codemotion ES 2014: Love Always Takes Care & HumilityCodemotion ES 2014: Love Always Takes Care & Humility
Codemotion ES 2014: Love Always Takes Care & Humility
 
No me indexes que me cacheo
No me indexes que me cacheoNo me indexes que me cacheo
No me indexes que me cacheo
 
XSS Google Persistentes
XSS Google PersistentesXSS Google Persistentes
XSS Google Persistentes
 
X Fórum AUSAPE 2014: Un Decálogo de Seguridad Máligna
X Fórum AUSAPE 2014: Un Decálogo de Seguridad MálignaX Fórum AUSAPE 2014: Un Decálogo de Seguridad Máligna
X Fórum AUSAPE 2014: Un Decálogo de Seguridad Máligna
 
LDAP Injection Techniques
LDAP Injection TechniquesLDAP Injection Techniques
LDAP Injection Techniques
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Código para Latch físico: Stepper_open.py

  • 1. #!/usr/bin/env python # Import required libraries import time import RPi.GPIO as GPIO # Use BCM GPIO references # instead of physical pin numbers GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Define GPIO signals to use # As input IN1,IN2,IN3,IN4 # As Coils A A B B StepPins = [22, 23, 24, 25] # NUM PIN Color # 1 A Black/NEGRO----| COIL A # 2 A Brawn/MARRON---/ # 3 B Orang/NARANJA-- # 4 B Yello/AMARILLO-| COIL B # Set all pins as output def SetPins(): for pin in StepPins: print "Setup GPIO%i as output" %(pin) GPIO.setup(pin,GPIO.OUT) # Set all pins as output def PinsOff(): for pin in StepPins: GPIO.output(pin, False) # ---------------------------- SetPins() PinsOff() # Define simple sequence SeqFull = [] SeqFull = range(4) # A A B B SeqFull[0] = [ 1, 0, 1, 0 ] SeqFull[1] = [ 0, 1, 1, 0 ] SeqFull[2] = [ 0, 1, 0, 1 ] SeqFull[3] = [ 1, 0, 0, 1 ] # Define advanced sequence # as shown in manufacturers datasheet SeqHalf = [] SeqHalf = range(8) # A A B B SeqHalf[0] = [ 1, 0, 1, 0 ] SeqHalf[1] = [ 0, 0, 1, 0 ] SeqHalf[2] = [ 0, 1, 1, 0 ] SeqHalf[3] = [ 0, 1, 0, 0 ] SeqHalf[4] = [ 0, 1, 0, 1 ] SeqHalf[5] = [ 0, 0, 0, 1 ] SeqHalf[6] = [ 1, 0, 0, 1 ] SeqHalf[7] = [ 1, 0, 0, 0 ] # Define some settings StepCounter = 0 WaitTime = 0.025
  • 2. # Choose a sequence to use Seq = SeqFull StepCount = len(Seq) def NextStep(Count,Step,Dir): Next=int(Step)+int(Dir) if Next==Count: Next=0 elif Next==-1: Next=Count-1 return Next # Start main loop StepPerRev=24*(StepCount/4) GoSteps = StepPerRev+4 CurrentSetp = 0 Dir = 1 Step = 0 while GoSteps != CurrentSetp: try: CurrentSetp = CurrentSetp + 1 Step=NextStep(StepCount,Step,Dir) # Set 4 pin status for pin in range(4): if Seq[Step][pin]!=0: GPIO.output(StepPins[pin], True) else: GPIO.output(StepPins[pin], False) # Wait a sleep time time.sleep(WaitTime) except KeyboardInterrupt: print " break!" PinsOff() exit(1) # PinsOff() exit(0)