Shop OBEX P1 Docs P2 Docs Learn Events
Rookie question but got me stumped — Parallax Forums

Rookie question but got me stumped

Hello

I am recording positional data from 2 encoders using 'Quadrature_Encoder' into a pair of counters. I then store these into variables at defined increments.

long counters[2]
long thetaData[3510]
long zData[3510]

following this I need to write the data to a csv file on a USB stick.

All of this I have working but when the data is either being written to ram or written to USB (not sure which) there is a problem. If the value decrements in the number of digits, the previous value is not overwritten and is being included in the new data.

This is an example of the data being captured.
the first set shows the second value is rising from -2658 to 4489

2058002,-2658
2061003,-1539
2064003,-281
2067005,970
2070004,2170
2073003,3265
2076002,4489

now in the data on the USB you can see the value is there but extra digits are being 'carried' down from previous readings.

2058002,-265846
2061003,-153946
2064003,-281946
2067005,9701946
2070004,2170946
2073003,3265946
2076002,4489946

This is my code to write the USB file. This was not easy to get working at all on a VDrive2!


repeat while writeCount < dataCount

longfill (@thetaSTR, $20, 1)
thetaTemp := thetaData[writeCount]
thetaSTR := decstrT(thetaTemp)
pen.write(thetaSTR)
delay(50)

pen.write(delimiter)
delay(50)

longfill (@zSTR, $20, 1)
zTemp := zData[writeCount]
zSTR := decstrZ(zTemp)
pen.writeLine(zSTR)
delay(50)

'pen.write($0A)

com6.dec(writeCount)
com6.str(delimiter)
delay(50)
writeCount := writeCount +1

You can see my last attempt to fix this by using a longfill, I also tried it on thetaTemp and zTemp but it does not work.

I'm sure this is an easy and common problem but I can't figure it out.


Thanks for looking
Andy

Comments

  • BeanBean Posts: 8,129
    edited 2015-09-25 12:37
    It looks like you are only filling the first four bytes (1 long) of the string.
    I think you want bytefill(@zSTR, 0, zSTRLEN) ' change zSTRLEN to the size of the string variable

    A zero byte indicates the end of a string.

    Bean
  • I once used the Vinculum devices for USB stick easy access to get data in and out of a PC or Mac from the Prop. For many years now on the forum, the default storage preference for the Prop has largely been SD card. There are a few really good objects available. Once you switch over to SD from the USB stick, it really feels much less like work. I spent a ton of hours on the Vdrive2 system, and yes you can use if for sure but getting up to speed seems like far more work compared to the SD. There are SD card readers for USB connection so there is no less convenience factor. It would benefit you to find a Ascii/hex/decimal chart so you can understand what "46" is in Ascii. Those are not random numbers you are seeing.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-09-28 15:52
    After you compile your program you can archive it.

    File\Archive"ProgramName"\Project...

    This will generate a .zip file with all the objects used. If you post this archive, it will be easier for us to look at your code.

    The "C" icon in the text editor will made code entered in your post easier to read. Just paste your code between the code tags the button generates.

    Like T Chap, I used to use USB sticks but prefer SD cards now.

    I have a couple of links to uSD sockets in this post:

    http://forums.parallax.com/discussion/comment/1331441/#Comment_1331441

    As Bean points out, you want to fill your string with zeros rather than spaces. I think you likely have other string handling issues. I can't think of how this line of code could possibly work as I think you expect.

    zSTR := decstrZ(zTemp)
    

    If "zSTR" is a buffer to hold strings, a call like this couldn't work for strings longer than four bytes (as Bean suggested). (Edit: "zSTR" isn't a buffer, it's a pointer. The buffer resides in the VAR section of the object "Numbers".)

    BTW, if you use the "Quote button, you can see the code tags I used above.

    If you decide to use a SD card, I wrote a small demo program showing how to write variables to a card. It's attached to this post:

    http://forums.parallax.com/discussion/comment/1094393/#Comment_1094393

    Edit: I just looked over the object "Numbers" in the Propeller Tool's library. I was incorrect in some of my statements.
  • Some great advice here, I am pretty new to this area so sometimes it all seems like a struggle.

    The VDrive2 is an absolute pain and took many hours experimenting to get it to work. Changing my data to a string is the only way I can get the damn thing to write it onto the stick. It seems to only accept strings for the write command so I took the 'decstr' routine from Simple_Numbers to convert my decimal value into a string. I have 2 of these working on separate values as I wondered if it would help my problem, I can probably just use one. The value will never reach more than 8 digits so I thought my string capacity was ok.

    I also realised it would be easier working with SD but the customer wants USB so that's what we need to provide :(

    I tried changing the code to
    bytefill (@thetaSTR, 0, 8)
    
    but it was not the problem. I had to try before reply to the posts and I realised where the problem was. As I mentioned I took the destr routine frome simple numbers, it uses a temporary variable to store each converted character, it was this variable holding the unwanted data, as it is a long I used longfill to cure it and it works.

    Now I need to get serial coms working between the propeller and a 4DSystems uLCD-43PT so we have a front end. Happy days.


    Andy



  • One more thought...

    I fully realise that despite your best intentions I did not provide enough information for you to find where the problem was. Live and learn, in future I shall try to include as much info as possible if I want help.

    Thank you
Sign In or Register to comment.