View Full Version : Connect Excel to the Propeller

07-23-2009, 12:56 PM
Here's a simple excel function that will continually update an Excel cell with the value of a variable in a spin program running on a Propeller connected to ViewPort:


Here's some Excel macro code that does lot's of cool stuff:

Dim a, b, channel As Integer
Sub StartVP()
'Start DDE connection to ViewPort
channel = DDEInitiate("vp", "system")
'Connect ViewPort to Propeller
DDEExecute channel, "connect"
'Set cell to list of names of Propeller variables
ActiveSheet.Cells(5, 5).Value = DDERequest(channel, "list")
'Set cell to detail of variable "a"
ActiveSheet.Cells(3, 2).Value = DDERequest(channel, "detail(a)")
'Set servo variable to value of cell
DDEPoke channel, "servo", Sheets("Sheet1").Range("A1")
'Link servo variable to cell- when the cell changes, the variable on the Propeller will be updated
DDEExecute channel, "link(servo,excel|sheet1.xls!r1c1)]"
'Read temp variable into cell
ActiveSheet.Cells(4, 2).Value = DDERequest(channel, "temp")
'Continually update cell with value of "temp" variable from Propeller
ActiveSheet.Cells(6, 2).Value = "=vp|get!temp"
ActiveWorkbook.SetLinkOnData "vp|get!temp", "gotData"
'Start a trigger that fires when "temp" rises above 20. Then, return temp and time
ActiveSheet.Cells(7, 2).Value = "=vp|rise!temp_20_temp_time"
ActiveWorkbook.SetLinkOnData "vp|rise!temp_20_temp_time", "gotTrigger"
End Sub
Sub gotData()
'Data received, update cell
ActiveSheet.Cells(4, 5).Value = a
a = a + 1
End Sub
Sub gotTrigger()
'Trigger received, update cell
ActiveSheet.Cells(5, 5).Value = b
b = b + 1
End Sub
Sub StopVP()
'Stop getting trigger/value updates
ActiveSheet.Cells(6, 2).Value = ""
ActiveSheet.Cells(7, 2).Value = ""
'Disconnect Propeller and terminate DDE
DDEExecute channel, "disconnect"
DDETerminate channel
End Sub

Here's the list of DDE commands that any program that speaks DDE can use to communicate with ViewPort/Propeller:

dde.init("vp","system"): connects to ViewPort DDE server

dde.execute("connect"): connects to Propeller

dde.execute("disconnect"): disconnects Propeller- releases com port

dde.request("list"): returns a list of variables whose values can be read/written

dde.request("detail(var)"): returns information about a variable, for example,
detail("io") returns "io|array[400]|base 16"

dde.poke("var",value): sets a Propeller variable to a value, for example, poke(servo,1500)
sets the servo variable to a value of 1500.

dde.execute("link(var,ddecommand)"): links a Propeller variable to a DDE variable, for
example, link(servo,excel|sheet1.xls!r1c1) links the servo variable on the Propeller to the
contents of the top, left cell of sheet1.xls in Excel. When you change that cell in Excel, the
servo variable will change on your Propeller- potentially moving a servo.

dde.request(varlist): returns a list of comma separated values for the list of variables you
specified. For example, vp|get|temp_wind_time can return "20,15,8:05"

dde.StartAdvise(varlist): your dde client will be advised 10 times/second with a list of comma
separated values for the list of variables you specified. For example, a varlist of
vp|get|temp_wind_time will result in events with a parameter of "20,15,8:05"

dde.StartAdvise(trigger): sets a trigger. When the condition is valid, the trigger result is set
to the values of the variables in the varlist. For example, StartAdvise("rise!temp_20_temp_time")
will set up a new trigger that fires when the Propeller variable "temp" rises above 20. The
application will get notified with a comma-delimmeted string of values- for example, "21,90,8:05".

Mostly working here, will release to beta in a week. PM me if you're a ViewPort Ultimate user interested in testing with other applications.

Download (http://mydancebot.com) a free trial of ViewPort- the premier visual debugger for the Propeller
Includes full debugger, simulated instruments, fuzzy logic, and OpenCV for computer vision. Now a Parallax Product!