Hi all,
Again, thank you for reading these.
Goal: to record the state of the sensors and actuators of my current setup in the simple form of 0s and 1s.
Issue: the "records" stored on the SD show discrepancies that I can't account for (image included).
I've attached both my code and 2 examples of the recorded files on the SD. Please let me know if I should provide anything.
Thank you again.
P01_0303.TXT (19 KB)
P02_0303.TXT (16 KB)
variables.h (1.62 KB)
V2.2.ino (22.5 KB)
Here are a few tips that might help you fix your code.
-
You have an SD card with a lot of memory. Make use of it and write a nice file format like XMP that describes each data element. Than you will find it much easier to figure out what values was not written correctly.
-
SD cards do not like small values to be written to them. Collect data data and write multiple data values. SD card where made for digital cameras that write large files.
-
Your code could use some separation. Separate the SD card code into a couple of functions. Right now your code writes to the card all over the place.
-
SD card also do not like opening and closing files on Arduinos. They are used to PC and users that have all the time in the world and wait for them to finish. Open the file and write to it and keep it open until you are done.
-
Give your functions better names. e.g. issueWithSD -> lcdPrintSdError
-
Try to reduce the amount of numbers in your code and use CONSTANT_NAMES. Numbers make code hard to read.
-
Find better loop variable names than i ii iii and do not nest them in random order. At least i should have been the other most loop and ii the second and so on.
Thank you for your response. I will implement your suggestions and report back.