Skip to content

Commit 0bc9eb9

Browse files
committed
firstcommit_w25q128
1 parent 8e8535c commit 0bc9eb9

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.vscode
2+
test/w25q128_test/.theia/launch.json

test/w25q128_test/w25q128_test.ino

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <SPI.h>
2+
#include <SdFat.h>
3+
#include <Adafruit_SPIFlash.h>
4+
5+
#ifndef FLASH_CONFIG_H_
6+
#define FLASH_CONFIG_H_
7+
8+
#define EXTERNAL_FLASH_USE_CS 22
9+
#define EXTERNAL_FLASH_USE_SPI SPI
10+
11+
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
12+
13+
#endif
14+
15+
Adafruit_SPIFlash flash(&flashTransport);
16+
17+
FatVolume fatfs; // file system object from SdFat
18+
19+
#define FILE_NAME "data.csv" //ファイル名を指定
20+
21+
void setup() {
22+
// Initialize serial port and wait for it to open before continuing.
23+
Serial.begin(115200);
24+
while (!Serial) {
25+
delay(100);
26+
}
27+
Serial.println("Adafruit SPI Flash FatFs Simple Datalogging Example");
28+
29+
// Initialize flash library and check its chip ID.
30+
if (!flash.begin()) {
31+
Serial.println("Error, failed to initialize flash chip!");
32+
while (1) {
33+
delay(1);
34+
}
35+
}
36+
Serial.print("Flash chip JEDEC ID: 0x");
37+
Serial.println(flash.getJEDECID(), HEX);
38+
39+
// First call begin to mount the filesystem. Check that it returns true
40+
// to make sure the filesystem was mounted.
41+
if (!fatfs.begin(&flash)) {
42+
Serial.println("Error, failed to mount newly formatted filesystem!");
43+
Serial.println(
44+
"Was the flash chip formatted with the fatfs_format example?");
45+
while (1) {
46+
delay(1);
47+
}
48+
}
49+
50+
Serial.println("Mounted filesystem!");
51+
Serial.println("Logging data every 60 seconds...");
52+
}
53+
54+
void loop() {
55+
// Open the datalogging file for writing. The FILE_WRITE mode will open
56+
// the file for appending, i.e. it will add new data to the end of the file.
57+
File32 dataFile = fatfs.open(FILE_NAME, FILE_WRITE);
58+
// Check that the file opened successfully and write a line to it.
59+
if (dataFile) {
60+
// Take a new data reading from a sensor, etc. For this example just
61+
// Write a line to the file. You can use all the same print functions
62+
// as if you're writing to the serial monitor. For example to write
63+
// two CSV (commas separated) values:
64+
dataFile.print("Sensor #1");
65+
dataFile.print(",");
66+
dataFile.print(reading, DEC); //必要なデータの代入
67+
dataFile.println();
68+
dataFile.close();
69+
Serial.println("Wrote new measurement to data file!");
70+
} else {
71+
Serial.println("Failed to open data file for writing!");
72+
}
73+
74+
Serial.println("Trying again in 60 seconds...");
75+
76+
// Wait 60 seconds.
77+
delay(60000L); //時間を適切な時間に修正
78+
}

0 commit comments

Comments
 (0)