https://docs.sunfounder.com/
un r4 wifi 日本語サイト
https://newbiely.com/
r4の詳しい説明あり
-------------------------------------------------
PIEZO,DHT11,SERVO,WS2812(真ん中が信号、赤Vcc、白Gnd)OK
ーーーーーーーーーーーーーーーーーーーーーーーーーー
https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card
---------------- first :: file create on sdcard ----------------------
#include <SD.h>
#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module
File myFile;
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println(F("SD Card is either missing or has failed!"));
while (1); // don't do anything more:
}
Serial.println(F("SD Card is ready"));
if (!SD.exists("arduino.txt")) {
Serial.println(F("arduino.txt doesn't exist. Creating arduino.txt file..."));
// create a new file by opening a new file and immediately close it
myFile = SD.open("arduino.txt", FILE_WRITE);
myFile.close();
}
// recheck if file is created or not
if (SD.exists("arduino.txt"))
Serial.println(F("arduino.txt exists on SD Card."));
else
Serial.println(F("arduino.txt doesn't exist on SD Card."));
}
void loop() {
}
#include <SD.h> #define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module File myFile; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD Card is either missing or has failed!")); while (1); // don't do anything more: } Serial.println(F("SD Card is ready")); // open file for writing myFile = SD.open("arduino.txt", FILE_WRITE); if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } // open file for reading myFile = SD.open("arduino.txt", FILE_READ); if (myFile) { int line_count = 0; while (myFile.available()) { char line[100]; // maximum is 100 characters, change it if needed int line_length = myFile.readBytesUntil('\n', line, 100); // read line-by-line from Micro SD Card line_count++; Serial.print(F("Line ")); Serial.print(line_count); Serial.print(F(": ")); Serial.write(line, line_length); // print the character to Serial Monitor // \n character is escaped by readBytesUntil function Serial.write('\n'); // print a new line charactor } myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } } void loop() { }
-------------third:: file read on sdcard------------------------------
#include <SD.h> #define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module File myFile; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD Card is either missing or has failed!")); while (1); // don't do anything more: } Serial.println(F("SD Card is ready")); // open file for writing myFile = SD.open("arduino.txt", FILE_WRITE); if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } // open file for reading myFile = SD.open("arduino.txt", FILE_READ); if (myFile) { int line_count = 0; while (myFile.available()) { char line[100]; // maximum is 100 characters, change it if needed int line_length = myFile.readBytesUntil('\n', line, 100); // read line-by-line from Micro SD Card line_count++; Serial.print(F("Line ")); Serial.print(line_count); Serial.print(F(": ")); Serial.write(line, line_length); // print the character to Serial Monitor // \n character is escaped by readBytesUntil function Serial.write('\n'); // print a new line charactor } myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } } void loop() { }
0 件のコメント:
コメントを投稿