Page 14 of 16
Page 304
Note change the start of setup to:
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
to setup to force some ESP32s to change baud rate after upload and before calling loop.
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
esp_partition_iterator_t partit =
esp_partition_find(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_ANY, NULL);
while (partit != NULL) {
const esp_partition_t* part = esp_partition_get(partit);
Serial.printf("DATA label= %s Address= %lX size = %ld \n",
part->label, part->address, part->size);
partit = esp_partition_next(partit);
};
esp_partition_iterator_release(partit);
Serial.printf("\n");
partit = esp_partition_find(ESP_PARTITION_TYPE_APP,
ESP_PARTITION_SUBTYPE_ANY, NULL);
while (partit != NULL) {
const esp_partition_t* part = esp_partition_get(partit);
Serial.printf("APP label= %s Address= %lX size = %ld \n",
part->label, part->address, part->size);
partit = esp_partition_next(partit);
};
esp_partition_iterator_release(partit);
}
void loop() {
}
Page 307
Note change the start of setup to:
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
to setup to force some ESP32s to change baud rate after upload and before calling loop.
#include "nvs_flash.h"
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
nvs_flash_init();
nvs_handle_t my_handle;
nvs_open("localstorage", NVS_READWRITE, &my_handle);
char key[] = "mykey";
int32_t myvalue = 42;
int32_t myretrievedvalue;
nvs_set_i32(my_handle, key, myvalue);
nvs_commit(my_handle);
nvs_get_i32(my_handle, key, &myretrievedvalue);
Serial.printf("stored value = %ld\n", myretrievedvalue);
}
void loop(){}
Page 308
#include "FS.h"
#include "FFat.h"
void setup() {
Serial.begin(9600);
Serial.println();
Serial.println(FFat.format(true,"ffat"));
}
void loop() {
}
Page 309 Complete program
Note change the start of setup to:
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
to setup to force some ESP32s to change baud rate after upload and before calling loop.
#include "FS.h"
#include "FFat.h"
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
FFat.begin(false, "", 2, "ffat");
Serial.printf("Total space: %10u\n", FFat.totalBytes());
Serial.printf("Free space: %10u\n", FFat.freeBytes());
File f = FFat.open("/hello.txt", FILE_WRITE);
f.println("Hello world");
f.close();
f = FFat.open("/hello.txt",FILE_READ);
while (f.available()) {
char c = f.read();
Serial.write(c);
}
f.close();
Serial.println("File Closed");
}
void loop() {}
Page 310
Note change the start of setup to:
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
to setup to force some ESP32s to change baud rate after upload and before calling loop.
#include "FS.h"
#include "FFat.h"
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
FFat.begin(false, "", 2, "ffat");
Serial.printf("Total space: %10u\n", FFat.totalBytes());
Serial.printf("Free space: %10u\n", FFat.freeBytes());
File root=FFat.open("/");
File file = root.openNextFile();
while(file){
Serial.println(file.name());
file = root.openNextFile();
}
}
void loop() {
}
Page 313
Note change the start of setup to:
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
to setup to force some ESP32s to change baud rate after upload and before calling loop.
#include "FS.h"
#include "SD.h"
#include "SPI.h"
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
SPI.begin(18, 4, 15, 5);
SD.begin(5);
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
File f = SD.open("/hello.txt", FILE_WRITE);
f.println("Hello world");
f.close();
f = SD.open("/hello.txt",FILE_READ);
while (f.available()) {
char c = f.read();
Serial.write(c);
}
f.close();
Serial.println("File Closed");
}
void loop() {
}