The message logger visualizer writes message data to a file. The log to file visualizer writes all serial data to a file, regardless of how it is sent by your Arduino sketch.

The message logger gives your Arduino program more control over what data is written to the log file by storing only the data sent using the message library. You’ll get a cleaner log file containing only the data chosen by your Arduino sketch, uncluttered by other messages such as commands for plotting data. The message logger and message monitor visualizers use the same data format so you can both view and write message data to file from within MegunoLink. Use message channels with a message logger visualizer to support multiple, simultaneous log files containing different messages.

Message logging

The message logger visualizer writes serial data selected by your Arduino sketch to a file.

Creating a Message Logger

Select Message Logger

from the visualizer menu or toolbox to create a new visualizer to configure and write a message log file.

You can create multiple Message Logger visualizers to:

Drag the visualizer tab to organize the windows in your MegunoLink project.

Sending Arduino Data to a Message Logger

Use the Message class in our library to send data and commands from your Arduino sketch to a message logger visualizer. After installing the MegunoLink Arduino library:

  1. Add #include "MegunoLink.h" to the top of your Arduino sketch.
  2. Create a Message variable.
  3. Use methods such as Send, Begin and End to send data and commands to the message logger.

Examples for the message logger can be found in Library Examples &rdarr; MegunoLink &rdarr; MessageLogger in MegunoLink. Each example includes an Arduino code file and a MegunoLink project file. The examples include:

  • SendCSVData: write comma separate values to a log file.
  • LogToFiles: uses a serial command to start an experiment that writes 10 measurements to each of 5 separate files.

Send CSV Data Example

The SendCSVData example demonstrates sending comma separated values to a Message Monitor or Message Logger. The values are separated from the main serial stream making it easier to load them into another program, such as Microsoft Excel.

Log To Files Example

The LogToFiles example demonstrates using the Message Logger to log measurements from the Arduino’s analog input. The program uses a serial command to start an experiment that writes 10 measurements to each of 5 files. The Arduino program sends the data to a Message Logger controlling the log filename.

This example can be found under MegunoLink Examples⇒Message Logger⇒LogToFiles. It includes a companion MegunoLink project that stores the log files in the My Documents\LogToFile\[Date]\ folder.

User Interface

The message logger user interface provides controls to choose the log file path start and stop logging, add time-stamps to the lines as they are written.

message logger user interface

Mange message data logging using the message logger visualizer.

Visualizer Toolbar

Tool Description
Connect/disconnect button Connect/disconnect the selected connection. Use the drop-down to select the connection used by this visualizer.
Channel selector Select the channels processed by the visualizer (message logger only).
Insert time Open the drop-down menu to control date and time-stamping new lines appended to the log file.
Delete log file Delete the log file (only available when not writing to the log file).
Write file Enable/disable writing the log file. Open the drop-down menu to enable/disable logging automatically when the connection is opened. A red + is displayed on the toolbar button whenever content is written to the file.
Help Open online documentation for the visualizer.

Log File Path

The log file path is resolved automatically each time the log file is opened. It can reference well known locations, such as your documents, Dropbox or MegunoLink project path, include the date and/or time, and be changed from your Arduino sketch.

Click the Configure log path button to open the dialog to view and configure the log file path.

Log file path UI
Configure Log Path

Use the Configure Log Path dialog to build a composite path for writing log files.

The log filename can be set from your Arduino sketch using the Message class in our Arduino library. Use the LogTo method to set the filename and start logging. The filename sent from your Arduino sketch is combined with the base path and folder set in MegunoLink to determine the log file path.

Allow serial commands to set filename and Allow serial commands to start and stop logging must be turned on in the log file path dialog for your Arduino sketch to control logging.

Starting and Stopping Logging

To start logging in MegunoLink, check the Enable logging command on the visualizer toolbar. To stop logging uncheck the Enable logging command.

Start and stop logging

Logging can be started and stopped from your Arduino sketch using the Message class in our Arduino library. Use the StartLogging and StopLogging methods.

Allow serial commands to start and stop logging must be turned on in the log file path dialog for your Arduino sketch to control logging.

MegunoLink can also start logging automatically whenever a connection is opened. Simply check the Start logging automatically when connection is opened menu item. This can be combined with the Restore on Load option in the Connection Manager to open a connection and automatically start logging when the MegunoLink project is opened.

Adding Time/Date to Log

The time and/or date can automatically be added to the log file by selecting one or both of the options on the time-stamp menu.

When enabled, the current date and time are written to the start of each line in the log file.

Time stamp menu
Select an option from the time-stamp drop-down to add the current time and/or date to each line of data written to the log file.

More Information

Leave a Comment

Start typing and press Enter to search