Go Down

Topic: How to let an Arduino open Programs/files off a Micro SD Card Module? (Read 614 times) previous topic - next topic

Bork1547

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


Erik_Baas


Bork1547

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() {}

Erik_Baas

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

Bork1547

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() {}

Erik_Baas

Sorry, can't help you there, being a beginner myself...  ;-)

Juraj

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

pert

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():
https://www.arduino.cc/en/Reference/SD
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.

Bork1547

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.)

pert

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 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.

pert

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.

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.

pert

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.

Bork1547

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)

pert

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

Go Up