This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
Some Examples that show how to use some custom boards with their corresponding I2S pins

View File

@@ -0,0 +1,57 @@
/**
@file streams-generator-audiokit.ino
@brief Tesing I2S output on the cross band handy walkie talkie
https://github.com/immortal-sniper1/cross_band_handy_walkie_talkie
@author Phil Schatzmann
@copyright GPLv3
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "SD.h"
AudioInfo info(32000, 2, 16);
SineWaveGenerator<int16_t> sineWave(
32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(
sineWave); // Stream generated from sine wave
DriverPins my_pins;
AudioBoard board(AudioDriverES8388, my_pins);
AudioBoardStream out(board);
StreamCopy copier(out, sound); // copies sound into i2s
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while (!Serial);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// sd pins: clk, miso, mosi,cs,
my_pins.addSPI(ESP32PinsSD{PinFunction::SD, 44, 42, 43, 2, SPI});
// add i2c codec pins: scl, sda, port, frequency
my_pins.addI2C(PinFunction::CODEC, 35, 36);
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
my_pins.addI2S(PinFunction::CODEC, 47, 21, 12, 14, 11);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
config.sd_active = true;
out.begin(config);
// check SD drive
if (!SD.begin(2)) {
Serial.println("Card Mount Failed");
stop();
}
// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
}
// Arduino loop - copy sound to out
void loop() { copier.copy(); }

View File

@@ -0,0 +1,41 @@
/**
* @file AudioMini.ino
* See https://github.com/sonocotta/esp32-audio-development-kit
* @author Phil Schatzmann
* @copyright GPLv3
*/
#include "AudioTools.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
I2SStream out;
StreamCopy copier(out, sound); // copies sound into i2s
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while(!Serial);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
// Custom I2S output pins
config.pin_bck = 26;
config.pin_ws = 25;
config.pin_data = 22;
out.begin(config);
// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
}
// Arduino loop - copy sound to out
void loop() {
copier.copy();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 KiB

View File

@@ -0,0 +1,16 @@
## ESP32S3 Camera Baord
Here are the sketches which test the functionality of this ESP32 S3 camera board
![ESP32S3 Camera Board](Overview.jpg)
Here is a summary of the limitations/issues that I have found:
- I could not make the 4 pin SDMMC to work.
- The microphone just provides noise
- The board has no Boot button, so you can not set the board easily into upload mode. Here is the work around:
- connect GND with Pin 0
- press and release the SWT2 (Reset/EN button)
- disconnect Pin 0

View File

@@ -0,0 +1,13 @@
/// If button is pressed it is pulled low
const int BUTTON = 38;
void setup() {
Serial.begin(115200);
pinMode(BUTTON, INPUT);
}
void loop() {
Serial.println(digitalRead(BUTTON));
}

View File

@@ -0,0 +1,89 @@
#pragma once
#include <memory>
#include "esp_camera.h"
class Camera;
/**
* @brief A simple Arduino C++ API over the ESP32 camera functionality.
* @author Phil Schatzmann
*/
class Camera {
// esp_camera_fb_return
struct Deleter {
void operator()(camera_fb_t *ptr) const {
if (ptr) {
esp_camera_fb_return(ptr);
}
}
};
public:
Camera() = default;
/**
* @brief Initialize the camera driver
*
* @note call camera_probe before calling this function
*
* This function detects and configures camera over I2C interface,
* allocates framebuffer and DMA buffers,
* initializes parallel I2S input, and sets up DMA descriptors.
*
* Currently this function can only be called once and there is
* no way to de-initialize this module.
*
* @param config Camera configuration parameters
*
* @return RESULT_OK on success
*/
bool begin(const camera_config_t &config) {
return esp_camera_init(&config) == ESP_OK;
}
/**
* @brief Deinitialize the camera driver
*
* @return
* - RESULT_OK on success
* - ERR_INVALID_STATE if the driver hasn't been initialized yet
*/
bool end(void) { return esp_camera_deinit() == ESP_OK; }
/**
* @brief Obtain unique_ptr to a frame buffer.
*
* @return pointer to the frame buffer
*/
auto frameBuffer(void) {
return std::unique_ptr<camera_fb_t, Deleter>(esp_camera_fb_get());
}
/**
* @brief Save camera settings to non-volatile-storage (NVS)
*
* @param key A unique nvs key name for the camera settings
*/
bool settingsSave(const char *key) {
return esp_camera_save_to_nvs(key) == ESP_OK;
}
/**
* @brief Load camera settings from non-volatile-storage (NVS)
*
* @param key A unique nvs key name for the camera settings
*/
bool settingsLoad(const char *key) {
return esp_camera_load_from_nvs(key) == ESP_OK;
}
/**
* @brief Return the frame buffer to be reused again.
*
* @param fb Pointer to the frame buffer
*/
void returnFrameBuffer(camera_fb_t &fb) { return esp_camera_fb_return(&fb); }
};

View File

@@ -0,0 +1,68 @@
// important settings:
// - USB CDC on Boot: Enabled (to see the Serial.print)
// - PSRAM: QSPI PSRAM (to have enough memory for the framebuffer)
#include "Camera.h"
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 21
#define SIOC_GPIO_NUM 14
#define Y9_GPIO_NUM 11
#define Y8_GPIO_NUM 9
#define Y7_GPIO_NUM 8
#define Y6_GPIO_NUM 6
#define Y5_GPIO_NUM 4
#define Y4_GPIO_NUM 2
#define Y3_GPIO_NUM 3
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 13
#define HREF_GPIO_NUM 12
#define PCLK_GPIO_NUM 7
#define LED_GPIO_NUM 34
Camera camera;
camera_config_t config;
void setup() {
Serial.begin(115200);
while(!Serial);
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sccb_sda = SIOD_GPIO_NUM;
config.pin_sccb_scl = SIOC_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG; // YUV422,GRAYSCALE,RGB565,JPEG
config.frame_size = FRAMESIZE_HD; //
config.jpeg_quality = 16;
config.fb_count = 2; // 8
config.fb_location = CAMERA_FB_IN_PSRAM; /*!< The location where the frame
buffer will be allocated */
config.grab_mode = CAMERA_GRAB_LATEST; /*!< When buffers should be filled */
if (!camera.begin(config)){
Serial.println("Camera failed");
while(true);
}
Serial.print("Recording...");
}
void loop() {
auto fb = camera.frameBuffer();
Serial.println(fb->len);
}

View File

@@ -0,0 +1,19 @@
// Demo for the color LED (SK6812)
#include <FastLED.h>
const int NUM_LEDS = 1;
const int DATA_PIN = 33;
CRGB led;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(&led, NUM_LEDS);
}
void loop() {
led = CRGB::Red;
FastLED.show();
delay(1000);
led = CRGB::Black;
FastLED.show();
delay(1000);
}

