Solved: Arduino Yun: Using SD- and FileIO-libs at the same time: Not possible?

Hi I’m trying to use FileIO to copy a .bmp-File from an Arduino Yun AR9331-connected SD-card to an SD card that is connected on the 32u4-side of the yun. However, as soon as I use SD.h (to talk to the SD-card on the 32u4-side) and FileIO.h (to talk to the AR9331 over the bridge), I get the following compiler-error:

In file included from tft_3_5_zoll_copy_bmp_from_ar9331_to_sd_and_display.ino:13:0:
/Applications/Arduino_1.5.7.app/Contents/Resources/Java/libraries/Bridge/src/FileIO.h:28:7: error: redefinition of ‘class File’
class File : public Stream {
^
In file included from tft_3_5_zoll_copy_bmp_from_ar9331_to_sd_and_display.ino:11:0:
/Applications/Arduino_1.5.7.app/Contents/Resources/Java/libraries/SD/src/SD.h:26:7: error: previous definition of ‘class File’
class File : public Stream {
^

This is the source I’m trying to compile:

/***************************************************
  Trying to copy a file from Yun's AR9331-SD to 32U4-SD
  over FileIO (Bridge).

 ****************************************************/

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

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.

#define SD_CS 4

File myFile;

void setup(void) {
  Bridge.begin(); // Noetig, damit die Console laeuft, man also ueber Internet etwas vom Arduino yun hoeren kann
  Serial.begin(57600);
  while(!Serial);
  pinMode(8, OUTPUT); // Hardware SS must be set to Output!

  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
  }
  Serial.println("OK!");

  if (SD.exists("test.bmp")) {
    SD.remove("test.bmp");
 Serial.println("Removing example.txt...");
  }

  myFile = SD.open("test.bmp", FILE_WRITE);
  if (myFile){
  // Open requested file on SD card of AR9331
  File bmpFile = FileSystem.open("/mnt/sda1/bilder/75er/001.bmp");
  if (bmpFile == NULL) {
    Serial.println("File not found");
    return;
  }
  else {
    Serial.println("File found");
  }
  // Jetzt lesen wir die Daten via Bridge und schreiben Sie ins File.
  while (bmpFile.available()){
   myFile.write(bmpFile.read());
  }
  myFile.close();
  }
}

void loop() {
}

What could I do to circumvent this error? Do I have to rename one of the classes?
Thanks, Dani

Both SD.h and FileIO.h use a class that have the same name, so if you include them together you have that error. To use both libraries you can change the name of a class but you have to change the name everywhere the class is used. If you don't know what you have to modify you will encounter a lot of compilation errors.

Thanks for confirming my apprehension - I'll try it anyway! Dani

Ok, so if you want to use the Bridge library (FileSystem) to access files on the AR9331-side and copy them over to a SD-card on the 32u4 or teensy 3.1 side, you can use my altered Bridge library as attached below. It is a modified version of Paul Stoffregens general Bridge library as found at GitHub - PaulStoffregen/Bridge: Communicate between Teensy & Raspberry Pi - similar to Arduino Yun.

The following sketch copies a file from the linux side to the sd card on the arduino side:

/***************************************************
  Copying a file from Yun's AR9331-SD to teensy3.1-SD
  over FileIO (Bridge).
  Daniel Süsstrunk modified the already modified Arduino Yun
  Bridge by Paul Stoffregen to rename the class File to
  MyFile to avoid conflicts with the class File of the SD library.
 ****************************************************/

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

#define SD_CS 10

void setup(void) {
  Bridge.begin(); // Start bridge
  Serial.begin(57600);
  while(!Serial){;};
  Serial.println("Start");
  pinMode(SS, OUTPUT); // Hardware SS must be set to Output!

  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
  }
  else {
  	Serial.println("OK!");
  }

  File sdFile = SD.open("test.bmp", FILE_WRITE);

  // if the file opened okay, write to it:
  if (sdFile) {
    Serial.println("File opened ...");
    // Open requested file on SD card of AR9331
    MyFile bmpFile = FileSystem.open("/mnt/sda1/bilderrahmen/bilder/75er/001.bmp");
    if (bmpFile == NULL) {
      Serial.println("File not found");
      return;
    }
    else {
      Serial.println("File found");
    }
    // Now read from the bridge and write to sdFile.
    while (bmpFile.available()){
    	sdFile.write(bmpFile.read());
    }
    sdFile.close();
    Serial.println("and closed");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.bmp");
  }
}

void loop() {
}

I’m not used to tamper with libraries and if you see, that I did things the wrong way, please feel free to alter it and let me know here. Thanks!

Dani

Bridge.zip (134 KB)