Hi mrtm3050,
I doubt I can help with the python script but perhaps I can help fix your arduino code.
The sketch you posted will not light the led and send serial data if one or more characters are available on the serial port. Is this really the functionality you want? I would guess you want the opposite – light the LED if a character is available on the serial port and the input pin is low.
I wonder if you are confused by the unintuitive use of the -1 return code to serial read.
My guess is that this is what you want:
void loop() {
if(Serial.available()) { // do the following if one or more characters are available
val = Serial.read(); // remove a character from the serial buffer
if( val == 'A'){
// here if the character 'A' was received
Dval4 = digitalRead(Dpin4);
if(Dval4 == LOW) {
digitalWrite(ledPin, HIGH);
Serial.println(4);
}
else {
Serial.println(0);
}
}
}
}
IMO, calling Serial.available() to see if data is available is much more expressive than testing the return value from Serial.read for -1. I have seen -1 used in this way in a few times recently and hope this friendly post will encourage you to use the more common and intuitive Serial.available() method;