Ich Möchte daten Loggen habe aber das Problem, dass mein Programm nur ein Zeichen pro Zeile schreibt und ich nicht weiss warum…
Hier der Code, den ich von http://arduino.cc/en/Tutorial/Datalogger abgeändert habe:
//Header-Dateien
#include <SoftwareSerial.h>;
//Define
#define PMTK_UPDATE_1HZ "$PMTK220,1000*1F"
#define PMTK_UPDATE_5HZ "$PMTK220,200*2C"
#define PMTK_UPDATE_10HZ "$PMTK220,100*2F"
#define PMTK_OUTPUT_RMC_ONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
#define PMTK_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
//Initialisierung
int rxPin = 2; //Input
int txPin = 3; //Output
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.println(PMTK_OUTPUT_RMC_ONLY);
mySerial.println(PMTK_UPDATE_1HZ);
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
// make a string for assembling the data to log:
String dataString = "";
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println((char)mySerial.read());
dataFile.close();
// print to the serial port too:
Serial.println((char)mySerial.read());
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}