ich bin unwissend

Ich möchte gerne, dass von einem RFID-Transponder die uid ausgelesen wird.
Je nach Transponder soll dann eine andere LED aufleuchten.
Bei dem LED-Code - der unabhängig - vom RFID-Code läuft, hängt sich der Code auf ... und ich weiss nicht, warum.
Vielleicht habt ihr ja einen Tipp für mich und könnt mit dem Fehler was anfangen:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf8 -*-
import RPi.GPIO as GPIO
import MFRC522
import signal
import sys
import time
# !/usr/bin/python
# -*- coding: utf-8 -*-
LED_1 = 20 #rot
LED_2 = 4 #gelb
LED_3 = 27 # gruen
DELAY = 1
continue_reading = True
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
# This loop keeps checking for chips.
# #If one is near it will get the UID and authenticate
while continue_reading:
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
karten_id0 = "" + str(uid[0]) + ""
karten_id1 = "" + str(uid[1]) + ""
karten_id2 = "" + str(uid[2]) + ""
karten_id3 = "" + str(uid[3]) + ""
karten_gesamt = karten_id0 + karten_id1 + karten_id2 + karten_id3
# ", str(uid[1]), str(uid[2]), str(uid[3])"
# Print UID
if karten_gesamt == "134194169187":
print "hallo uid"
if __name__ == '__main__': # Programmstart
GPIO.setmode(GPIO.BCM) # GPIO-Nummer verwenden
GPIO.setwarnings(False) # Warnungen ausschalten
GPIO.setup(LED_2, GPIO.OUT) # Pin als Ausgang verwenden
try:
while True:
GPIO.output(LED_2, GPIO.LOW)
time.sleep(1)
GPIO.output(LED_2, GPIO.HIGH)
time.sleep(DELAY)
except KeyboardInterrupt: # wenn 'CTRL-C' gedrückt, dann Ende
GPIO.cleanup() # RESET, GPIO-Pins freigeben
sys.exit()
else:
print "das war nichts"
# print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
#print karten_gesamt
#print ""+str(uid[0])+""
# This is the default key for authentication
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
# Select the scanned tag
MIFAREReader.MFRC522_SelectTag(uid)
# Authenticate
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)
# Check if authenticated
if status == MIFAREReader.MI_OK:
MIFAREReader.MFRC522_Read(8)
MIFAREReader.MFRC522_StopCrypto1()
else:
print "Authentication error"
GPIO.setmode(GPIO.BCM)
ValueError: A different mode has already been set!