0
我正試圖使用卡模塊從串行端口寫入Arduino Mega 2560中的SD卡。從串行端口寫入SD卡
我希望能夠在txt文件中寫入我在串行com中輸入的內容。
#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如果答案幫助解決了你的問題,你可以考慮增加一個投票,還是選擇它作爲答案。乾杯 –