Go Down

Topic: How to detect if the board is connected to PC? (Read 1 time) previous topic - next topic

Nick Gammon

I think there was a thread a while back about detecting if you are connected to USB or not. Something to do with checking the voltage level of Vin. That may help.

I should point out that, unless you modify things a bit, connecting to the board via serial comms tends to assert RTS which resets the board. You may need to take that into account.

Another possibility is to have a switch or two on the board. Hit a button and it sends its data.
http://www.gammon.com.au/electronics

Stan09

#16
Jul 07, 2012, 09:18 am Last Edit: Jul 07, 2012, 09:30 am by Nick Gammon Reason: 1

I think there was a thread a while back about detecting if you are connected to USB or not. Something to do with checking the voltage level of Vin. That may help.

and that was exactly the post I was referring to in my first reply ... in this thread. I can refer to it again:
http://arduino.cc/forum/index.php?topic=107860.0


Moderator edit: Insult deleted.

Nick Gammon

Why are you asking then? Even so, I don't think it will be particularly reliable. Merely having power doesn't guarantee anything. I think my suggestion of a button you push when everything is connected, and the receiving program is ready, would be better.
http://www.gammon.com.au/electronics

Stan09

#18
Jul 07, 2012, 09:31 am Last Edit: Jul 07, 2012, 09:32 am by Stan09 Reason: 1
Nick, if you could bother yourself with reading the original post, you could have noticed I was asking for solutions _other_ then two most obvious ones. And with obvious reason as well: first one  - I cannot modify program code, second one - hardly reliable.

Nick Gammon

Keep on insulting people, and see what happens.
http://www.gammon.com.au/electronics

Stan09

Wow!
Don't be so important please.
Where is an insult? The mere fact I pointed out you are giving replies without reading original question?
Ban me, it will make you happy.

WizenedEE


Are there any programmatically only alternatives?


Can we just say "No" and be done with this?

PGT

#22
Jul 09, 2012, 02:56 am Last Edit: Jul 09, 2012, 03:25 am by PGTBOOS Reason: 1
Perhaps try to think outside of the box.. dont detect it.
You might write to both usb and to the SD you do it in a circular logging way. (FILO)
Circular logging is sometimes used in databases to have some time window to be able to restore data
Ofcourse its not the best.. but its better then nothing, and it might be all you want.
That is if you do not have to much data (or else your SD will be full quickly)..but it will always overwrite oldest data (so there is a time limit of how much data can be recovered back in time)..
Also keep in mind how often you can rewrite your SD...
If it is important data get it to a networked file cluster or so ..

Not sure how SD storage works (i dont have it)
if you have a file system on it, then keep a pointer to oldest write somewhere, and update it once you overwrite your oldest stored data samples. (circular logging).
When connected to PC perhaps also store a date time on the SD
Perhaps use clock shield or so.

You might have 2 arduino's around, another one to replay a SD to your compter, to restore data
or write a program that replays trough a comlink to fool the original computer program

PS for medical data it might not be wise to use an arduino, see its license its not to be used in environments that could change the dead or alive situation of a carbon based life form..or something like that.
Ask yourself what is the cost if your solution would fail, its not foolproof hardware it will brakedown someday



PS It might interest you to read about atomic databases  (no its not about physics) >Exchange uses it.

PeterH

The only solution I can see, given those constraints, is to have a second Arduino powered off the USB which acts as a bridge between the logger and the PC; you can arrange for this to give a handshake with the logger so that the logger knows whether it is there and hence whether the USB is powered up. Of course we have to assume that power on the USB means that the USB interface is fully functional, because you have ruled out every way I can think of to confirm that.

Not a brilliant solution, but the only one I can think of.
I only provide help via the forum - please do not contact me for private consultancy.

Stan09

#24
Jul 09, 2012, 05:22 am Last Edit: Jul 09, 2012, 05:38 am by Stan09 Reason: 1

Perhaps try to think outside of the box.. dont detect it.
You might write to both usb and to the SD you do it in a circular logging way. (FILO)

Well, first of all it was just "nice to have", and as I can see now, there are no simple ways, so heck with it.


PS for medical data it might not be wise to use an arduino, see its license its not to be used in environments that could change the dead or alive situation of a carbon based life form..or something like that.
Ask yourself what is the cost if your solution would fail, its not foolproof hardware it will brakedown someday

it costs nothing at all because there is also a "science". And even more to this, it is about mostly exercising... like, 'your zone' of Polar which actually has purchased the idea for cash from "unnamed" (Eastern European) source.
This is just my hobby... connect Arduino board to the living being, collect some data and tell when exactly that "living being" is  gonna bust away :)

vpinho13

Friend, I'm not sure about what do you want. But when I need to check if PC and Arduino is connected I use this.


String serialnumber;
void setup() {
  Serial.begin(9600);
  Serial.println ("Data between Arduino and PC ok!");
   int sensorValue = analogRead(A0);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  be continue........

PaulS

Quote
But when I need to check if PC and Arduino is connected I use this.

Which only assures that the Arduino was able to connect to one end of the serial port. There is nothing there that assures that there is anything on the other end of the port.

Stan09


Friend, I'm not sure about what do you want. But when I need to check if PC and Arduino is connected I use this.


String serialnumber;
void setup() {
  Serial.begin(9600);
  Serial.println ("Data between Arduino and PC ok!");
   int sensorValue = analogRead(A0);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  be continue........

Are you  saying that if Serial.begin does not fail this along proves it is connected?
Certainly not.
The have such a functionality for Ard Leonardo, though, as I stated in my initial post, that is  a clause 'if(serial)'

Go Up