Hello,
I am a complete beginner to Raspberry Pi and Python. Currently, I am trying to convert the Arduino code that reads the serial string sent from RFID card through serial. The string has 12 characters, and I need to deal with the underscores and the carriage return. Here's the fragment of the Arduino code:
Now, for Raspberry Pi I am using the following:
I am ignoring the underscores for now. It seems that the Arduino's method of finding the character in string does not work for Python. What would be the correct method of finding the carriage return? What is the Python's alternative for Arduino command "return"?
Thanks!
I am a complete beginner to Raspberry Pi and Python. Currently, I am trying to convert the Arduino code that reads the serial string sent from RFID card through serial. The string has 12 characters, and I need to deal with the underscores and the carriage return. Here's the fragment of the Arduino code:
Code:
void loop(){ if (RFID.available() > 0) { c = RFID.read(); // underscore? ignore it and jump to the next character if (c == '_') return; // send the character Serial.write(c); // if it was a carriage return send a linefeed character, too if (c == '\r') Serial.write('\n'); }}
Now, for Raspberry Pi I am using the following:
Code:
import serialser = serial.Serial(' /dev/ttyAMA0', 9600)while True: string = ser.read() if '\r' in string: print('\r\n')
Thanks!
Statistics: Posted by santon — Wed Feb 26, 2025 3:21 pm