I'm currently working on recreating the puzzle language from the game "The Witness" on an Arduino UNO Rev 3. Im using a 2.8" TFT Touchscreen from Adafruit for user interaction and displaying. I'm super excited how far I already got after a lot of different prototypes.
My questions is partially very general and also very specific to the code I wrote, I feel like. Bascially: how can I reduce the program storage the code takes further? I read through the Adafruit Arduino Memory Guide and went through several articles already trying my best to reduce size to best my knowledge. Any help would be greatly appreciated as it would lead to more puzzle elements incorporated. I am basically trying to get as much program (or rather all the puzzle elements, and not that many are left, though their rules are somewhat code-lengthy) into the limited space of the Arduino UNO and its been great fun trying to optimize and reduce everything. Yet I think this can still be reduced further maybe and I just have not yet discovered all the ways of reducing it and that is why I am reaching out to you.
Pretty much everything is commented. I'll give a short explanation here as well though:
The Code reads through a .txt file from the SD card holding all of the puzzle information and stores the puzzle element tags in an 2D uint8_t array. The user input is handled in the Input.h class which is mainly used in the Snake.h class. The snake class bascially is the path that the user creates. Whenever the user stops touching the screen while the path is on an endcap of a puzzle the Solver class gets instantiated and the solver checks all the puzzle elements for their validity. There is a floodfill algorithm as well for the different regions which felt really good, when it eventually worked, haha!
Thanks already and wishing you a great weekend
Chris
The SdFat takes up quite a bit of storage space, especially on a 328P MCU. Optimising the library, if not already done, by disabling support for filesystem types that are not being used would be one way to reduce its footprint. If memory serves, this can be done in SdFatConfig.h.
Can't seem to find that info might wanna update github
I can see in the program its looking for the /witnuino folder in the root directory and its looking for a fat file system, but does that include the whole folder from github or?
Oh good point. I forgot to mention that. Thanks for pointing that out.
So the SD card holds a folder witnuino and inside that folder there are several numbered .txt files which are the levels. Currently what is in the "/levels/example levels/" folder. Additionally there will be a "save.txt" which will hold the last level loaded so when we reboot the system we can start from there.
Just updated the git.
The "/witnuino" folder is the one, that should be placed on the SD-card with all its contents. I added some explanations in the README as well.
Hmm that is very curious. I implemented more now and pushed it to the limit again, so I am looking for more ways to save storage.
However the current version should just be fine to upload on an UNO R3. It works for me at least with 32076 bytes. I'll make sure that everything is the same on github (though I don't see why it wouldn't)
Sketch uses 32076 bytes (99%) of program storage space. Maximum is 32256 bytes.
EDIT:
I just realised it might be that you are not using the modified SDFat library? I couldn't figure out a way yet for the sketch to specifically use the one in the local folder so it keeps referencing to the main Arduino library folder. Maybe that might cause the problem for you?
Sketch uses 34692 bytes (107%) of program storage space. Maximum is 32256 bytes.
Global variables use 669 bytes (32%) of dynamic memory, leaving 1379 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
text section exceeds available space in board
Compilation error: text section exceeds available space in board
Do you have the SdFat library in your Arduino libraries folder? If so are you willing to zip the original for backup and replace the folder with the one I uploaded on the git?
There should be a way to tell the IDE to use the local folder but I have not yet managed. I'll look into this later.
Good news. There are updates. First of, this project was meant mainly as a christmas present for my SO and I managed to develop a version that works on a portable Arduino UNO Rev3 unit with a LiPo and charger shield and a handmade cork case. It's a nice little Witness puzzle console now to have around.
I managed to optimize the code just enough to fully implement the "Sun"-rules and elements as well as well as different colour palettes. Ontop I developed a seperate Level-Editor for the device. With it you can quickly build levels and save them on the SD-card.
Right now I don't have a way to implement the polynominoes as there simply is not enough storage. However with most rules implemented it is really fun to build quite complex and difficult puzzles nevertheless.
I updated the git with the newest version just now and hope it works for others. Would love to see what others think as I think this was quite a breakthrough for myself, coding a puzzle game like that on the Arduino Uno
I suddenly just realized my problem... I have the Elegoo 2.8in TFT Capactive touch screen and not the Adafruit one!
Would it be possible when you have free time to change that for me and either upload it to get as a either A: files required for that screen OR B: just send it to me?
NO RUSH TAKE YOUR TIME I CAN TEST AND REPLY WITH RESULTS!!
It can use the adafruit libraries but I am not aware where to change the pin out for this screen in your software.
however, even when instructions are followed I still have a 1% over memory error. I have tried with a UNO R3 and a MEGA 2560 R3.