So I have no idea how I need to word this but I've been told to ask a new question so here, editHere's the title accrdingly.Arduino code:
void setup() {
Serial.begin(9600);
pinMode(7, INPUT_PULLUP);
}
void loop() {
int val = digitalRead(7);
if (val == HIGH) {
Serial.print("1");
} else {
Serial.print("0");
}
Serial.println(""); // new line
}
Python code:
import time
import serial
# setup Arduino USB communication
try:
arduinoSerialData = serial.Serial('com3', 9600)
except: # not connected/damaged
pass
while True:
if arduinoSerialData.inWaiting() > 0:
datastr = arduinoSerialData.readline()
print datastr
time.sleep(1)
WHat I needwant to do digitalWrite(7, HIGH); in Arduino when thereadd is a Serial connection between Arduino and a, if Python program (PySerial) via USB. When the USB cable is disconnectedexits, or crashes, let the Arduino has to do do digitalWrite(7, LOW);
How can I know when Serial connection is "established" and when it is "disconnected"somehow. More specifically turn on a LED in Arduino?pin 8.