I thought it might be cool to provide a remote control for the AudioPlayer which is part of the Arduino Audio Tools.

I did not want to invent a new protocol, so I implemented the HTML interface that has been documented by the KA-Radio project.

I am providing a Stream and a Http implementation via the following classes:

The following commands are supported: play, instant, volume, volume+, volume-, pause, resume, stop, start, next, prev, mute, infos, version.

The Arduino Sketch

To keep things simple, I am using an AudioKit for this test, which has a built in SD drive and a Es8388 Codec Chip.

Here is a simple Arduino Sketch that implements the Serial Protocol. Enter the following command via the Serial Monitor for example “volume=50&play=128&infos” to start the playback of the file #128 at volume 50 and display all infos.

#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h" // arduino-audio-driver
#include "AudioTools/Disk/AudioSourceSDMMC.h" // or AudioSourceIdxSDMMC.h
#include "AudioTools/AudioCodecs/CodecMP3Helix.h" // libhelix
#include "AudioTools/AudioLibs/KARadioProtocol.h"

const char *startFilePath="/";
const char* ext="mp3";
AudioSourceSDMMC source(startFilePath, ext);
AudioBoardStream kit(AudioKitEs8388V1);
MP3DecoderHelix decoder;  // or change to MP3DecoderMAD
AudioPlayer player(source, kit, decoder);
KARadioProtocol protocol(player); // Serial remote control protocol 

void setup() {
  Serial.begin(115200);
  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);

  // setup output
  auto cfg = kit.defaultConfig(TX_MODE);
  cfg.sd_active = false;
  kit.begin(cfg);

  // setup player
  player.setVolume(0.7);
  player.begin();
  player.setActive(false);
}

void loop() {
  // process command
  protocol.processCommand(Serial, Serial);
  // process Audio
  player.copy();
}

The command protocol.processCommand(Serial, Serial); is reading the command from Serial and outputs the result to Serial.

Dependencies


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *