I've been digging a lot for the last couple days, into trying to create some sounds from the M5core2 speaker (tones) but I haven't been able to get anything to work.
I tried the Arduino 2.x Example, but that's declared as the M5Tough. Then I found the same example file on the M5core2 from 'github' (updated?):
M5-ProductExampleCodes/Core/M5Core2/Arduino/speak/speak.ino at master · m5stack/M5-ProductExampleCodes · GitHub
But I can't get that to compile. The errors end with:
c:/users/mfros/appdata/local/arduino15/packages/m5stack/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\mfros\AppData\Local\arduino\sketches\B714D4ED1044DE02A7B84BDD4D8EEB69\sketch\DingDongSimp.ino.cpp.o:(.literal._Z8DingDongv+0x4): undefined reference to `previewR'
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "SD.h"
Used: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\SD
Not used: C:\Users\mfros\AppData\Local\Arduino15\libraries\SD
Not used: C:\Users\mfros\Documents\Arduino\libraries\SD
Using library M5Core2 at version 0.2.0 in folder: C:\Users\mfros\Documents\Arduino\libraries\M5Core2
Using library Wire at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\Wire
Using library SPI at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\SPI
Using library FS at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\FS
Using library SD at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\SD
Using library SPIFFS at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\SPIFFS
Using library HTTPClient at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\HTTPClient
Using library WiFi at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\WiFi
Using library WiFiClientSecure at version 2.0.0 in folder: C:\Users\mfros\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.3\libraries\WiFiClientSecure
exit status 1
Compilation error: exit status 1
I tried another from:
Wouldn't compile either...
Tried a sketch that I found in: How to make audio tone from Core2 speaker · Issue #12 · m5stack/M5Unified · GitHub
#include <M5Unified.h>
const uint8_t sin_wav[] = { 128, 152, 176, 198, 218, 234, 245, 253, 255, 253, 245, 234, 218, 198, 176, 152, 128, 103, 79, 57, 37, 21, 10, 2, 0, 2, 10, 21, 37, 57, 79, 103 };
void setup(void)
{
M5.begin();
M5.Display.setFont(&fonts::DejaVu18);
{ /// By changing the sampling rate, the fold noise changes.
auto spk_cfg = M5.Speaker.config();
// spk_cfg.sample_rate = 50000;
spk_cfg.sample_rate = 96000;
// spk_cfg.sample_rate = 100000;
// spk_cfg.sample_rate = 144000;
// spk_cfg.sample_rate = 192000;
// spk_cfg.sample_rate = 200000;
M5.Speaker.config(spk_cfg);
}
M5.Speaker.begin();
M5.Speaker.setVolume(64);
}
void loop(void)
{
delay(500);
for (int i = 500; i < 8000; i += 1) {
// M5.Speaker.tone(i, 1000, 0, true);
M5.Speaker.tone(i, 1000, 0, true, sin_wav, sizeof(sin_wav));
M5.Display.setCursor(0, M5.Display.height() / 2);
M5.Display.printf("Freq = %d Hz ", i);
delay(1);
}
delay(500);
for (int i = 500; i < 8000; i += 500) {
// M5.Speaker.tone(i, 500, 0, true);
M5.Speaker.tone(i, 500, 0, true, sin_wav, sizeof(sin_wav));
M5.Display.setCursor(0, M5.Display.height() / 2);
M5.Display.printf("Freq = %d Hz ", i);
while (M5.Speaker.isPlaying()) { delay(1); }
}
}
Which worked, but it uses M5Unified.h which has the ".tone()" function. I need to use the "M5core2.h" for my application and I couldn't get the script to compile with both of them declared. To be honest, I'm not sure what the M5Unified.h is, other than it's supposed to support multiple M5 products (I think...).
I'm looking for a simple function to sent out tones.
Any other ideas?
Sir Michael