View File

@@ -0,0 +1,17 @@
// Demo for the LED
const int LED=34;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin as an output.
pinMode(LED, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

View File

@@ -0,0 +1,37 @@
// The module comes with a MSM261 I2S Microphone
// Make sure that USB CDC on Boot is enabled
const int I2S_WS = 37;
const int I2S_SCK = 36;
const int I2S_SD = 35;
const AudioInfo info(8000, 1, 16);
I2SStream i2sStream; // Access I2S as stream
CsvOutput<int16_t> csvOutput(Serial);
StreamCopy copier(csvOutput, i2sStream); // copy i2sStream to csvOutput
// Arduino Setup
void setup(void) {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
auto cfg = i2sStream.defaultConfig(RX_MODE);
cfg.copyFrom(info);
cfg.i2s_format = I2S_STD_FORMAT; // or try with I2S_LSB_FORMAT
cfg.use_apll = false;
cfg.pin_data = I2S_SD;
cfg.pin_mck = I2S_SCK;
cfg.pin_ws = I2S_WS;
i2sStream.begin(cfg);
// make sure that we have the correct channels set up
csvOutput.begin(info);
Serial.println("starting...");
}
// Arduino loop - copy data
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,20 @@
/// set
/// - USB CDC on Boot: enabled
/// - PSRAM: QSPI RAM
#include <Arduino.h>
void setup() {
Serial.begin(115200);
Serial.printf("Total heap: %d\n", ESP.getHeapSize());
Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize());
Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());
}
void loop() {
}

