Sending data from Raspberry to Arduino serial communication

Hello! Please help me
I am stuck on a project for 2 days and I can't find an answer. I tried a simple debugging and I don t know what's wrong.
I try to send a simple number from Raspberry to Arduino using python.
When the number is received by Arduino is checked with the same number, the led flash once and then stops instead of blinking continuosly.
It seems my loop is stoping working after checking if connection exists and r become 3. I don't know how to pass this.

Arduino code: I complicated code to put every exception possible and it doesn't pass to blink continously. It works only once everything I do.

int r = 1;
boolean boolmaster = false;
boolean counter = false;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
if(boolmaster == false)
{
check_serial();
blinkled();
}
else
{
blinkled();
}
} // wait for a second
void check_serial()
{
if (counter == false)
{
if(Serial.available() > 0)
{
r = r *(Serial.read() - '0');

if(r == 3)
{
boolmaster = true;
counter = true;
}
}}
else
{
boolmaster = true;
}
}
void blinkled()
{
if (boolmaster == true)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
}

Py script:
import serial
ser = serial.Serial('dev...')
ser.write(b'3')

There is a python serial comms article in in the "interfacing with the computer" section.

It works in combination with the code in the "serial input basics" article.

Do a search; I'm on a cellphone at the moment.

I tried the easiest thing now. It's seems that my loop doesn't work after flashing one time.

bool counter = false;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}

void loop() {
if(Serial.available() > 0) // put your main code here, to run repeatedly:
{digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500);
counter = true; }
else if (counter == true)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
}

This simple Python - Arduino demo should help get you started.

...R

So python must be like in a loop also. I believed that if I send a simple write function to Arduino, Arduino will work without be affected by Raspberry. I will read more about this or if it's too hard I will pass and I will try an open/ closed contact communication or by a server . Thank you!

metalamen96:
So python must be like in a loop also. I believed that if I send a simple write function to Arduino, Arduino will work without be affected by Raspberry. I will read more about this or if it's too hard I will pass and I will try an open/ closed contact communication or by a server . Thank you!

I don't understand that.

...R