Hallo,
bei einem aktuellen Projekt würde ich gerne einen Wert im byte oder integer Format von der SD Karte auslesen und in einer Variable speichern. In der Datei "savePcur.txt" ist lediglich der Wert 1 gespeichert. Wenn ich das Beispiel in der Arduino IDE verwende wird dieser Wert auch im Serial Monitor angezeigt. Wenn ich jedoch versuche den Wert in einer Variable zu speichern (siehe code) und mir dann den Wert in der Variable anzeigen lassen wird als Wert im Serial Monitor "49" ausgegeben. Was mache ich falsch bzw. wie liest man die Werte richtig in eine Variable ein?
#include <SPI.h>
#include <SD.h>
File config_file;
const int chipSelect = 5;
byte save_P_cur = 2;
void setup() {
Serial.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(SS, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
config_file = SD.open("savePcur.txt");
if (config_file) {
Serial.print("open savePcur.txt ");
while (config_file.available()) {
save_P_cur = (config_file.read());
}
//while (config_file.available()) {
// Serial.write(config_file.read());
//}
Serial.println(save_P_cur);
// close the file:
config_file.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening savePcur.txt");
}
}
void loop() {
}
Vielen Dank schonmal
ArduinoArti