Arduino SD Karte Hilfe Benötigt!

OP #4155186
Lesenswert?
• ▲
▼
Hallo zusammen,
ich habe mit meinem Arduino und einem SD Shield schon mal eine 
Verbindung aufgebaut die funktioniert aber ich möchte wenn ich eine TXT 
Datei lese einzelne Zeilen auslesen, beschreiben, löschen können ohne 
die anderen dabei zu verändern. Ist dies realisierbar?

LG
OP #4155515
Lesenswert?
• ▲
▼
Hallo zusammen,
ich habe nochmal ein bisschen rumprobiert und stehe vor einem Problem: 
ICh möchte mit dem SD.exists Befehl gucken ob ein Ordner da ist aber es 
kommt immer folgende Fehlermeldung:

Arduino: 1.6.2 (Windows 7), Platine: "Arduino Uno"

ReadWrite.ino: In function 'void loop()':

ReadWrite.ino:70:19: error: invalid conversion from 'const char*' to 
'char' [-fpermissive]

ReadWrite.ino:71:25: error: invalid conversion from 'char' to 'char*' 
[-fpermissive]

In file included from ReadWrite.ino:22:0:

C:\Program Files\Arduino\libraries\SD\src/SD.h:76:11: error: 
initializing argument 1 of 'boolean SDClass::exists(char*)' 
[-fpermissive]

   boolean exists(char *filepath);

           ^

Fehler beim Kompilieren.

  Dieser Report hätte mehr Informationen mit
  "Ausführliche Ausgabe während der Kompilierung"
  aktiviert in Datei > Einstellungen


Das ist der Quellcode:

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card 
file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
File myFile;
SoftwareSerial mySerial(2, 3);
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by 
default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an 
output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.

/*

  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }*/
}

void loop()
{
 if (mySerial.available()){
    char mysread = mySerial.read();
    char readed = "/filename/";
    if (SD.exists(readed))
    {
    Serial.print("Existiert!");
    }
    Serial.print(mysread);
}
}


Kann mir jemand helfen?
#4155555
Lesenswert?
• ▲
▼
@ Toni Nachname (ich3)

>ReadWrite.ino: In function 'void loop()':

In der Funktion 'void loop()'

>ReadWrite.ino:70:19: error: invalid conversion from 'const char*' to
>'char' [-fpermissive]

ungültige Umwandlung von Zeiger auf konstantes Zeichen zu Zeichen

Auch im Arduino-Wunderland braucht man ein paar solide C-Grundlagen. 
Dazu gehört auch die Stringverarbeitung. Und ein paar minimale 
Englischkenntnisse wären auch gut, not only some Brocken. An deinem 
Einrückungsstil solltest du auch arbeiten.

Strukturierte Programmierung auf Mikrocontrollern

Eher so.
1
void loop() {
2
  if (mySerial.available()) {
3
    char mysread = mySerial.read();
4
    char my_filename[] = "/filename/";   // das ist ein char array!
5
    if (SD.exists(my_filename)) {
6
      Serial.print(my_filename);
7
      Serial.println(" existiert!");
8
    }
9
    Serial.print(mysread);
10
  }
11
}
Gast #4155605
Lesenswert?
• ▲
▼
1
char my_filename[] = "/filename/";   // das ist ein char array!
und
1
if (SD.exists(my_filename)) //<-- da wird ein Pointer uebergeben
2
{
3
}
Alternativ:
1
if (SD.exists(&my_filename[0])) //Adresse von erstem Element aus dem Char-Array
2
{
3
}

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.