ATOM SPK SPEAKER KIT
-
Hello, some example of how to use SPK with the library: github
How do I configure the output to use the spk chip?
I have modified an example in the ide, but I don't know if it is correct.This example in theory plays an mp3 station
Thanks for the help
All the best
Francisco#include <Arduino.h>
#include <M5Atom.h>
#include <WiFi.h>
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
//#include "AudioOutputI2SNoDAC.h"
#include "AudioOutputI2S.h"// Enter your WiFi setup here:
#ifndef STASSID
#define STASSID "TESTWIFI"
#define STAPSK "TEST"
#endif// Digital I/O used
#define I2S_DOUT 25 // DIN connection
#define I2S_BCLK 22 // Bit clock
#define I2S_LRC 21 // Left Right Clockconst char* ssid = STASSID;
const char* password = STAPSK;// Randomly picked URL
const char* URL = "http://kvbstreams.dyndns.org:8000/wkvi-am";AudioGeneratorMP3* mp3;
AudioFileSourceICYStream* file;
AudioFileSourceBuffer* buff;
//AudioOutputI2SNoDAC* out;
AudioOutputI2S* out = NULL;
//AudioOutputI2S* outvoid setup()
{
M5.begin();Serial.begin(9600); delay(1000); Serial.println("Connecting to WiFi"); WiFi.disconnect(); WiFi.softAPdisconnect(true); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); // Try forever while (WiFi.status() != WL_CONNECTED) { Serial.println("...Connecting to WiFi"); delay(1000); } Serial.println("Connected"); audioLogger = &Serial; file = new AudioFileSourceICYStream(URL); file->RegisterMetadataCB(MDCallback, (void*)"ICY"); buff = new AudioFileSourceBuffer(file, 2048); buff->RegisterStatusCB(StatusCallback, (void*)"buffer"); //out = new AudioOutputI2SNoDAC(); out = new AudioOutputI2S(0, 1, 32); out->begin(); mp3 = new AudioGeneratorMP3(); mp3->RegisterStatusCB(StatusCallback, (void*)"mp3"); mp3->begin(buff, out);}
void loop()
{
static int lastms = 0;if (mp3->isRunning()) { if (millis() - lastms > 1000) { lastms = millis(); Serial.printf("Running for %d ms...\n", lastms); Serial.flush(); } if (!mp3->loop()) mp3->stop(); } else { Serial.printf("MP3 done\n"); delay(1000); }}
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void* cbData, const char* type, bool isUnicode, const char* string)
{
const char* ptr = reinterpret_cast<const char*>(cbData);
(void)isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
char s1[32], s2[64];
strncpy_P(s1, type, sizeof(s1));
s1[sizeof(s1) - 1] = 0;
strncpy_P(s2, string, sizeof(s2));
s2[sizeof(s2) - 1] = 0;
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
Serial.flush();
}// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void* cbData, int code, const char* string)
{
const char* ptr = reinterpret_cast<const char*>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1) - 1] = 0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
}Thanks for the help
All the best
Francisco
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login