I've come to using PuTTy to capture Arduino's serial data to a log file, and then I have a data connection from Excel to that log file for plotting.
(I am reading an analog voltage and printing "millis, value" to serial every 200 ms, it's a very simple program that works great for what I want)
Two problems:
The voltage I want to measure is likely to range between 25V to 45V. I thought of using a 10k potentiometer to create a voltage divider, but then I lose one bit of resolution (that would map to about 2.2V to 5V). I could ignore this, but it would be good to have the resolution, and I also wonder if there is a better range for the adc, such as 1V to 4V rather than say 2V to 5V?
Ever so often, there is a data glitch, it looks like the data in a cell gets truncated or shifted one cell to the right. I suspect this might be Excel accessing the log file (via auto refresh every 1 min) the same time as PuTTy and interrupting the communication to the log file. I could manually clean the data later or just access the log file after the test is complete, but it is nice to see the data plot update periodically.
I had initially hoped for a more direct path into Excel from the com port serial stream and have a more live update. Here are a couple VBA scripts I tried that would work once out of a thousand times or just capture some garbage or nothing. I gave up on them after days of hacking away at found code, but I post them for amusement.
Sub Send_and_Read()
'this one seemed to work when sending a "plain string, and sometime when casing a static integer variable cast as a string(intVar), for example...
'--------------------------------------------------------
cmnd$ = "Hello World" 'A string to send
Dim i As Integer
Dim timeout As Date
i = 1
'--------------------------------------------------------
timeout = Now + TimeValue("00:00:20")
Open "COM5" For Binary Access Read Write As #5
cmnd$ = cmnd$ + Chr(13) 'add [CR] to command string
'Put #1, , cmnd$ 'write string to interface
'--------------------------------------------------------
While Now < timeout
answer = "" 'clear response string
char = Input(3, #5) 'get first character
While (char <> Chr(13)) 'loop until [CR]
If (char > Chr(47) And char < Chr(58)) Then 'was chr 31
answer = answer + char 'add, if printable char
Else
' Do what ever you like
End If
char = Input(255, #5) 'get the next character
Wend
'--------------------------------------------------------
'Cells(1, 1) = answer 'put response in cell("A1")
Cell = "B" & i
Range(Cell).Value = Now
Cell = "C" & i
Range(Cell).Value = answer
i = i + 1
Application.Wait (Now + TimeValue("0:00:01"))
Wend
Close #5
End Sub
Public Sub Receive_COM5()
'This one seemed more reliable in capturing data, but was often 0 or 224.
Dim timeout As Date
Dim byte1 As Byte, chars As String, lineEnding As String
Dim comPORT As Integer
Dim i As Integer
comPORT = 5
i = 1
'Define line ending character(s)
'lineEnding = vbCrLf
lineEnding = vbCr
'Monitor COM port for 30 seconds
timeout = Now + TimeValue("00:00:10")
Close comPORT
'Open COM5 port with baud rate 9600, No parity, 8 data bits, and 1 stop bit.
'These are the default port settings in HyperTerminal.
'In HyperTerminal, use Flow control = None.
'Open "COM5:9600,N,8,1" For Random As #5 Len = 3
Open "COM5:9600,N,8,1" For Binary Access Read Write As #5
chars = ""
While Now < timeout
'Get 1 byte
Get #comPORT, , byte1
Debug.Print Now; IIf(Chr(byte1) < " ", "<" & byte1 & ">", Chr(byte1))
chars = chars & Chr(byte1)
Cell = "C" & i
Range(Cell).Value = chars
i = i + 1
Application.Wait (Now + TimeValue("0:00:01"))
If Right(chars, Len(lineEnding)) = lineEnding Then
'Debug.Print "Line:" & Left(chars, Len(chars) - Len(lineEnding))
chars = ""
End If
DoEvents
Wend
Close #comPORT
End Sub