0

We are currently creating a system which can log student attendance using RFIDs. Currently, we have the RFID Scanner set up (MFRC522 reader and Arduino UNO microcontroller). The database for the student's info and time-logging is also already set up. We are; however, having problems with accessing the data the Arduino is sending. We want the Arduino device to send us the Tag IDs via a USB Connection and have set it up to send the relevant data through the Serial Port. However, we cannot access this data using a Python program with this code.

import serial

x = 1
while(x == 1 ):
    ser = serial.Serial("COM3", baudrate = 9600, timeout = 0)
    if(ser.is_open):
       print("Serial Port in Use")
    else:
       print("Card ID: " + ser.read)

We are attempting to read from Port COM3 (the SP the Arduino uses). If the serial port is in use, the program outputs the "Serial Port in Use" (for testing purposes only, to be removed in final code) and if not, it will output the Card ID. However, through this, we run into the problem of being unable to use the same serial port with the Arduino (we are running on Windows). We tried using a serial port splitter but replacing the "COM3" with the name of the virtual port does not work.

We would prefer not to use Processing and would be open to simply avoiding the use of a serial port completely.

  • How do I grab data from my Arduino device using a Python program? ...... use the serial port to transport the data ..... i think that you answered your own question – jsotola Mar 3 at 19:08
  • use the serial monitor in the Arduino IDE to verify the presence of valid data before you proceed with python code development – jsotola Mar 3 at 19:09
0

It isn't a good idea to open serial in a loop. It can be opened once at the start (or you can retry once per few seconds, if it fails).

Also the method is_open should return true if the serial was successfully opened so you can use it.

Maybe some working example would be a good way to start.

  • We are completely sure the Arduino is working properly, as checking the Serial Monitor reveals the device is reading properly. The real problem arises whenever we run the above code while the Arduino is plugged in and on. On running the code, an error occurs at Line 5 (opening the Serial Port). The error says, among other things "Cannot Open Port: Access Denied" – o0V0o Mar 4 at 5:57
  • @o0V0o I'm not questioning Arduino side. I'm just pointing on condition that seems to be wrong, and port opening logic in python code. – KIIV Mar 4 at 20:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.