View File

@@ -0,0 +1,259 @@
/*
* pin 1 - not used | Micro SD card |
* pin 2 - CS (SS) | /
* pin 3 - DI (MOSI) | |__
* pin 4 - VDD (3.3V) | |
* pin 5 - SCK (SCLK) | 8 7 6 5 4 3 2 1 /
* pin 6 - VSS (GND) | ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ /
* pin 7 - DO (MISO) | ▀ ▀ █ ▀ █ ▀ ▀ ▀ |
* pin 8 - not used |_________________|
* ║ ║ ║ ║ ║ ║ ║ ║
* ╔═══════╝ ║ ║ ║ ║ ║ ║ ╚═════════╗
* ║ ║ ║ ║ ║ ║ ╚══════╗ ║
* ║ ╔═════╝ ║ ║ ║ ╚═════╗ ║ ║
* Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║
* full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║
* SD card ║ ║ ║ ║ ║ ║ ║ ║ ║
* Pin name | - DO VSS SCK VDD VSS DI CS - |
* SD pin number | 8 7 6 5 4 3 2 1 9 /
* | █/
* |__▍___▊___█___█___█___█___█___█___/
*
* Note: The SPI pins can be manually configured by using `SPI.begin(sck, miso, mosi, cs).`
* Alternatively, you can change the CS pin and use the other default settings by using `SD.begin(cs)`.
*
* +--------------+---------+-------+----------+----------+----------+----------+----------+
* | SPI Pin Name | ESP8266 | ESP32 | ESP32S2 | ESP32S3 | ESP32C3 | ESP32C6 | ESP32H2 |
* +==============+=========+=======+==========+==========+==========+==========+==========+
* | CS (SS) | GPIO15 | GPIO5 | GPIO34 | GPIO10 | GPIO7 | GPIO18 | GPIO0 |
* +--------------+---------+-------+----------+----------+----------+----------+----------+
* | DI (MOSI) | GPIO13 | GPIO23| GPIO35 | GPIO11 | GPIO6 | GPIO19 | GPIO25 |
* +--------------+---------+-------+----------+----------+----------+----------+----------+
* | DO (MISO) | GPIO12 | GPIO19| GPIO37 | GPIO13 | GPIO5 | GPIO20 | GPIO11 |
* +--------------+---------+-------+----------+----------+----------+----------+----------+
* | SCK (SCLK) | GPIO14 | GPIO18| GPIO36 | GPIO12 | GPIO4 | GPIO21 | GPIO10 |
* +--------------+---------+-------+----------+----------+----------+----------+----------+
*
* For more info see file README.md in this library or on URL:
* https://github.com/espressif/arduino-esp32/tree/master/libraries/SD
*/
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#define REASSIGN_PINS
int sck = 42;
int miso = 41;
int mosi = 39;
int cs = 38;
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.path(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char *path) {
Serial.printf("Creating Dir: %s\n", path);
if (fs.mkdir(path)) {
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char *path) {
Serial.printf("Removing Dir: %s\n", path);
if (fs.rmdir(path)) {
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if (!file) {
Serial.println("Failed to open file for appending");
return;
}
if (file.print(message)) {
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char *path1, const char *path2) {
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(fs::FS &fs, const char *path) {
Serial.printf("Deleting file: %s\n", path);
if (fs.remove(path)) {
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
void testFileIO(fs::FS &fs, const char *path) {
File file = fs.open(path);
static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;
if (file) {
len = file.size();
size_t flen = len;
start = millis();
while (len) {
size_t toRead = len;
if (toRead > 512) {
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u bytes read for %lu ms\n", flen, end);
file.close();
} else {
Serial.println("Failed to open file for reading");
}
file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
size_t i;
start = millis();
for (i = 0; i < 2048; i++) {
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end);
file.close();
}
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
#ifdef REASSIGN_PINS
SPI.begin(sck, miso, mosi, cs);
if (!SD.begin(cs)) {
#else
if (!SD.begin()) {
#endif
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
listDir(SD, "/", 0);
createDir(SD, "/mydir");
listDir(SD, "/", 0);
removeDir(SD, "/mydir");
listDir(SD, "/", 2);
writeFile(SD, "/hello.txt", "Hello ");
appendFile(SD, "/hello.txt", "World!\n");
readFile(SD, "/hello.txt");
deleteFile(SD, "/foo.txt");
renameFile(SD, "/hello.txt", "/foo.txt");
readFile(SD, "/foo.txt");
testFileIO(SD, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}
void loop() {}

View File

@@ -0,0 +1,262 @@
/*
* pin 1 - D2 | Micro SD card |
* pin 2 - D3 | /
* pin 3 - CMD | |__
* pin 4 - VDD (3.3V) | |
* pin 5 - CLK | 8 7 6 5 4 3 2 1 /
* pin 6 - VSS (GND) | ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ /
* pin 7 - D0 | ▀ ▀ █ ▀ █ ▀ ▀ ▀ |
* pin 8 - D1 |_________________|
* ║ ║ ║ ║ ║ ║ ║ ║
* ╔═══════╝ ║ ║ ║ ║ ║ ║ ╚═════════╗
* ║ ║ ║ ║ ║ ║ ╚══════╗ ║
* ║ ╔═════╝ ║ ║ ║ ╚═════╗ ║ ║
* Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║
* full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║
* SD card ║ ║ ║ ║ ║ ║ ║ ║ ║
* ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 |
* ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 |
* ESP32 | 4 2 GND 14 3V3 GND 15 13 12 |
* ESP32-S3-Camera 40 41 42 39 38 37
* Pin name | D1 D0 VSS CLK VDD VSS CMD D3 D2 |
* SD pin number | 8 7 6 5 4 3 2 1 9 /
* | █/
* |__▍___▊___█___█___█___█___█___█___/
* WARNING: ALL data pins must be pulled up to 3.3V with an external 10k Ohm resistor!
* Note to ESP32 pin 2 (D0): Add a 1K Ohm pull-up resistor to 3.3V after flashing
*
*
* For more info see file README.md in this library or on URL:
* https://github.com/espressif/arduino-esp32/tree/master/libraries/SD_MMC
*/
#include "FS.h"
#include "SD_MMC.h"
// Default pins for ESP-S3
// Warning: ESP32-S3-WROOM-2 is using most of the default GPIOs (33-37) to interface with on-board OPI flash.
// If the SD_MMC is initialized with default pins it will result in rebooting loop - please
// reassign the pins elsewhere using the mentioned command `setPins`.
// Note: ESP32-S3-WROOM-1 does not have GPIO 33 and 34 broken out.
// Note: if it's ok to use default pins, you do not need to call the setPins
int clk = 42;
int cmd = 39;
int d0 = 41;
int d1 = 40;
int d2 = 37;
int d3 = 38;
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.path(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char *path) {
Serial.printf("Creating Dir: %s\n", path);
if (fs.mkdir(path)) {
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char *path) {
Serial.printf("Removing Dir: %s\n", path);
if (fs.rmdir(path)) {
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
}
void writeFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
}
void appendFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if (!file) {
Serial.println("Failed to open file for appending");
return;
}
if (file.print(message)) {
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
}
void renameFile(fs::FS &fs, const char *path1, const char *path2) {
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(fs::FS &fs, const char *path) {
Serial.printf("Deleting file: %s\n", path);
if (fs.remove(path)) {
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
void testFileIO(fs::FS &fs, const char *path) {
File file = fs.open(path);
static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;
if (file) {
len = file.size();
size_t flen = len;
start = millis();
while (len) {
size_t toRead = len;
if (toRead > 512) {
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u bytes read for %lu ms\n", flen, end);
file.close();
} else {
Serial.println("Failed to open file for reading");
}
file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
size_t i;
start = millis();
for (i = 0; i < 2048; i++) {
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end);
file.close();
}
void setup() {
Serial.begin(115200);
while (!Serial)
;
Serial.println("starting...");
/*
// If you want to change the pin assignment on ESP32-S3 uncomment this block and the appropriate
// line depending if you want to use 1-bit or 4-bit line.
// Please note that ESP32 does not allow pin change and will always fail.
//if(! SD_MMC.setPins(clk, cmd, d0)){
if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)){
Serial.println("Pin change failed!");
return;
}
*/
if (!SD_MMC.setPins(clk, cmd, d0)) {
Serial.println("Pin change failed!");
return;
}
if (!SD_MMC.begin("/sdcard", true)) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD_MMC card attached");
return;
}
Serial.print("SD_MMC Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
listDir(SD_MMC, "/", 0);
createDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 0);
removeDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 2);
writeFile(SD_MMC, "/hello.txt", "Hello ");
appendFile(SD_MMC, "/hello.txt", "World!\n");
readFile(SD_MMC, "/hello.txt");
deleteFile(SD_MMC, "/foo.txt");
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop() {}

View File

@@ -0,0 +1,10 @@
The LyraT Mini is a bit tricky to use because it has a ES8311 which is handling the output and a
ES7243 which is handling the microphone input: both need to be on separate I2S ports.
You should be able to use the examples that can be found in the [audiokit directory](https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-audiokit): just replace the
driver with LyratMini!
For the examples install:
- [Arduino AudioTools](https://github.com/pschatzmann/arduino-audio-tools)
- [Arduino Audio Driver](https://github.com/pschatzmann/arduino-audio-driver)

View File

@@ -0,0 +1,64 @@
/**
* @file buttons.ino
* @author Phil Schatzmann
* @brief Demo how to use the buttons.
* @version 0.1
* @date 2024-11-03
*
* The button values are determined with an analogRead(39) via the driver library.
* This demo shows how to use the integrated AudioActions class via the AudioBoardStream
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioBoardStream lyrat(LyratMini);
void rec(bool, int, void*) {
Serial.println("rec");
}
void mode(bool, int, void*) {
Serial.println("mode");
}
void play(bool, int, void*) {
Serial.println("play");
}
void set(bool, int, void*) {
Serial.println("set");
}
void volUp(bool, int, void*) {
Serial.println("vol+");
}
void volDown(bool, int, void*) {
Serial.println("vol-");
}
// Arduino Setup
void setup(void) {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// start board
lyrat.begin(lyrat.defaultConfig(TX_MODE));
lyrat.addAction(KEY_REC, rec);
lyrat.addAction(KEY_MODE, mode);
lyrat.addAction(KEY_PLAY, play);
lyrat.addAction(KEY_SET, set);
lyrat.addAction(KEY_VOLUME_UP, volUp);
lyrat.addAction(KEY_VOLUME_DOWN, volDown);
}
void loop() {
lyrat.processActions();
}

View File

@@ -0,0 +1,49 @@
/**
* @file output.ino
* @author Phil Schatzmann
* @brief Demo how to use the microphone.
* @version 0.1
* @date 2024-11-03
*
* The microphone seems to be attached to 2 different i2s ports. In addition to the
* ES8311, the ES7243 is also started.
* The I2S pins can be selected via cfg.i2s_function: CODEC uses the ES8311 I2S pins
* and CODEC_ADC uses the ES7243 I2S pins; By default the CODEC value is used.
*
* Only CODEC_ADC will give a proper microphone input!
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioInfo info(44100, 2, 16);
AudioBoardStream i2s(LyratMini); // Access I2S as stream
CsvOutput<int16_t> csvOutput(Serial);
StreamCopy copier(csvOutput, i2s); // copy i2s to csvOutput
// Arduino Setup
void setup(void) {
Serial.begin(115200);
// Display details what is going on
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
AudioDriverLogger.begin(Serial, AudioDriverLogLevel::Info);
auto cfg = i2s.defaultConfig(RX_MODE);
cfg.copyFrom(info);
// cfg.i2s_function = PinFunction::CODEC_ADC; // determined automatically
// cfg.i2s_port_no = 0; // or 1 if 0 is already in use
i2s.begin(cfg);
// make sure that we have the correct number of channels set up
csvOutput.begin(info);
}
// Arduino loop - copy data
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,48 @@
/**
* @file output.ino
* @author Phil Schatzmann
* @brief Demo to output audio on a lyrat-mini board: with headphone detection
* active to switch the power amplifier on and off.
* I2S is used and the ES8311 is initialized via the driver library.
* @version 0.1
* @date 2024-11-03
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
AudioBoardStream out(LyratMini);
StreamCopy copier(out, sound); // copies sound into i2s
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
// cfg.i2s_function = PinFunction::CODEC; // determined automatically
// cfg.i2s_port_no = 0; // or 1 if 0 is already in use
out.begin(config);
// additinal settings
out.setVolume(0.5);
out.addHeadphoneDetectionAction();
// start sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
}
void loop() {
copier.copy();
out.processActions();
}

View File

@@ -0,0 +1,55 @@
/**
* @file sd.ino
* @author Phil Schatzmann
* @brief Test/Demo that SD is not working!
* @version 0.1
* @date 2024-11-03
*
* @copyright Copyright (c) 2022
*/
#include <SPI.h>
#include <SD.h>
// These pins are defined in the HAL
#define PIN_SD_CARD_CS 13
#define PIN_SD_CARD_MISO 2
#define PIN_SD_CARD_MOSI 15
#define PIN_SD_CARD_CLK 14
#define PIN_SD_CARD_DET 34
// Arduino Setup
void setup(void) {
Serial.begin(115200);
// setup SPI
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI, PIN_SD_CARD_CS);
// Optionally determine if there is an SD card
pinMode(PIN_SD_CARD_DET, INPUT);
if (digitalRead(PIN_SD_CARD_DET)!=0){
Serial.println("No SD Card detected");
}
// Open SD library
if (!SD.begin(PIN_SD_CARD_CS)){
Serial.println("SD.begin failed");
while(true);
}
// Open an existing file
auto file = SD.open("/audio8000.raw", FILE_READ);
if (!file){
Serial.println("file open failed");
while(true);
}
file.close();
Serial.println("Success");
}
// Arduino loop - repeated processing
void loop() {}

View File

@@ -0,0 +1,52 @@
/**
* @file sdmmc.ino
* @author Phil Schatzmann
* @brief Test/Demo how to use the SD_MMC API in Arduino with the LyraT Mini
* @version 0.1
* @date 2024-11-03
*
* @copyright Copyright (c) 2022
*/
#include "FS.h"
#include "SD_MMC.h"
// These pins are defined in the HAL
const int PIN_SD_CARD_POWER = 13;
const int PIN_SD_CARD_DET = 34;
// Arduino Setup
void setup(void) {
Serial.begin(115200);
// Mandatory: set power pin to low
pinMode(PIN_SD_CARD_POWER, OUTPUT);
digitalWrite(PIN_SD_CARD_POWER, LOW);
// Optionally: Determine if there is an SD card
pinMode(PIN_SD_CARD_DET, INPUT);
if (digitalRead(PIN_SD_CARD_DET)!=0){
Serial.println("No SD Card detected");
}
// open SDMMC in 1 bit mode
if (!SD_MMC.begin("/sdcard", true)) {
Serial.println("Card Mount Failed");
while(true);
}
// open an existing file
auto file = SD_MMC.open("/test.mp3", FILE_READ);
if (!file){
Serial.println("file open failed");
while(true);
}
file.close();
Serial.println("Success");
}
// Arduino loop - repeated processing
void loop() {}