MegunoLink includes two logging visualizers:

  1. Log to File: all data received on the serial connection is written to the file,
  2. Message Logger: data sent using matching message commands are written to the file.

The Log to File visualizer is useful for capturing all of the data sent from your Arduino program. The Message Logger gives your Arduino program more control over what data is written to the log file.

Create a new visualizer by selecting Log to File or Message Logger from the Visualizers menu.


Log to File

The Log to File writes all the serial data received into a log file.

Log File Path

Select the path where MegunoLink should write the log file using the Configure Log Path dialog box. Click the Save button in the visualizer window to open the Configure Log File dialog.

Log file path UI

The log file path is made up of 3 parts:

  1. Base Folder
  2. Folder
  3. Filename
Configure Log Path

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

This lets you select a path that will work even if you use the MegunoLink project on computers that use a different file system layout. The key to these flexible paths is the base folder.

The Base Folder resolves to the actual path of the selected folder when the log file is created. You can choose from:

  • None: Treat the Folder as an absolute path. The base folder is ignored.
  • Project: The log file is saved under the same folder as the MegunoLink project file.
  • Dropbox Folder: The log file is saved under the user’s Dropbox folder.
  • Dropbox Personal Folder: The log file is saved under the user’s personal Dropbox folder.
  • Dropbox Business Folder: The log file is saved under the user’s business Dropbox folder.
  • My Documents: The log file is saved under the user’s documents folder.
  • Desktop: The log file is saved under the user’s Desktop folder.

The Folder is appended to the base folder, allowing you to select a folder inside the base folder. Use the drop-down menu to include the date and/or time in the folder name.

The Filename sets the log files name. Use the drop-down menu to include the date and/or time in the filename.

Use the Test button to combine all the parts of the log file name to see where the log file will be saved.

Commands sent by your Arduino program to a Message Logger visualizer can control logging. Your Arduino program can start and stop logging if the Allow serial commands to start and stop logging is checked. If Allow serial commands to set filename is checked your Arduino program can change the filename of the log file. Note: commands only apply to the Message Logger visualizer, not to the Log to File visualizer.

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

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.

If you are using the Message Logger you can also start and stop logging from your Arduino program. Ensure the Allow serial commands to start and stop logging option is checked in the Configure Log Path dialog. Then call the MessageLogger::StartLogging(); or MessageLogger::StopLogging(); commands. For example:

Adding Time/Date to Log

The time and/or date when each line of data is received can be added to the log file by selecting the corresponding options from the time-stamp menu on the visualizer’s toolbar.

Add the time or date to your log file

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.

Message Logger

The message logger picks out specially formatted messages from the serial data and writes them to a log file.

By using a message logger, your Arduino program can select which data should be written to the log file. You’ll get a cleaner log containing only the data you need. It won’t get cluttered by other messages like commands for plotting data.

The Message Logger supports MegunoLink’s channel tags. If you want to log only a single channel of messages then choose the channel before enabling the logger.

Sending to the Message Logger

The Message Monitor Arduino Library provides a convenient set of methods for sending data to the Message Logger visualizer. The same library works for the Message Monitor visualizer so you can use the Message Monitor to observe the logged events and the Message Logger to create a permanent record.

In addition to the commands shown in the Message Monitor Library Reference, the Message Logger supports additional commands to control logging:

  • LogTo(Filename)
  • StartLogging()
  • StopLogging()

Message Logger Reference

See also: Message Monitor Library Reference.

LogTo(Filename)
Changes the log filename to Filename and begins logging. The Filename is combined with the Base Folder and Folder to create a path where the log file will be written.

The LogTo command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging and the Allow serial commands to set filename options are enabled in the Configure Log Path dialog.

StartLogging()
Sends a command to start the Message Logger writing serial messages to the log file.

The StartLogging command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging option is enabled in the Configure Log Path dialog.

StopLogging()
Sends a command to stop the Message Logger writing serial messages to the log file.

The StopLogging command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging option is enabled in the Configure Log Path dialog.

Arduino Examples

Examples for the Message Logger can be found in Library Examples⇒MegunoLink⇒MessageLogger in MegunoLink. Each example includes an Arduino code file and a MegunoLink project file. The examples include:

  • SendCSVData: Write comma separated 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.

Start typing and press Enter to search