Arduino Serial Output

Active1 year, 3 months ago
$begingroup$

How can I save data retrieved from a sensor to a text file on the computer?

desNotesdesNotes
$endgroup$

The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License. Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.

8 Answers

$begingroup$

you can write the sensor data to the serial port using serial-lib and write a small processing program that reads the data from the serial port and writes it to a file.

in the arduino code initalize the serial lib in the setup method

and write your sensor values to the serial interface using

in your loop method

on the processing side use a PrintWriter to write the data read from the serial port to a file

Community
Nikolaus GradwohlNikolaus Gradwohl
Arduino Serial Output$endgroup$$begingroup$

Yet another option is to use an SD Card reader / writer, and write your file to a SD card. When you're done collecting data, swap out SD cards with your workstation computer. This approach will allow you to run your project disconnected from a computer, and will provide for non-volatile storage of large amounts of data.

Craig TraderCraig Trader
$endgroup$

Arduino Serial Output Clear

$begingroup$

The program gobetwino will log sensor values from an Arduino to a text file or spreadsheet with minimal effort. It can also automate things on the computer, add timestamps (so you don't need to program them into the arduino), etc.

endolithendolith
21.1k18 gold badges97 silver badges160 bronze badges
$endgroup$$begingroup$

The simplest method is to use the Serial library and output to that. You can then capture the output to a text file using a terminal program. Hyperterminal is available on Windows, Teraterm on Linux and Z Term on OS X.

Melanie

CyberspiceCyberspice
$endgroup$Output$begingroup$

If you want to write sensor data directly to a file on your computer without having to copy and paste the output form the serial monitor window, then try reading the data stream directly from the serial port (which is what the serial monitor does anyway, I suspect). On mac/linux do something like:

God knows what's the equivalent on windows machines.

garageàtroisgarageàtrois
$endgroup$

Arduino Serial Output To Raspberry Pi

$begingroup$

You can create a python script to read the serial port and write the results into a text file:

Ulad KasachUlad Kasach
$endgroup$$begingroup$

I found easier and safer to use a Python script. I usually use this one based on the serial library. It's very common to use also the datetime module to add the timestamps:

G MG M
$endgroup$$begingroup$

Arduino Serial Output To Pc

The next step is to use either the ethernet shield or something like a WIZ810MJ board and internet enable your arduino. You can then write data to that and send it to say a web server to collate it. I do this in my vivarium temperature monitor.

CyberspiceCyberspice
$endgroup$

protected by KortukJan 12 '13 at 2:59

Arduino Serial Output To Csv

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged arduino or ask your own question.

Description

Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART), and some have several.

BoardUSB CDC nameSerial pinsSerial1 pinsSerial2 pinsSerial3 pins

Uno, Nano, Mini

0(RX), 1(TX)

Mega

0(RX), 1(TX)

19(RX), 18(TX)

17(RX), 16(TX)

15(RX), 14(TX)

Leonardo, Micro, Yún

Serial

0(RX), 1(TX)

Uno WiFi Rev.2

Connected to USB

0(RX), 1(TX)

Connected to NINA

MKR boards

Serial

13(RX), 14(TX)

Zero

SerialUSB (Native USB Port only)

Connected to Programming Port

0(RX), 1(TX)

Due

SerialUSB (Native USB Port only)

0(RX), 1(TX)

19(RX), 18(TX)

17(RX), 16(TX)

15(RX), 14(TX)

101

Serial

0(RX), 1(TX)

On Uno, Nano, Mini, and Mega, pins 0 and 1 are used for communication with the computer. Connecting anything to these pins can interfere with that communication, including causing failed uploads to the board.

Arduino Serial Output Binary

You can use the Arduino environment’s built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().

Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.

To use these extra serial ports to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.