Go Down

Topic: Heartbeat from Arduino to PC via wire, how? (Read 3575 times) previous topic - next topic


I want to do some tests on battery life with various parameters. I plan to set up the device with the code for the specific experiment and then let it run until it dies out. So how do I know when it dies?

I want to let my computer log that in one way or another. I am really, really new in this so bear with me :)

This is my equipment:
* USB to Serial, "3.3V FTDI Basic", from SparkFun.com
* Arduino Fio

I see the following possibilities, but don't know if they are possible:
1) Connecting the FTDI to the 6 pins on the Fio, as when uploading code. Then somehow have the Fio send a heartbeat via this.
2) Connecting a digital port on the Fio with some pin on the FTDI using a small wire. Then have the Fio send a heartbeat on the digital out and have the pc listen on the virtual serial port.

In either case, I could really use some good advice to get me started :)

Thanks, Velle


How do you currently debug code on the Arduino? That is the way to connect the FTDI to the Arduino, then.

Will the Arduino be measuring battery voltage? If not, what will it be doing? Is the Arduino powered by the battery being abused?

There are too few details in your post to offer any real suggestions.
The art of getting good answers lies in asking good questions.


It will have some kind of meaningless behavior, e.g. measuring photocell every 5 seconds. Versus measuring flex sensor every 5 seconds. I want to see how different kinds of sensor readings, and different patterns of radio communication (AT over XBee) will affect battery life. All data will be dummy data. I will make at at least 10 such experiments.

I currently don't know of any clever way of debugging! I write my code carefully and I watch the behavior of the radio communication, if any unexpected behavior then I read my code 5 times over again. As I said, I am really new to this! But if there is a way of having the Arduino write live debugging information to a PC, I guess that is what I need!!

Side note: I can't use the XBee transmissions as heartbeat since I also want to measure battery life for some sketches that have the XBee sleeping forver or even not attached.

I don't know if this Arduino can measure battery voltage. If it can, then I still want to implement the heart beat part first, and perhaps play with battery voltage measurements at a later point. Right now, I am just looking for the easiest way of transmitting heartbeats, just any kind of signal that it is still running, to a PC.

Sorry, but I don't understand your 'abuse' question?

Thanks, Velle


I watch the behavior of the radio communication, if any unexpected behavior then I read my code 5 times over again.

Can you see radio waves? I certainly can't. So, I don't know what this statement means.

The FTDI cable is connected to the Arduino in one way, to enable the PC to communicate with the Arduino via a serial port. You can, after uploading code, open the Serial Monitor, and see anything that the Arduino uses Serial.print(), Serial.println(), or Serial.write() to send to the serial port.

I don't know if this Arduino can measure battery voltage.

Sure it can. Connect a the positive side to an analog pin, and the negative side to ground, if the battery voltage is 5V or less. If it is greater than 5V, use a voltage divider (+ to one end, middle to analog pin, other end to ground).

Sorry, but I don't understand your 'abuse' question?

You are trying to beat a battery to death, making it do various things, measuring how long those various things take to kill the battery. That's what I meant by abuse.

It still isn't clear whether the battery will be powering the Arduino, too, so that the Arduino stops sending data when the battery voltage drops too low. If so, then you are missing a great opportunity to measure and plot how the voltage drops off, if all you are sending for data is "I'm still here" every so often.
The art of getting good answers lies in asking good questions.


My sketches so far have been very simple, and I have been able to tell if they were performing correctly by reading what was sent by the Fio over XBee to the PC. Anyway, my point is that I did not use a dedicated debugging tool.

I get it now, that Serial.write writes to the serial port. And I am able to read that data in the Serial Monitor. Great! However, that data is also sent on the XBee radio. I set up the radio as they suggest here: http://arduino.cc/en/Main/ArduinoBoardFioProgramming. Can I set up the XBee module such that I can write to the XBee radio and not to the serial port (the six physical pins on the Fio) and vice versa? I think if I can achieve that, then I am ready to go.

Side note: I am researching the battery behaviour (safety mechanisms agains over-draining and over-charging), charging behavior, voltage measurement etc. I will get back about this when I know a bit more. Thanks for the hints.


I think you're saying that you want to have a PC monitor an Arduino to confirm that it is running, without powering the Arduino from the PC. I assume you want to avoid snipping USB power lines.

Connecting via FTDI instead of via the USB port seems like a good option, if you have a suitable adapter.

Another option is to set up a serial connection from the Arduino under test to a monitoring Arduino; the purpose of the monitoring Arduino would be to detect when the Arduino under test stops communicating. It is up to you whether the monitoring Arduino detects the 'death' of the test subject itself, or merely passes communications through to the PC and have the detection done there. It is up to you whether you want that communication to include any other data such as battery voltage/status from the test subject.


On the Arduino Fio, the USB connector is only for powering and charging the battery, it can't be used for communication, so that was never an option in the first place.

But I just realized that the FTDI supplies power too. Even when the power switch on the Fio is off, if the FTDI is connected, the power diode is on. So having the FTDI connected would also contribute with some power to the device, and thus decrease the energy consumed from the battery, right?

Maybe I could make a custom connector which connected the five pins (GND, AREV, RX1, TX0, DTR) but did not connect the 3V3. Would such a thing work?


May 12, 2012, 08:42 pm Last Edit: May 12, 2012, 08:45 pm by velle Reason: 1
I found my heart beat solution. And it was in fact very simple.

I used the SoftwareSerial library. It lets you use two digital pins as rx and tx on a serial port.

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX=D2, TX=D3

void setup() 

void loop() // run over and over

And then I wired D3 on the Fio to RX1 on the FTDI. I thought I also needed to connect ground between the two, but it works without. If you want to also send from the FTDI to the Fio, just connect D2 to TX0.

The "normal" Serial, sends via the XBee radio.

Thanks for your hints, advice and help, all of you.

Go Up