CS (chip select) pin the SD card reader is connected to. Also known as SS (slave select).
FILEstring
File name to append to
Wpulse
Perform file open, write, flush, close cycle
b0byte
b1byte
b2byte
b3byte
b4byte
DONEpulse
Fires when write is done
To use the node in your project you should have the nazarijtipusak080/work-with-sd-esp32 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_W
#pragma XOD error_raise enable
//{{#global}}
#include <FS.h>
#include <SD.h>
#include <SPI.h>
//{{/global}}
node {
bool begun;
void evaluate(Context ctx) {
if (!isInputDirty<input_W>(ctx))
return;
if (!begun) {
// Ініціалізація SPI та SD
auto csPin = getValue<input_CS>(ctx);
SPI.begin(18, 19, 23, csPin); // SCK, MISO, MOSI, CS
begun = SD.begin(csPin);
}
if (!begun) {
// Помилка ініціалізації
raiseError(ctx);
return;
}
// Отримання імені файлу
char filename[16] = { 0 };
dump(getValue<input_FILE>(ctx), filename);
// Спроба відкрити файл для запису
File file = SD.open(filename, FILE_WRITE);
if (!file) {
// Помилка відкриття файлу
begun = false;
raiseError(ctx);
return;
}
// Запис рядка у файл
uint8_t B0 = getValue<input_b0>(ctx);
uint8_t B1 = getValue<input_b1>(ctx);
uint8_t B2 = getValue<input_b2>(ctx);
uint8_t B3 = getValue<input_b3>(ctx);
uint8_t B4 = getValue<input_b4>(ctx);
uint8_t array[5] = {B0,B1,B2,B3,B4};
file.seek(0);
file.write(array,5);
// Додати новий рядок та завершити
file.flush();
file.close();
// Передати сигнал про завершення
emitValue<output_DONE>(ctx, 1);
}
}