I'm working on a project in which I have to receive some 25 character data at a time in order to process it in Raspberry Pi. Here is the example code that generates some data I want to receive from Arduino:
char i =0;
char a =0;
char b=0;
void setup(){
Serial.begin(9600);
for(i=0;i<25;i++){
Serial.print('l');}
Serial.print('\n');
delay(2000);
}
void loop(){
for(i=0;i<25;i++){
for(a=0;a<i;a++){
if((a==9)||(a==19)||(a==24))
Serial.print('l');
else
Serial.print('d');
}
for(b=0;b<25-i;b++){
Serial.print('l');
}
delay(2000);
}
}
It sends a line like this 'llllddddllldddd...' This line is 25 characters length. Now, I want to receive this with Raspberry Pi. Here is the code I'm trying to work:
ser = serial.Serial('/dev/AMA0',9600,timeout=1)
ser.open()
try:
serial_data = ser.readline()
print serial_data
except serial.serialutil.SerialException:
pass
This code receives data very correctly for like 5 seconds, and then suddenly stops receiving.
Moreover, when I try the following, I get no output, or Input/output errors.
serial_data = ser.readline()
print serial_data
EDIT1: Okay, I commented the exception now. It gives the following error:
raise SerialException('device reporst rediness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
What is the correct way to receive a 25 character data from arduino into raspberry via PySerial? Any help will be greately appreciated.