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')