Shop OBEX P1 Docs P2 Docs Learn Events
Get data from Notepad into Propeller - Page 3 — Parallax Forums

Get data from Notepad into Propeller

13

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-08-18 13:09
    idbruce wrote: »
    Great :( Now I have to read everything all over again to understand just exactly what you accomplished.

    I just went back on found Bean's post.

    Phil's post shows how to implement Bean's idea.

    This forum is great. I learn a lot use information here.

    Duane
  • idbruceidbruce Posts: 6,197
    edited 2011-08-18 13:19
    This forum is great. I learn a lot use information here.

    Yea, yea, yea.... Just let me know if my code works. :)

    http://forums.parallax.com/showthread.php?133885-Get-data-from-Notepad-into-Propeller&p=1028349&viewfull=1#post1028349
  • $WMc%$WMc% Posts: 1,884
    edited 2011-08-18 19:44
    zpua:
    '
    Have you figured this out yet?
    '
    Its pretty simple with the PST.
    '
    P.S. there is a difference between a single phone # and a Tampa phone book listing.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-08-18 20:28
    $WMc% wrote:
    Its pretty simple with the PST.
    It is? If you're talking cut-and-paste, my experience with PST runs contrary even to "possible", let alone "simple."

    -Phil
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-08-18 22:07
  • zpuazpua Posts: 33
    edited 2011-08-19 07:42
    Bruce,
    May I know what does this line code trying to do?

    DataValueOne := DataValueOne * 10 + (DataFileCharacter[0] - "0")

    And is DataFileCharacter[0] is being sent into propeller?

    Thank you.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 07:59
    @zpua
    May I know what does this line code trying to do?

    DataValueOne := DataValueOne * 10 + (DataFileCharacter[0] - "0")

    It has actually been a while since I wrote that formula, but I will do my best to explain it.

    Let's say that the file DataFile.dat contains the number 1234 and that DataValueOne initially has a value of 0.

    During the first iteration of the REPEAT loop DataFileCharacter[0] will contain the number 1 from the value of 1234.

    So it would be something like this:
    DataValueOne := 0(DataValueOne's initial value) * 10 + 1(character within DataFileCharacter[0]) - "0" (NULL terminating character)
    DataValueOne := 0 * 10 + (1 - "0")
    During the second iteration of the REPEAT loop DataFileCharacter[0] will contain the number 2 from the value of 1234 and DataValueOne will be equal to 1.

    So it would be something like this:
    DataValueOne := 1(DataValueOne's value form first iteration) * 10 + 2(character within DataFileCharacter[0]) - "0" (NULL terminating character)
    DataValueOne := 1 * 10 + (2 - "0")
    So on and so forth until the value equals 1234
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 08:11
    Since DataFile.dat is compiled, the program is stored in EEPROM (memory). Upon boot, the program is loaded, so in reality, at that point, it is already in the Propeller, but it has not been read by your program. The code below, providing that it works properly, will read DataFile.dat and fill DataFileCharacter[0] which can in turn be used by your program.
  • zpuazpua Posts: 33
    edited 2011-08-19 09:43
    Bruce,

    I understand what you trying to say. The code is running, but my PST still show nothing. What if I have 0.1234 in my notepad? Any changes needed on the code?
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 10:06
    zpua
    The code is running, but my PST still show nothing.

    Like I previously mentioned, I have no way of testing it. I am sure it is something simple. I don't believe that FullDuplexSerial defines the constant CLS, so eliminate the following line:
    Debug.Tx(Debug#CLS)
    
    Yes, that decimal point is unaccounted for in the code I provided.

    DataFile.dat should contain nothing but numbers upto 2147483647

    Make sure the baud rate within the serial terminal is 115200 or alter the source code accordingly to match the baud rate you are using.
    CON
     
      _CLKMODE      = XTAL1 + PLL16X
      _XINFREQ      = 5_000_000
     
    DAT
     
      Data          FILE      "DataFile.dat"
      Str byte 0 'If this file is not NULL terminated, we need to add a 0
     
    OBJ
     
      Debug:"FullDuplexSerial"
     
    VAR
     
      LONG DataValueOne
      BYTE DataFileCharacter[1]
     
    PUB GetDataAndCompare | Index, ComparisonValue
     
      ComparisonValue := 2_147_483_647 'Maximum value for LONG type declarations
     
      Debug.Start(31, 30, 0, 115_200)
      WAITCNT(CLKFREQ * 2 + CNT)
     
      Index := 0
     
      REPEAT
     
        DataFileCharacter[0] := BYTE[Data][Index++]  'This is an individual character
     
        DataValueOne := DataValueOne * 10 + (DataFileCharacter[0] - "0") 
     
      WHILE Temp > 0
     
      Debug.Dec(ComparisonValue)
      Debug.Tx(13) {Carriage Return} 
      Debug.Dec(DataValueOne)
      Debug.Tx(13) {Carriage Return}
     
      IF DataValueOne == ComparisonValue
     
        Debug.Str(STRING("These values are equal"))
     
      ELSE
     
        Debug.Str(STRING("These values are unequal"))
    
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 10:28
    zpua

    Additionally, the following line should be changed from:
    WHILE Temp > 0
    

    to:
    WHILE DataFileCharacter[0] > 0
    
  • zpuazpua Posts: 33
    edited 2011-08-19 10:40
    Bruce,

    Attached file is my data and what I got in my Serial Terminal. It seems odd to me. Thanks
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 10:42
    I can't open that file
  • zpuazpua Posts: 33
    edited 2011-08-19 11:14
    What about this file?
    1016 x 634 - 54K
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 11:19
    Does DataFile.dat contain the number 602?
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 11:23
    I should have been more specific, the code only has support for one number upto 2147483647 to be contained within DataFile.dat.
  • zpuazpua Posts: 33
    edited 2011-08-19 11:29
    All of my data in DataFile.dat are in decimal points. Should I need to put in floating point in the code?
    My data does not consist 602. So I am not really sure why is it displaying 502.
  • zpuazpua Posts: 33
    edited 2011-08-19 11:31
    Looping need to be added in order to support more than one number?
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 11:34
    zpua

    Like I said, you must start with the basics, you are trying to dive right in. First put one number(without decimals) in the file to see if the code works properly. 2147483647 would be a good number, because if they come out equal, you know the code is working 100%.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 11:43
    My sample code will have to be modified to:
    1. Support more than one number in DataFile.dat
    2. Support decimal points
    Hopefully I have provided you with a good starting point.
  • zpuazpua Posts: 33
    edited 2011-08-19 12:03
    Bruce,
    I changed to only 2147483647 in my DataFile but it displayed:

    2147483647
    1623048008
    These values are unequal

    Yeah, it's a good starting for me. Thanks a lot.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 14:15
    zpua

    I have not figured it out completely just yet, but I got it working to a certain extent. It is putting correct ASCII values. I will get back to you.
  • zpuazpua Posts: 33
    edited 2011-08-19 14:21
    Thanks Bruce.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 15:13
    zpua

    The following code will work perfectly. However, there is an easier way to do this, but to be perfectly honest, I forget how it is done. Of course this is just an example of using the FILE directive. I hope this helps.

    Bruce
    CON
     
      _CLKMODE      = XTAL1 + PLL16X
      _XINFREQ      = 5_000_000
     
    DAT
     
      Data          FILE      "DataFile.dat"
      Str BYTE 0 'If this file is not NULL terminated, we need to add a 0
     
    OBJ
     
      Debug:"FullDuplexSerial"
     
    VAR
     
      LONG DataValueOne
      BYTE DataFileCharacter[1]
     
    PUB GetDataAndCompare | Index, ComparisonValue
     
      ComparisonValue := 2_147_483_647 'Maximum value for LONG type declarations
     
      Debug.Start(31, 30, 0, 115_200)
      WAITCNT(CLKFREQ * 2 + CNT)
     
      Index := 0
      DataValueOne := 0   
       
      REPEAT
     
        DataFileCharacter[0] := Data[Index++]  'This is an individual character
     
        IF DataFileCharacter[0] == 48 '0 Character
          DataValueOne := (DataValueOne * 10) + 0
          
        IF DataFileCharacter[0] == 49 '1 Character
          DataValueOne := (DataValueOne * 10) + 1
          
        IF DataFileCharacter[0] == 50 '2 Character
          DataValueOne := (DataValueOne * 10) + 2
          
        IF DataFileCharacter[0] == 51 '3 Character
          DataValueOne := (DataValueOne * 10) + 3
          
        IF DataFileCharacter[0] == 52 '4 Character
          DataValueOne := (DataValueOne * 10) + 4
          
        IF DataFileCharacter[0] == 53 '5 Character
          DataValueOne := (DataValueOne * 10) + 5
          
        IF DataFileCharacter[0] == 54 '6 Character
          DataValueOne := (DataValueOne * 10) + 6
          
        IF DataFileCharacter[0] == 55 '7 Character
          DataValueOne := (DataValueOne * 10) + 7
          
        IF DataFileCharacter[0] == 56 '8 Character
          DataValueOne := (DataValueOne * 10) + 8
          
        IF DataFileCharacter[0] == 57 '9 Character
          DataValueOne := (DataValueOne * 10) + 9
     
      WHILE DataFileCharacter > 0
     
      Debug.Dec(ComparisonValue)
      Debug.Tx(13) {Carriage Return} 
      Debug.Dec(DataValueOne)
      Debug.Tx(13) {Carriage Return}
     
      IF DataValueOne == ComparisonValue
     
        Debug.Str(STRING("These values are equal"))
     
      ELSE
     
        Debug.Str(STRING("These values are unequal"))
    
    
  • PliersPliers Posts: 280
    edited 2011-08-19 18:24
    Here is a spin file and a visual basic file that will communicate with each other.
    I used an LED on the Demo board to indicate data value matches. The visual basic window is used to send data and to receive data from the demo board. These are very simple files, only a few lines long.

    I hoped the visual basic would demonstrate the possibilities for communication between a PC and the demo board.
    Having Visual Basic read files (text) off you hard drive and send it out the serial port is not to difficult.

    I don't know about using floating point decimals in the propeller.I do every thing with integers.
    I'm afraid that the Visual Basic files will not run on your machine.
    I don't know how to share VB projects. Perhaps Bruce can shed some light on this.
    It was easy as opening an existing project, I just needed to find the right file.


    I did include the setup file that will install the communications program on your system. You will find it in the publish folder.

    The previously Zipped folder was missing the SPIN code.
    Propeller to Visual Basic.zip
  • idbruceidbruce Posts: 6,197
    edited 2011-08-20 05:15
    zpua and all other interested parties

    This post contains an attached working example of the FILE directive. Additionally, this example is better than my previous post, because the REPEAT loop utilizes the NEXT command for faster iterations.

    In the attachment below, DataFile.dat contains a single whole number which is 2147483647. During execution, the Propeller will compare the value of the number uploaded in DataFile.dat to that of a local variable in the Spin code, being the ComparisonValue, which is also 2147483647.

    Bruce
  • zpuazpua Posts: 33
    edited 2011-08-20 08:59
    Bruce,

    Did you get the working example run perfectly? I have not yet. I am not sure why. May I know what is number 48, 49, 50 and so on doing?

    Thank you.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-20 09:06
    Zpua

    Yes, that latest example should work perfectly.
    • 48 is the ASCII value for the 0 character
    • 49 is the ASCII value for the 1 character
    • 50 is the ASCII value for the 2 character
    • 51 is the ASCII value for the 3 character
    • 52 is the ASCII value for the 4 character
    • 53 is the ASCII value for the 5 character
    • 54 is the ASCII value for the 6 character
    • 55 is the ASCII value for the 7 character
    • 56 is the ASCII value for the 8 character
    • 57 is the ASCII value for the 9 character
  • idbruceidbruce Posts: 6,197
    edited 2011-08-20 09:32
    zpua
    Did you get the working example run perfectly? I have not yet.

    The example assumes a baud rate of 115200. You may have to adjust the baud rate in the example, the Parallax Serial Terminal, or port settings. Additionally, you may have to specify the proper port.
  • Zap-oZap-o Posts: 452
    edited 2011-08-20 09:54
    After all my pontificating, I decided I'd better try it myself. 'Turns out, it's not as easy as I thought it would be. The problem is that, even with handshaking turned off, the printer driver toggles DTR, which resets the Propeller. Unfortunately, I know of no way around this problem.

    -Phil

    Place a switch or button between the propeller and the DTR line. This way you can program the prop by holding down the button. It works great.
Sign In or Register to comment.