How to let an Arduino open Programs/files off a Micro SD Card Module?

I have a Arduino Pro Micro connected to a Micro SD Card Module and I was wondering how do I get the Arduino to open Programs/files off the SD Card when I plug it into a Computer (Windows 10).

So far I have this:

#include <SD.h>
#include <SPI.h>

File myFile;

void setup()
{
pinMode(3, INPUT_PULLUP);
if (digitalRead(3) == LOW){
while(1);

myFile = SD.open("test.txt", FILE_WRITE);
}

void loop() {}

The Error I receive is this:

exit status 1
a function-definition is not allowed here before '{' token

Press Ctrl+T in the IDE and you will see what's wrong.

Same Problem,

#include <SD.h>
#include <SPI.h>

File myFile;

void setup()
{
pinMode(3, INPUT_PULLUP);
if (digitalRead(3) == LOW) {
while (1); {

myFile = SD.open("test.txt", FILE_WRITE);
}

void loop() {}

Wy are there three spaces in front of "void loop()" ? Hint: count your curly braces!

I took out the extra {'s and it allowed me to Upload to the Arduino. The only problem is that it doesn't open the Text file. (I would like to be able to Run any file type (Bat, Txt, Png, Etc))

#include <SD.h>
#include <SPI.h>

File myFile;

void setup()
{
pinMode(3, INPUT_PULLUP);
if (digitalRead(3) == LOW)
while (1);

myFile = SD.open("test.txt", FILE_WRITE);
}

void loop() {}

you can't. Micro can by only a USB HID device, not a USB Mass Storage device

Bork1547:
The only problem is that it doesn't open the Text file. (I would like to be able to Run any file type (Bat, Txt, Png, Etc))

It's not clear what you mean by this.

First of all, it's very clear that you haven't bothered to study the reference for the SD library at all, otherwise you would know the most basic information that you need to call SD.begin():

You also don't do anything with the file once you open it, so how would you know it didn't open the file. Start by following the DumpFile tutorial:
https://www.arduino.cc/en/Tutorial/DumpFile

Are you expecting the file to open on your computer maybe? That's not how it works. The file is opened on the Arduino board. You can read and write to the files on the SD card from your Arduino program. You can't "Run" anything from the card.

All Im trying to do is that there is a Batch file located in that SD Card that is attached to the SD Module which is attached to the Arduino Pro Micro. Im trying to create something on the Arduino that when plugged into the Computer it will Automatically open that .bat file from the SD Card. (I do not what the Arduino to run the Batch file when opened, I want the Computer to.)

You would need to do something extremely hacky to make this happen. Note that, unless otherwise noted, this is all done in your Arduino sketch and runs on your Arduino board:

  • Open batch file on SD card.
  • Use the [Keyboard library](https://www.arduino.cc/reference/en/language/functions/usb/keyboard/\) to open a text editor on the computer.
  • Read the contents of the batch file and use the Keyboard library to type it into the text file on the computer.
  • Use the Keyboard library to save the text file as a .bat on the computer.
  • Use the Keyboard library to run the saved .bat file on the computer.

Alternately, you could use the Keyboard library to open cmd on the computer and type and execute each line of the batch file individually. That would work with basic batch files that are just lists of commands, but not with the more advanced batch files that use special features of the batch file language.

If I do that there is another problem I run into. When I plug in my Arduino into the PC the SD Card does not show up. I was wondering if there is a way to show the SD Card when the Arduino is plugged in or when a Button on the Arduino is pressed while plugged in.

Are you expecting the SD card to show up on the computer? That will never happen. The SD card will be visible only to your Arduino Micro and needs to be read and written to by the code in your sketch.

No I wasn't expecting the SD Card to magically show up. I was a little vague, Is there some Simple Code that could show the SD Card to the Computer so I could find it in the Files like any other Portable Storage Device? And if so is there a way to make it so when a Certain button was press on the Arduino that has been attached (D2 and GND) that it would show when Press and not when Unpressed. Thanks.

(Attached file is showing what I have setup on the Arduino)

No. No. No. Listen to what we're telling you. You can't do that with an Arduino Micro.

Bork1547:
If I do that there is another problem I run into. When I plug in my Arduino into the PC the SD Card does not show up. I was wondering if there is a way to show the SD Card when the Arduino is plugged in or when a Button on the Arduino is pressed while plugged in.

see my comment

So there is no way for the Arduino Pro Micro to execute files off the connected SD Card Module, able to find the Directory of the SD Card while plugged into computer and have the Arduino read a script from the SD Card and let that Script from the SD Card execute files?

"So there is no way for the Arduino Pro Micro to execute files off the connected SD Card Module, "
Yes, look into this
https://forum.arduino.cc/index.php?topic=16812.0

"able to find the Directory of the SD Card while plugged into computer "
Not directly, the computer would need to read the card and pass along the info. Maybe a Python sketch?

"and have the Arduino read a script from the SD Card and let that Script from the SD Card execute files?"
There is a program that will execute scripts from an SD card connected to the Arduino called bitlash

Take a look into that.

So there is no way to have the Arduino execute a file from the Sd Card or have the Arduino Have something else do it for it? (The Arduino reads another script from the SD Card and that script executes the file)

I think a bitlash program would do that. I've not done it myself, all my sketches have run independently.

I looked at Load sketch code from SD Card - Interfacing - Arduino Forum That, and I don't want to execute Sketch files from the Arduino I would like to Execute Batch or VBScript files. Is there a way for the Arduino to execute a file or read a Batch/VBScript files from the Arduino?