カードモジュールを使用してArduino Mega 2560のシリアルポートからSDカードに書き込もうとしています。シリアルポートからSDカードに書き込む
シリアルCOMに入力したものをtxtファイルに書きたいと思っています。
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("This is a test and should be ignored");
if (!SD.begin(chipSelect)) {
Serial.println("\nCard failed, or not present");
// don't do anything more:
return;
}
else{
Serial.println("\ncard initialized.");
}
}
void loop() {
// put your main code here, to run repeatedly
File OpenFile = SD.open("test.txt", FILE_WRITE);
if(OpenFile and Serial.available());
{
OpenFile.println(Serial1.read());
OpenFile.close();
}
}
しかし連続の「-1」行と「1」は、「なし、SDに書き込まれます。
はい、私は他の方法でSDカードに書き込むことができています。 ..
乾杯、ポップ
これは機能しました。しかしそれはASCIIで書かれています(コードは他のcompにあります...)。将来的に誰かが助けを必要とするなら、あなたはcharでSerial.readを解析する必要があります。 – PoP
@PoP答えがあなたの質問を解決する助けになった場合は、投票を追加するか、答えとして選択することを検討できますか?乾杯 –