Pages: 1 [2]   Go Down
Author Topic: How to detect if the board is connected to PC?  (Read 1718 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18786
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


USA, OH
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 07, 2012, 02:30:22 am by Nick Gammon » Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18786
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


USA, OH
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 07, 2012, 02:32:51 am by Stan09 » Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18786
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Keep on insulting people, and see what happens.
Logged


USA, OH
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are there any programmatically only alternatives?

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

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 08, 2012, 08:25:32 pm by PGTBOOS » Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

USA, OH
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
« Last Edit: July 08, 2012, 10:38:15 pm by Stan09 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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........
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

USA, OH
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)'
Logged

Pages: 1 [2]   Go Up
Jump to: