This article will help you test out the SD card on your Megatronics and guide you on how to configure it in the firmware. First make sure the SD card is formatted using a FAT32 file system. Then insert the card into the Megatronics and plug in the USB cable.
To test if everything is ok, find the CardInfo example in the File -> Examples -> SD menu. Change the line
const int chipSelect = 4;
the number 4 to 53. After that, you can upload the sketch. Open Serial Monitor, and view the output. It should give something like:
Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 3212836864
Volume size (Kbytes): 3137536
Volume size (Mbytes): 3064
Files found on the card (name, date and size in bytes):
FILE.EXT 2018-07-19 19:05:36 9093270
This means that the file list was read successfully and everything works. If you encounter a problem, make sure that your PC can read the SD card and the SD card supports SPI.
To enable the use of SD cards in your firmware, in the configuration file, find the line
Uncomment (remove the //) to enable SD card support. After you upload the firmware, it should report a list of .g and .gcode files when you execute gcode M21 and then M20.