Skip to main content
Update because some communication was detected without plugging in device : has to be improved...
Source Link

This should do the trick. There seemsI did not try to bego further, but I know there is some communicationinformation passing on Serial1 when you plug a device, you should be able to detect it with this code.

void setup() {  
  Serial.begin(115200);  
  Serial1.begin(250000);  
}

void loop() {  
  if(!Serial1.available()) {  
    Serial.println("OFF");  
    delay(500);  
  }  
  else {  
    Serial.println("ON");  
    Serial1.end();  
    delay(500);  
    Serial1.begin(250000);  
  }  
}  

Maybe you can try to see if depending on the device, information is persistent, in which case you should be able to detect a specific device / kinf of device ? I'll look at it tomorrow, maybe will have more code to show...

This should do the trick. There seems to be some communication on Serial1 when you plug a device, you should be able to detect it with this code

void setup() {  
  Serial.begin(115200);  
  Serial1.begin(250000);  
}

void loop() {  
  if(!Serial1.available()) {  
    Serial.println("OFF");  
    delay(500);  
  }  
  else {  
    Serial.println("ON");  
    Serial1.end();  
    delay(500);  
    Serial1.begin(250000);  
  }  
}  

I did not try to go further, but I know there is some information passing on Serial1 when you plug a device.

void setup() {  
  Serial.begin(115200);  
  Serial1.begin(250000);  
}

void loop() {  
  if(!Serial1.available()) {  
    Serial.println("OFF");  
    delay(500);  
  }  
  else {  
    Serial.println("ON");  
    Serial1.end();  
    delay(500);  
    Serial1.begin(250000);  
  }  
}  

Maybe you can try to see if depending on the device, information is persistent, in which case you should be able to detect a specific device / kinf of device ? I'll look at it tomorrow, maybe will have more code to show...

Source Link

This should do the trick. There seems to be some communication on Serial1 when you plug a device, you should be able to detect it with this code

void setup() {  
  Serial.begin(115200);  
  Serial1.begin(250000);  
}

void loop() {  
  if(!Serial1.available()) {  
    Serial.println("OFF");  
    delay(500);  
  }  
  else {  
    Serial.println("ON");  
    Serial1.end();  
    delay(500);  
    Serial1.begin(250000);  
  }  
}