Hi,
I am currently trying to read data from this temperature sensor and read RFID-Cards at the same time. Therefore I also bought the RC522 Reader/Writer from joy-it. When I use them in separated scripts they work fine.
Scripts:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import sys
sys.path.append('/home/pi/MFRC522-python')
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
print("Show your card")
try:
id,text = reader.read()
print(id)
print(text)
finally:
GPIO.cleanup()
import time
import grovepi
# Connect the Grove Temperature Sensor to analog port A0
# SIG,NC,VCC,GND
TEMP1_PIN = 0
while True:
try:
temp1 = round(grovepi.temp(TEMP1_PIN,'1.2'))
print(temp1)
time.sleep(2)
except KeyboardInterrupt:
break
except IOError:
print ("Error")
But when I try to read a RFID tag and and the sensor data in the same script:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import sys
sys.path.append('/home/pi/MFRC522-python')
from mfrc522 import SimpleMFRC522
import time
import grovepi
TEMP1_PIN = 0
i = 0
while i<20:
if i%2 == 0:
try:
temp1 = round(grovepi.temp(TEMP1_PIN,'1.2'))
print(temp1)
except KeyboardInterrupt:
print("interrupted")
else:
try:
print("Show Card")
reader = SimpleMFRC522()
id,text = reader.read()
del reader
print(id)
print(text)
finally:
GPIO.cleanup()
i += 1
they seem to block each other from reading. When I start the program the output is:
23
Show Card
718099397027
hallo
So what I made of this is, that without creating an SimpleMFRC522 object it is possible to read from the sensor. But after creating such an object it just freezes while trying to receive the data from the sensor. I tried to solve this by deleting the object after the card was read, but that didn’t help. I also tried to understand the exact reason on why this is happening, but I only found out that the RFID-Reader communicates via SPI and the GrovePi via I²C (or not?) and that these communications usually don’t interfere with each other, as they are using different ports of the Pi.
My question is, if anybody knows why exactly this happens and if there is a way to solve this problem.
Greetings Joe
note: I am sorry, if some of my formatting are not correct or not fitting for this forum. I am new to using a raspberryPi and GrovePi.