SparkFun gator:log Hookup Guide
MakeCode Examples
Now that you have added the gator:particle extension to the Editor, lets start with some example code. Plug the micro:bit into your computer using an USB micro-B cable after you have assembled your hardware with the instructions from the previous section. The micro:bit should appear on your computer as a removable storage device.
To upload new code, this is where you will be copying the downloaded .hex
file to later.
Block Functions
Initialize gator:log
This block should be pretty self explanatory, it sets the gator:log and SD card to they are ready to log data. You should use this within the on start
block.
open file named "____"
This block should be pretty self explanatory, it opens a specific file. If the file can't be found in the current directory, a new file with the input name will be created. (*New files aren't actually created until there is data written into them.)
File Name
- Input name of file to be opened. Standard 8.3 filenames are supported. For example:
87654321.123
is acceptable.987654321.123
is not acceptable.
remove file "___"
This block should be pretty self explanatory, it deletes a file from the current directory
File Name
- Input name of file to be to be deleted. Standard 8.3 filenames are used and wildcards (e.g. *
) are supported.
create folder with name "___"
This block should be pretty self explanatory, creates a folder within the current directory.
Folder Name
- Input name of sub-directory to be created.
change to "___" folder
This block should be pretty self explanatory, changes the current directory to a specific folder. If the folder can't be found in the current directory, a new folder with the input name will be created.
Folder Name
- Input name of sub-directory to move to.
remove folder "___" and it's contents
This block should be pretty self explanatory, it deletes a folder and any content inside it.
Folder Name
- Input name of directory to be deleted along with any files contained within it.
write line "___" to current file
This block writes data to the currently accessed file. If no specific file is accessed after initialization, by default this data is written to LOG00000.txt (created on initialization).
Data
- Input data to be entered into current file. (Entry contains carriage return and next entry will begin on a new line.)
write "___" to current file
This block writes data to the currently accessed file. If no specific file is accessed after initialization, by default this data is written to LOG00000.txt (created on initialization).
Data
- Input data to be entered into current file. (Entry does not contain a carriage return and next entry will begin on the same line after the previous entry.)
write line "___" at position ___
This block writes data to the currently accessed file at a specific character number. If no specific file is accessed after initialization, by default this data is written to LOG00000.txt (created on initialization).
Data
- Input data to be entered into current file. (Entry contains carriage return and next entry will begin on a new line.)Position
- An integer for where in the current data the entry should begin.
Basic Test
Below, is a simple example of how to test the data logger. To use this example, there are multiple options for accessing the .hex
file:
- Replicate the block functions from the display below to copy the example project. Then download the
.hex
file. - Expand the display widow to pull up the example project. Then download the
.hex
file. - Use this link to pull up the example project. Then download the
.hex
file. Download the
.hex
file from the button below or the link on the bottom of the display.
This code is relatively simple, in that it is used to test the buffer on the gator:log. The code expands the span of the dataset stored on each subsequent line; except when the length of digits increase, then is expands by 3. This was to limit the cycle time spent to map that out neatly. (With this code, I was able to max out the gator:log in several minutes; whereas, when mapped out neatly the gator:log had only reached the 200th line after 30 minutes.)
The µSD card was removed from the gator:log and opened on a computer. You will notice the config.txt
and LOG00000.txt
files, which are created on initialization. The sample data set for this example is stored in sample.txt
.
Based on the recorded data set, the last full row was line 1737, which had 1743 characters stored before the gator:log reset itself. Now, we do not expect many users to reach data sets that long on a single line, but users should be aware of certain limitations.
It is always a best practice to test/verify that the gator:log will work properly for your application. It would be a disappointing to lose a bunch of data or miss out on something important.
Multiple Files
Below, is a simple example of how to write data to multiple files. Again, there are multiple options for accessing the .hex
file:
This code is relatively simple, in that odd numbers are saved to the odd.txt
file and even numbers are saved to the even.txt
file. After loading this example and waiting a bit, you can remove the µSD card and open the odd.txt
and even.txt
files. You should see the corresponding integers stored in each file.