Skip to content

Commit a5df252

Browse files
committed
ESP32‐S3 AI Smart Speaker
1 parent f086d01 commit a5df252

File tree

10 files changed

+371
-41
lines changed

10 files changed

+371
-41
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Examples for the [ESP32‐S3 AI Smart Speaker Development Board](https://github.com/pschatzmann/arduino-audio-driver/wiki/ESP32%E2%80%90S3-AI-Smart-Speaker-Development-Board)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file streams-generator-audiokit.ino
3+
* @brief NeoPixel example for ESP32-S3-AI-Smart-Speaker
4+
* @author Phil Schatzmann
5+
* @copyright GPLv3
6+
*/
7+
8+
#include <Adafruit_NeoPixel.h>
9+
10+
// Which pin on the Arduino is connected to the NeoPixels?
11+
#define PIN 38
12+
13+
// How many NeoPixels are attached to the Arduino?
14+
#define NUMPIXELS 6
15+
16+
// When setting up the NeoPixel library, we tell it how many pixels,
17+
// and which pin to use to send signals. Note that for older NeoPixel
18+
// strips you might need to change the third parameter -- see the
19+
// strandtest example for more information on possible values.
20+
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
21+
22+
void setup() {
23+
// END of Trinket-specific code.
24+
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
25+
}
26+
27+
void loop() {
28+
pixels.clear(); // Set all pixel colors to 'off'
29+
30+
// The first NeoPixel in a strand is #0, second is 1, all the way up
31+
// to the count of pixels minus one.
32+
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
33+
34+
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
35+
int red = random(255);
36+
int green = random(255);
37+
int blue = random(255);
38+
// Here we're using a moderately bright green color:
39+
pixels.setPixelColor(i, pixels.Color(red, green, blue));
40+
}
41+
pixels.show(); // Send the updated pixel colors to the hardware.
42+
delay(100); // Pause before next pass through loop
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @file player-sdmmc-audiokit.ino
3+
* @brief SDMMC Audio Player example for ESP32-S3-AI-Smart-Speaker
4+
* @author Phil Schatzmann
5+
* @copyright GPLv3
6+
*/
7+
8+
#include "AudioTools.h"
9+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
10+
#include "AudioTools/Disk/AudioSourceSDMMC.h" // or AudioSourceIdxSDMMC.h
11+
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
12+
#include "ESP32S3AISmartSpeaker.h"
13+
14+
const char *startFilePath="/";
15+
const char* ext="mp3";
16+
AudioSourceSDMMC source(startFilePath, ext);
17+
AudioBoardStream kit(ESP32S3AISmartSpeaker);
18+
MP3DecoderHelix decoder; // or change to MP3DecoderMAD
19+
AudioPlayer player(source, kit, decoder);
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
delay(2000);
24+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
25+
26+
// setup output
27+
auto cfg = kit.defaultConfig(TX_MODE);
28+
cfg.sdmmc_active = true;
29+
//cfg.sd_active = false;
30+
kit.begin(cfg);
31+
kit.setVolume(0.4);
32+
33+
34+
// setup player: must be after
35+
player.begin();
36+
37+
// select file with setPath() or setIndex()
38+
//player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
39+
//player.setIndex(1); // 2nd file
40+
41+
}
42+
43+
void loop() {
44+
player.copy();
45+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @file real-time-clock.ino
3+
* @brief RTC PCF85063A example for ESP32-S3-AI-Smart-Speaker
4+
* @author Phil Schatzmann
5+
* @copyright GPLv3
6+
*/
7+
8+
#include "AudioTools.h"
9+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
10+
#include "ESP32S3AISmartSpeaker.h"
11+
#include "PCF85063A-SOLDERED.h"
12+
13+
PCF85063A rtc;
14+
AudioBoardStream board(ESP32S3AISmartSpeaker);
15+
16+
void setup() {
17+
Serial.begin(115200);
18+
19+
// Initialize audio board: I2C
20+
board.begin();
21+
22+
// Initialize RTC module
23+
rtc.begin();
24+
25+
// setTime(hour, minute, sec);
26+
rtc.setTime(6, 54, 00); // 24H mode, ex. 6:54:00
27+
// setDate(weekday, day, month, yr);
28+
rtc.setDate(6, 16, 5, 2020); // 0 for Sunday, ex. Saturday, 16.5.2020.
29+
}
30+
31+
void loop() {
32+
printCurrentTime(); // Call funtion printCurrentTime()
33+
delay(1000);
34+
}
35+
36+
void printCurrentTime() {
37+
// Get weekday, 0 is Sunday and decode to string
38+
switch (rtc.getWeekday()) {
39+
case 0:
40+
Serial.print("Sunday , ");
41+
break;
42+
case 1:
43+
Serial.print("Monday , ");
44+
break;
45+
case 2:
46+
Serial.print("Tuesday , ");
47+
break;
48+
case 3:
49+
Serial.print("Wednesday , ");
50+
break;
51+
case 4:
52+
Serial.print("Thursday , ");
53+
break;
54+
case 5:
55+
Serial.print("Friday , ");
56+
break;
57+
case 6:
58+
Serial.print("Saturday , ");
59+
break;
60+
}
61+
62+
Serial.print(rtc.getDay()); // Function for getting day in month
63+
Serial.print(".");
64+
Serial.print(rtc.getMonth()); // Function for getting month
65+
Serial.print(".");
66+
Serial.print(rtc.getYear()); // Function for getting year
67+
Serial.print(". ");
68+
Serial.print(rtc.getHour()); // Function for getting hours
69+
Serial.print(":");
70+
Serial.print(rtc.getMinute()); // Function for getting minutes
71+
Serial.print(":");
72+
Serial.println(rtc.getSecond()); // Function for getting seconds
73+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @file streams-audiokit-csv.ino
3+
* @author Phil Schatzmann
4+
* @brief Testing the microphones: record a sine tome and open the serial plotter
5+
*
6+
* @author Phil Schatzmann
7+
* @copyright GPLv3
8+
*/
9+
10+
11+
#include "AudioTools.h"
12+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
13+
#include "ESP32S3AISmartSpeaker.h"
14+
15+
AudioInfo info(44100, 2, 16);
16+
AudioBoardStream kit(ESP32S3AISmartSpeaker); // Access I2S as stream
17+
CsvOutput<int16_t> csvOutput(Serial);
18+
StreamCopy copier(csvOutput, kit); // copy kit to csvOutput
19+
20+
// Arduino Setup
21+
void setup(void) {
22+
Serial.begin(115200);
23+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
24+
25+
auto cfg = kit.defaultConfig(RX_MODE);
26+
cfg.copyFrom(info);
27+
cfg.input_device = ADC_INPUT_LINE2;
28+
kit.begin(cfg);
29+
30+
// make sure that we have the correct channels set up
31+
csvOutput.begin(info);
32+
33+
}
34+
35+
// Arduino loop - copy data
36+
void loop() {
37+
copier.copy();
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file streams-generator-audiokit.ino
3+
* @brief Tesing I2S output for ESP32-S3-AI-Smart-Speaker with generated sine wave
4+
* @author Phil Schatzmann
5+
* @copyright GPLv3
6+
*/
7+
8+
#include "AudioTools.h"
9+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
10+
#include "ESP32S3AISmartSpeaker.h"
11+
12+
AudioInfo info(32000, 2, 16);
13+
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
14+
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
15+
AudioBoardStream out(ESP32S3AISmartSpeaker);
16+
StreamCopy copier(out, sound); // copies sound into i2s
17+
18+
// Arduino Setup
19+
void setup(void) {
20+
// Open Serial
21+
Serial.begin(115200);
22+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
23+
24+
// start I2S
25+
Serial.println("starting I2S...");
26+
auto config = out.defaultConfig(TX_MODE);
27+
config.copyFrom(info);
28+
out.begin(config);
29+
30+
// set the volume
31+
out.setVolume(0.4f);
32+
33+
// Setup sine wave
34+
sineWave.begin(info, N_B4);
35+
Serial.println("started...");
36+
}
37+
38+
// Arduino loop - copy sound to out
39+
void loop() {
40+
copier.copy();
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @file test-extio.ino
3+
* @brief Testing gpio inputs for ESP32-S3-AI-Smart-Speaker: you can call
4+
* digitalRead() and digitalWrite() on all pins including the EXIO pins.
5+
* The EXIO are mapped to starting at 1000: EXIO10 = 1010, EXIO11 = 1011, EXIO12 = 1012, ...
6+
* @author Phil Schatzmann
7+
* @copyright GPLv3
8+
*/
9+
#include "AudioTools.h"
10+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
11+
#include "ESP32S3AISmartSpeaker.h"
12+
13+
AudioInfo info(44100, 2, 16);
14+
AudioBoardStream board(ESP32S3AISmartSpeaker); // Access I2S as stream
15+
CsvOutput<int16_t> csvOutput(Serial);
16+
StreamCopy copier(csvOutput, board); // copy board to csvOutput
17+
18+
// Arduino Setup
19+
void setup(void) {
20+
Serial.begin(115200);
21+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
22+
23+
// setup board with default config
24+
board.begin();
25+
}
26+
27+
// Arduino loop - print keys
28+
void loop() {
29+
int key1 = board.digitalRead(EXIO10);
30+
int key2 = board.digitalRead(EXIO11);
31+
int key3 = board.digitalRead(EXIO12);
32+
33+
char msg[100];
34+
snprintf(msg, 100, "Keys: %d %d %d", key1, key2, key3);
35+
Serial.println(msg);
36+
37+
delay(1000);
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file test-keys.ino
3+
* @brief Testing key inputs for ESP32-S3-AI-Smart-Speaker.
4+
* The EXIO pins are mapped to starting at 1000: EXIO10 = 1010, EXIO11 = 1011,
5+
* EXIO12 = 1012, ...
6+
* @author Phil Schatzmann
7+
* @copyright GPLv3
8+
*/
9+
10+
#include "AudioTools.h"
11+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
12+
#include "ESP32S3AISmartSpeaker.h"
13+
14+
AudioBoardStream board(ESP32S3AISmartSpeaker); // Access I2S as stream
15+
16+
// event handler for key presses
17+
void handleKey(bool active, int gpio, void*) {
18+
Serial.print("Key event ");
19+
Serial.print(gpio);
20+
Serial.print(" -> ");
21+
Serial.println(active);
22+
}
23+
24+
// Arduino Setup
25+
void setup(void) {
26+
Serial.begin(115200);
27+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
28+
delay(3000);
29+
30+
// setup actions for keys
31+
board.addAction(board.getKey(1), handleKey);
32+
board.addAction(board.getKey(2), handleKey);
33+
board.addAction(board.getKey(3), handleKey);
34+
35+
// setup board with default config
36+
board.begin();
37+
}
38+
39+
// Arduino loop - copy data
40+
void loop() { board.processActions(); }

src/AudioTools/AudioLibs/AudioBoardStream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class AudioBoardStream : public I2SCodecStream {
3939
AudioBoardStream(audio_driver::AudioBoard &board) : I2SCodecStream(board) {
4040
// pin mode already set up by driver library
4141
actions.setPinMode(false);
42+
// use the AudioBoard
43+
actions.setReadCallback([this](int pin) { return this->digitalRead(pin); });
4244
}
4345

4446
bool begin() override { return I2SCodecStream::begin(); }

0 commit comments

Comments
 (0)