Code: Select all
import os
import threading
import urllib2
import Serial
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.2)
while True:
RFID = port.readline()
if len(RFID)>10:
print (RFID)Code: Select all
import os
import threading
import urllib2
import Serial
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.2)
while True:
RFID = port.readline()
if len(RFID)>10:
print (RFID)Code: Select all
import csv
import serial
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.5)
while True:
RFID = port.readline()
if len(RFID)>10:
print (RFID)
with open('data.csv' , 'w' , newline='') as fp:
a = csv.writer(fp,delimiter=',')
data = [RFID]
a.writerows(data)
Code: Select all
while True:
print ("step 1")
print("step 2")Code: Select all
while True:
print ("step 1")
print("step 2")Code: Select all
import serial
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.5)
while True:
RFID = port.readline()
if len(RFID)>10:
print (RFID)
csvresult = open("/home/pi/data.csv","a")
data = str(RFID)
csvresult.write(data + "," + "\n")
csvresult.closeCode: Select all
while True:
RFID = port.readline()
time.sleep(0.5)
if len(RFID)>10:ghp wrote:Hello,
writing to a file is quite fast, usually. Is the csv-file very large ?
Did you insert the print(RFID) direct after the read ? And how does this printout look like ?
Post current code please.
Regards,
Gerhard
pcmanbob wrote:it may be that you are not giving the Pi time to read the tag before you try processing the answer.
Try putting a sleep(0.5) between the line reading the tag and the if statement,
like thisyou will of course need to add "import time" to the top of your program as well.Code: Select all
while True: RFID = port.readline() time.sleep(0.5) if len(RFID)>10:
Code: Select all
import serial
import time
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.5)
while True:
RFID = port.readline()
if len(RFID) < 10:
RFID = "error less than 10"
print (RFID)
csvresult = open("/home/pi/data.csv","a")
data = str(RFID)
csvresult.write(data + "," + "\n")
csvresult.close
time.sleep (0.1)