Last Modified: November 28, 2016, at 010:16 AM
By: dndubins
Platforms: Microsoft Excel 2010 (Mac and PC versions)
Although 3rd party applications and plugins are available for port logging, it is possible to log data directly into Microsoft Excel through Visual Basic.
Link to worksheet: http://individual.utoronto.ca/ddubins/GetCSV.xlsm
There are no lack of applications tailored towards saving a .CSV file from an open port, which can then be imported into Microsoft Excel. For instance, GoBetwino, Processing, and Eltima Port Logger are useful and implementable strategies.
However, it is possible to have Visual Basic (underneath Excel) listen to the serial port and output the data directly into Excel without requiring another program or plugin to load - in both Mac and PC versions.
The first order of business is finding out the open port number, through the Arduino IDE. This is done by loading the Arduino IDE, connecting your device (e.g. Arduino Uno), then clicking on Tools --> Port.
Next, you will need to create a macro in Visual Basic to read the port. In Windows, the stripped down core routine looks like this:
Visual Basic connects directly to the COM port. This version of the macro only prints a message of the data, rather than the spreadsheet. However, going to the spreadsheet from this format is easier with commands like:
ActiveCell.Offset(1,0).Value = record_cat
For the Mac version of Excel, things are a little more complicated. The Open COMstring command won't work. However, Visual Basic allows for shell commands. One strategy then is to call the following command in a shell:
head -1 /dev/cu.yourcommunicationsportgoeshere
This gets the first line of your port from the terminal prompt. Then, since calling the head command will reset the serial connection each time, for the Uno it was necessary to connect a 10 uF capacitor between RST and GND.
Here is a stripped down version of the Visual Basic macro for Mac:
Setting a faster baud rate in the PC macro works well. However, I was unsuccessful in using a baud rate other than 9600bps with the Mac macro, even with the stty command in the terminal window.
The code is a bit clumsy, and could use optimizing. Also, if you plan on using this code, you can also have the program save the workbook every once in a while (e.g. every 10 readings?) with the command:
ActiveWorkbook.Save