Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:48 18 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : SD Card

     Page 1 of 2    
Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 12:51pm 29 Oct 2015
Copy link to clipboard 
Print this post

From what I have read in the manual it is not possible to put a Data File on an SD card and READ from it. I have a project that has a large data file, a year of dates and associated values , that are READ off day by day. It would be handy if the end user could simply slot in a new card with an updated file when the current data runs out. Is it possible?
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 01:08pm 29 Oct 2015
Copy link to clipboard 
Print this post

  palcal said   From what I have read in the manual it is not possible to put a Data File on an SD card and READ from it. I have a project that has a large data file, a year of dates and associated values , that are READ off day by day. It would be handy if the end user could simply slot in a new card with an updated file when the current data runs out. Is it possible?
Paul.


Hi Paul,

what system, manual. Where exactly did you read that?

Michael
causality ≠ correlation ≠ coincidence
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 01:19pm 29 Oct 2015
Copy link to clipboard 
Print this post

  Quote  what system, manual. Where exactly did you read that?

In the Micromite Advanced Manual under SD card I can find no way to READ
from a DATA file. OR I don't understand, which is more likely.

Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 01:35pm 29 Oct 2015
Copy link to clipboard 
Print this post

  palcal said  
  Quote  what system, manual. Where exactly did you read that?

In the Micromite Advanced Manual under SD card I can find no way to READ
from a DATA file. OR I don't understand, which is more likely.

Paul.


Ok, seems it's about a MM+. I don't use a MM+ but I think it should be possible
, eg using open, input# etc.
From Micromite (plus) Advanced Manual p.13
  Quote  OPEN fname$ FOR mode AS #fnbr
Opens a file for reading or writing. 'fname$' is the file name in 8.3 format. 'mode' can be INPUT,
OUTPUT, APPEND or RANDOM. ‘#fnbr’ is the file number (1 to 10).
 PRINT #fnbr, expression [[,; ]expression] … etc
Outputs text to the file opened as #fnbr.
 INPUT #fnbr, list of variables
Read a list of comma separated data into the variables specified from the file previously opened as #fnbr.
 LINE INPUT #fnbr, variable$
Read a complete line into the string variable specified from the file previously opened as #fnbr.
 CLOSE #fnbr [,#fnbr] …
Close the file(s) previously opened with the file number ‘#fnbr’.

Regards

EDIT:
A simple example
FName$="filenam.dat" 'Your file name
Open FName$ For random As 1
Seek #1,1

