Shop OBEX P1 Docs P2 Docs Learn Events
How to send data from Microsoft Excel into propeller cog — Parallax Forums

How to send data from Microsoft Excel into propeller cog

zpuazpua Posts: 33
edited 2011-08-15 12:12 in Propeller 1
Hello,

I would like to pass data from microsoft excel into propeller and put them in array form.

The reason I want to do this is because I want to compare get a difference between my data in Excel
and data in propeller cog in array form.

According to the advice from experts, I could do it through MicroSD card or activate the visual basic program that built into the Excel. Since I am not able to insert a SD card into my propeller demo board, so I think VBA is the only way for me to do so.

Can anyone gives me some ideas on how can I get this project work?

Thank you.
«1

Comments

  • localrogerlocalroger Posts: 3,452
    edited 2011-08-12 09:45
    The simplest way I can think of to do this would be:

    1. Save the data from Excel to a .csv format file, or copy it from the spreadsheet, paste it into Notepad, and save it as text which will be tab delimited.
    2. Write a Spin program to receive the incoming text with FullDuplexSerial and parse it into an array.
    3. Open the download cable port (the PropTool tells you which COM port it is emulating) with Hyperterminal and use Transfer -- Send Text file to transmit it over the "serial" port.

    The two hardest keys to this for a newbie will be learning to control fullduplexserial to send and receive data, and parsing the incoming data since there are no native Spin functions to take, say, the characters 4, 1, and 9 and assemble them into the decimal value 419 -- you have to do it yourself. It's not hard, but does require knowing Spin pretty well.
  • zpuazpua Posts: 33
    edited 2011-08-12 10:45
    Hi localroger,

    Thanks for you comments. I have saved my 100 data in Notepad as tab delimited format.

    Do you have any example spin code that will receive the incoming text and parse them into array form that I can review on it?

    Thank you.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 10:57
    Zpua

    Can you be more specific?

    How often will the data in the excel file change?

    How often will the Propeller data change?

    When you compare the data, what are you comparing? Adding? Subtracting?

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:05
    Zpua

    I believe it would be easier to use FullDuplexSerial to send Propeller data to the terminal, and use Windows functions in C++ to get your data and arrange it the way you want it. And then parse it against a csv file.

    Bruce
  • zpuazpua Posts: 33
    edited 2011-08-12 11:06
    Bruce,

    Let say I have 100 data in Excel and 100 data running in propeller,once propeller get data from excel, I want both data in array form get a differences such as:

    REPEAT I from 0 to 100
    Array3:=Array2-Array1

    Does it making any sense?

    zpua
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:14
    Is it absolutely imperative that the data comes from Excel? Are the arrays always a fixed number of elements?

    If the first answer is no, and the second answer is yes, then all you need is a small C++ dialog box program to enter values to compare against the Propeller data.

    I would imagine you could even send new data from this dialog box program to the serial terminal, which in turn would send it to the propeller to act upon it.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:21
    In fact, I am fairly certain that a dialog box program could accomplish the same tasks as FullDuplexSerial, therefore eliminating it completely.

    Bruce
  • zpuazpua Posts: 33
    edited 2011-08-12 11:24
    The data and number of elements are fixed.

    I don't understand what you mean by having a small c++ dialog box program, is it another programming tool that I have to use?

    Can I get the data in csv format by using only spin code?

    zpua
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:24
    But of course, my conclusions would require you to have some knowledge of C++
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:26
    Can I get the data in csv format by using only spin code?

    The quick answer is yes, but how often will this csv file need to be changed?
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:28
    Research the FILE directive within the Propeller Manual Ver.1.0, pg. 215
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:31
    It all depends upon how, where, and when you want your data.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 11:37
    Maybe this will help you. It is an example of passing a file to the propeller and the propeller parses the values. This example uses the FILE directive.
  • RaymanRayman Posts: 14,876
    edited 2011-08-12 12:05
    If you did want to do it directly from Excel, I'd try using something like this on the PC side:

    http://dev.emcelettronica.com/serial-port-communication-excel-vba

    and just fullduplexserial on the Prop...
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 12:05
    Zpua

    Are you comparing the data within the Propeller chip?

    OR

    Are you comparing the data within Excel?
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 12:12
    Rayman

    It almost sounds like he does not need FullDuplexSerial with the information you provided.

    Bruce

    PS Good find
  • zpuazpua Posts: 33
    edited 2011-08-12 12:26
    Hello,

    I would like to compare the data within the propeller chip.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-08-12 12:30
    It's a simple copy-and-paste operation. Format your data in Excel like this:

    attachment.php?attachmentid=83977&d=1313177332

    Then, just select the first three columns, do a copy, and paste the data into your DAT section:
    DAT
    
    mydata  long    1000
            long    1567
            long    2134
            long    2701
            long    3268
            long    3835
            long    4402
            long    4969
            long    5536
            long    6103
            long    6670
            long    7237
            long    7804
            long    8371
            long    8938
            long    9505
            long    10072
            long    10639
            long    11206
            long    11773
            long    12340
            long    12907
            long    13474
            long    14041
            long    14608
            long    15175
            long    15742
            long    16309
            long    16876
            long    17443
    
    The paste operation will put tabs between the column data so it formats okay for the compiler.

    -Phil
    263 x 576 - 8K
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 12:47
    @Phil

    That could be a real blessing or a real pain depending on his true needs. However, your method is probably the easiest for a newbie. But if his data is horizontal as compared to vertical, then perhaps a csv file, a parsing routine, and the FILE directive might be a better solution.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 13:03
  • zpuazpua Posts: 33
    edited 2011-08-12 13:21
    Hello Phil,

    I still have some confusion. If I do what you taught, do I still need to edit the visual basic code in Excel?

    Bruce,

    My data is in vertical form, but I would like to learn FILE directive method as well.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-08-12 13:35
    zpua: Firstly, welcome to this fantastic prop forum.

    Phil's example is by far the easiest. Of course it uses fixed data and will need a recompile and reload of the program into the prop each time the data changes. However, this is probably no different to the complexity of using a serial object (such as FullDuplexSerial) to receive the file each time, and saves a lot of programming.

    Here is an alternative, but of course is a lot more complex...
    In excel, format your data as fixed length, then save as a tab delimited file (or if you are proficient in VB, you can use VBA to output straight to the comm port and into the propeller). Use FullDuplexSerial on the prop to receive the data. Provided you use fixed lengths, you should be able to parse the data quite simply in spin, and store the data arrays.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-12 13:38
    I guess we have to clear up more details.

    Most important question is: do the values change all the time or are they constant (or at least constant for three months)?

    If the values change often, it makes sence that Excel sends the values to the propeller through a serial connection.

    If the values are constant Phi-Pi's suggestion is good.
    Anyway please give the forum an overview about your project. Make your description rich with a lot of details.
    Posting it short does only produce new questions, wrong assumptions and inapropriate suggestions.

    keep the questions coming
    best regards

    Stefan
  • idbruceidbruce Posts: 6,197
    edited 2011-08-12 13:44
    I still have some confusion. If I do what you taught, do I still need to edit the visual basic code in Excel?

    To expedite the answer, the answer is no.
  • zpuazpua Posts: 33
    edited 2011-08-12 14:42
    Hi all,

    Thanks for the feedback. Here is an overview of my project.
    Basically, I already have a set of data execute by propeller in spin generates sin(0) to sin(180) store in Array form.

    Now, I have a set of fixed data in Excel. It has the same number of elements of data in propeller. I do not intend to change the data in Excel in this practice. So I think Phil's suggestion might be easiest here, but I still do not know how can I assign them in array form in DAT.

    Once I get the data from excel in array form, I can get the difference between value in sine() executed by propeller and data from excel.

    I guess I could try VBA as well, it's all depend on which method make sense to me.

    Thank you.

    This is all about what I intend to do. Thank you.
  • agimuhingagimuhing Posts: 39
    edited 2011-08-12 15:04
    Parallax has an add on for Excel called PLX-DAQ (http://www.parallax.com/ProductInfo/Microcontrollers/PLXDAQDataAcquisitiontool/tabid/393/Default.aspx) that sends spreadsheet values directly to the prop.
    I don't think it sends data in array form, but arranging the data into an array can probably be done on the prop
  • localrogerlocalroger Posts: 3,452
    edited 2011-08-12 15:44
    If you have your data in a contiguous DAT block, you can treat them as an array by using a pointer to the first element (@NAME) and the LONG (or WORD, or BYTE according to the data width) operators:

    DAT
    MYVAL LONG 1,2,3,4

    PUB
    V=LONG[@MYVAL][3] 'V is set to 4
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-08-12 15:54
    zpua,

    As localroger points out, your data will already be in array form once you paste them into your DAT section, whether they be comma-separated or one datum per line. All you have to decide is whether you want bytes, words, or longs and set up the second column of your Excel form accordingly.

    -Phil
  • TappermanTapperman Posts: 319
    edited 2011-08-12 18:25
    agimuhing wrote: »
    Parallax has an add on for Excel

    I was wondering how long it take someone to mention that!

    ... Tim
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-12 22:53
    Hi zpua,

    it's up to you how many details you tell us. I don't think that calculating sinus and cosinus values are a selfpurpose. You are doing something with them.

    So to give a real overview about your project is answering the question what are you doing in the end?

    By the way: The propeller-chip has inbuild sinus and cosinus tables in the ROM. And there are objects in the obex how to access these sin-cos-values.
    If your project somehow does trigonometric calculations this will be very useful.

    And again this is an example how giving an overview and giving details opens up for new and better suiting solutions

    keep the questions coming
    best regards

    Stefan
Sign In or Register to comment.