Is there a way for the arduino to see if it is connected to the computer?
Thanks!
baum
Is there a way for the arduino to see if it is connected to the computer?
Thanks!
baum
baum:
Is there a way for the arduino to see if it is connected to the computer?Thanks!
baum
Maybe, would it be enough just to determine if board is being power by the USB connection or external power?
Lefty
I guess, but I was asking more to check if a serial port was open.
Either way, how do you check the power source?
baum
I guess, but I was asking more to check if a serial port was open.
The Arduino opens one end when the Serial.begin() method is called. You know whether you called that method, right?
You are looking, I think, to see if there is something that has opened the other end of the serial port. You can send a message to that application, and see if you get a reply. "Hey, Joe, are you listening?" Either Joe is, and says "Yo was up" or Joe isn't listening (or isn't responding, which means something slightly different).
But my computer then would need a program to respond to serial data. How do I check what is powering the arduino?
You need to start my making it clear what you are asking for. Knowing whether there is a serial connection and knowing whether the board is battery/mains powered vs. USB powered are two completely different things.
The Vin pin should have 5V on it when the Arduino has external power applied, and nothing if it is USB (only) powered. Check this with a voltmeter. If indeed it is the case, just run a wire from Vin to an analog pin, and read the value.
OK. That sounds good.
Thanks!
baum