Do
a$=Input$(1,#1)
Print a$;
Loop While Not Eof(1)

Edited by twofingers 2015-10-30
causality ≠ correlation ≠ coincidence
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 03:26pm 29 Oct 2015
Copy link to clipboard 
Print this post

Paul - reading and writing on the MM+ is most certainly do-able.
Pretty much like the Maximite, really, in that you can read whole lines into strings, or just single bytes, or a series of bytes in a loop till the code hits an EOM(end of message) marker byte.

Depending on what you want to actually do, we can all give you some example code to play with just as twofingers did above. His example opens the file as random and positions the file pointer to byte 1, and then you can set the file pointer to the byte you want to read, so long as you know exactly inside the datafile where you want to be.

SEEK #1,512 for example, would put the file pointer at byte 512 of the opened file. When you then read from the file, it will start from that byte. For a big datafile, this can dramatically speed up the reading process, so long as you datafile is mapped and uses a standard layout so you know where the data should always be kind of thing.

RANDOM is an advanced method, but you can just use standard open for read, and the MM+ will take care of incrementing the file pointer for you.

So - how many bytes are you needing to read from the file, and how is the datafile formatted? Do you need random access, or sequential? Sequential is when you open the file for read(not random), and the pointer is initially at zero and taken care of for you by the MM+. You then read a record at a time till you find what you need.

It does depend somewhat on how you want to access the data, so any additional details at this point would help everyone offer you some solutions.

Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 07:38pm 29 Oct 2015
Copy link to clipboard 
Print this post

Looks like I'm going to have to have a play with reading from the SD card. I haven't used it at all yet. I guess I was expecting to put the same file on the card as what I am using now with each line starting with DATA. But that is obviously not the case. I will play around, better to learn by myself. If I use someone else's code I won't learn anything. Will post back when I run into trouble.
Thanks Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 12:07pm 04 Nov 2015
Copy link to clipboard 
Print this post

OK I have altered my code to INPUT from the SD card instead of READing from a DATA file.
The file on the card opens OK but I'm having trouble inputting a file, I want to INPUT a string variable
I have opened the file as #1 so the syntax I am using is
INPUT #1, record$
but all I get is a ? on the screen as if the MM is waiting for input from the KB if I hit ENTER I get a message invalid variable name.
What am I doing wrong.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2948
Posted: 12:57pm 04 Nov 2015
Copy link to clipboard 
Print this post

Hi Paul,

How are you 'Opening' the file?
You need to use:

OPEN filename$ FOR INPUT as #1

Just checking you have done this . . .
NOTE: I think you can replace INPUT in the above line with RANDOM (but not next to a MM+ to check!)

WW
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 03:04pm 04 Nov 2015
Copy link to clipboard 
Print this post

Hi-de-hi.


Open "DATA.DAT" for INPUT as #1
...
...
...
LINE INPUT #1,record$


The ... is just me indicating the rest of your program - don't enter this - the interpreter will throw a wobbly.

Assuming that your datafile is called DATA.DAT - change the filename to whatever it actually is called.

I think you are only missing the word LINE from the beginning of your experiment.

INPUT #1,record$ - This will try to input a line of text from the CONSOLE.
LINE INPUT #1,record$ - this will try to input a line of text from the file on the SD card previously opened.
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 03:34pm 04 Nov 2015
Copy link to clipboard 
Print this post

Hi Grogster,
I don't want to input an entire line just the first variable
from the manual
  Quote  INPUT #fnbr, list of variables
Read a list of comma separated data into the variables specified from the file previously opened as #fnbr


so instead of a list of comma separated data I just want to enter the first entry in my data file.
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 04:00pm 04 Nov 2015
Copy link to clipboard 
Print this post

I did have a problem with the format of my data file which is now OK

INPUT #1,record$

gives an error of invalid variable name

Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 04:05pm 04 Nov 2015
Copy link to clipboard 
Print this post

Hi.

INPUT #1,record$ will try to suck data out of a SERIAL PORT buffer, NOT the SD card.

EDIT: My mistake - works with either or.....


Open "DATA.DAT" for INPUT as #1
...
...
...
BITE$=INPUT$(1,#1) 'Suck ONE byte from the open file, and save it in BITE$
PRINT BITE$.


...further down the same page 14 of the advanced manual...

This will get just ONE byte from the open file.
BITE$=INPUT$(5,#1) will suck FIVE bytes from the open file.
Etc....
Edited by Grogster 2015-11-06
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 04:08pm 04 Nov 2015
Copy link to clipboard 
Print this post

Is your datafile comma seperated or just raw data bytes one after another?

EDIT:

Example of comma separated: 001,125,231,045,002
Example of raw bytes: ABCDEFEdited by Grogster 2015-11-06
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 04:33pm 04 Nov 2015
Copy link to clipboard 
Print this post

In my experiements, I am unable to get anything other then zero's out of the input command - perhaps a bug?





I can get the bytes using LINE INPUT, but NOT via just the INPUT command.

Comments?

DATA.DAT is a single line - "ABCDEF<cr>"
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 04:50pm 04 Nov 2015
Copy link to clipboard 
Print this post

My data file is comma separated, this is part of the file

  Quote  
"015"
"-10"
1,0509,0.74,1120,3.08,1804,1.28,2320,2.58
2,0618,0.99,1231,2.84,1942,1.49,0,0
3,0031,2.18,0751,1.17,1424,2.73,2141,1.44
4,0314,2.03,0931,1.18,1609,2.84,2312,1.21
5,0458,2.20,1048,1.08,1717,2.99,0,0
6,0006,1.00,0551,2.39,1146,0.97,1800,3.09
7,0047,0.87,0628,2.54,1232,0.90,1833,3.14
8,0120,0.82,0657,2.65,1308,0.89,1901,3.14
9,0147,0.83,0723,2.72,1337,0.92,1926,3.11
10,0207,0.86,0747,2.77,1359,0.97,1949,3.06
11,0220,0.89,0810,2.80,1418,1.04,2010,2.99
12,0228,0.90,0832,2.81,1436,1.12,2031,2.89
13,0236,0.90,0855,2.81,1457,1.22,2051,2.78
14,0249,0.91,0922,2.78,1519,1.34,2110,2.64
15,0307,0.95,0954,2.73,1544,1.50,2133,2.48
16,0330,1.03,1033,2.65,1705,1.67,2202,2.29
17,0357,1.15,1124,2.54,1840,1.78,2245,2.08
18,0435,1.32,1232,2.46,2043,1.76,0,0
19,0021,1.89,0705,1.46,1425,2.47,2223,1.55
20,0259,1.88,0853,1.42,1606,2.67,2309,1.30
21,0427,2.12,1014,1.26,1655,2.91,2346,1.05
22,0513,2.40,1110,1.05,1733,3.14,0,0
23,0020,0.81,0551,2.71,1156,0.84,1807,3.34
24,0053,0.59,0628,3.02,1238,0.67,1842,3.49
25,0125,0.40,0707,3.29,1320,0.57,1918,3.57
26,0158,0.27,0749,3.50,1403,0.56,1956,3.53
27,0232,0.22,0833,3.60,1451,0.66,2037,3.38
28,0307,0.27,0920,3.59,1546,0.85,2120,3.11
29,0348,0.43,1010,3.47,1649,1.09,2206,2.76
30,0435,0.68,1104,3.26,1801,1.32,2258,2.39
31,0536,0.96,1207,3.02,1933,1.45,0,0
32

This is the data for Oct 2015, the data continues for all of the following year (2016).

What I want to do is read the first entry '015' and compare it to the year in DATE$ then compare the second entry '-10' and compare it to the month in DATE$
Then keep reading the entries until I find the one that corresponds to the day in DATE$. That done I want to INPUT the next 8 entries which are the times and heights of the tide and print them to the screen.
I have the code working fine using a DATA file and READ command but the end user would not be able to alter the data so I want to put it on an SD card.

Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 05:07pm 04 Nov 2015
Copy link to clipboard 
Print this post

Lovely - that gives us a sample dataset to work with.

I will have a play around with this sample data.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 05:23pm 04 Nov 2015
Copy link to clipboard 
Print this post

I am getting results using LINE INPUT, but still not the wanted using INPUT.





This example just reads the firt ten lines of the file.
It does nothing with the data, except prove that it is reading it fine.
We could write some code toe extract the data in the strings to the values you need, or if all you wanted to do was show it on the screen, then job done.

Naturally, there would still be a little bit of manipulation needed yet to find the correct dataset, and then find the correct starting point, but that isn't that difficult.
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1997
Posted: 05:33pm 04 Nov 2015
Copy link to clipboard 
Print this post

Thanks for the help Grogs,
The beginning of my code is,


START:
year$ = Right$(Date$,3)
month$ = Mid$(Date$,3,3)
days$ = Left$(Date$,2)
day = Val(days$)
OPEN tidetime.dat FOR input AS #1
Do 'look through the data for the year eg: "015"
input$ #1, year2$
If year2$ = year$ Then Exit
Loop

Do
input #1, month2$ 'look through the data for the month eg: -10
If month2$ = month$ Then Exit
Loop

Do ' look through the data for the correct day
input #1, day2$
If Len(day2$)= 1 Then
day2$ = "0"+day2$
EndIf
If day2$ = days$ Then Exit
Loop


after this the next 8 entries are INPUT and printed to the screen

Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 05:40pm 04 Nov 2015
Copy link to clipboard 
Print this post

I've just got to nip away to a job, but I will post back later with a code for you to experiment with. Other members may well have chimed in by then with code, in which case, I won't.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 08:30pm 04 Nov 2015
Copy link to clipboard 
Print this post

Try this:


START:
year$ = Right$(Date$,3)
month$ = Mid$(Date$,3,3)
days$ = Left$(Date$,2)
day = Val(days$)
Open "paul.dat" For input As #1
Print "DAY/MONTH/YEAR:"
Print days$,month$,year$
Print "Searching for year...";

Do 'look through the data for the year eg: "015"
Line Input #1,year2$
If Mid$(year2$,2,3) = year$ Then
Print "(OK)"
Exit Do
EndIf
Loop
Print "Searching for month...";
Do
Line Input #1,month2$ 'look through the data for the month eg: -10
If Mid$(month2$,2,3) = month$ Then
Print "(OK)"
Exit Do
EndIf
Loop
Print "Searching for day...";
Do ' look through the data for the correct day
Line Input #1,day2$
If Mid$(day2$,2,1)="," Then
daze$="0"+day2$
Else
daze$=day2$
EndIf
If Mid$(daze$,1,2)=days$ Then
Print "(OK)"
Exit Do
EndIf
Loop

'At this point, we should be at the right place in the datafile

For X=1 To 8
Line Input #1,L$
Print L$
Next
Print:Print "Done."
End


I have tried setting the date to both a single-digit, and a double-digit.

Results:

DATE$="05-10-2015"





DATE$="17-10-2015"




These test codes make no allowance for the date being close to the end of the month, and there not being eight days to read from the file - that would require a little more code.
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025