AMB82-mini uart example

Hi,

Could somebody provide example code how set additional uart pins to send byte array? I mean, usually in arduino IDE i can use SoftwareSerial.h but in AMB82-mini I get error message, that library do not exist. Also code completion suggest use Serial1, Serial2, Serial3 but it not working for me. Plus, I do not find information that UART in amb82-mini can work in 921600 baud rate. Probably can, but still.

Thank you.

Hi @Justinas_Krauleidis ,

Currently SoftwareSerial library is only supported in AmebaD boards and not yet on AMB82-Mini. We will need to test further and port this feature to AMB82-Mini. Please give us some time to give you a sample code to use the additional UART pins to send byte array.

UART in AMB82-Mini can work in 921600 baud rate. Here is the proof.

Thank you.

Hi @Kelvin_Huang I got a Grove - MP3 Module V4.0 and I’m using it with the AMB82-Mini but that module requires the Software Serial Library. Is there any way I can play the audio directly from the SD card and the AOUT pin from the AMB82 Mini board? Or when will you and your team be porting the Software serial library?

Hi, the library not working, but in AMB82-Mini you have 4 UART ports, and in Arduino IDE they represent as Serial, Serial1, Serial2 and Serial3. So Serial1.begin() init UART2 interface. And it’s working. Working also on 921600 baudrate. I was able to send and get data.
In my case, bad wiring. On oscilloscope I saw “rounded data :D” sitting on 50Hz :D.

Hi @Justinas_Krauleidis, can you provide me with your code or an example to help me understand this

Hi @Incy ,

Instead of using SoftwareSerial, you can try to develop using hardware UART interfaces directly that AMB82-Mini provides. For example, you can try to connect grove - mp3 module to AMB82-Mini pins 21 and 22 to use serial1 UART interface. That way you can send uart commands to the module and get something back depending on the API of the MP3 Module.

Also, currently we don’t have a way to directly play audio from the SD card. The computer is a medium for the playback of audio.

We do not have a confirmed schedule on porting the Software Serial yet, but we will let you know once the feature is available.

Thanks!

Hi, instead of a library you can use Serial1.begin(115200); Serial1 represent 21 and 22 pins. Than try find datasheet about mp3 chip and write your own class.

Hi @Kelvin_Huang , Thankyou so much for the solution but I was unable to send the data to the MP3 Module to play it. I am unable to send an mp3 file from the AMB82 Mini to the MP3 Player module due to the restrictions in the MP3 Module. Is there any way I can play an MP3 audio file from the SD Card within the AMB82 Mini? Maybe RTP Stream the file to itself?

Hi @Incy ,

Right now, I do not have the MP3 module to help to test. Would you mind sharing your code on your implementation on how you are sending the MP3 file from AMB82 Mini to MP3 player? Maybe I can take a look and see if there are any errors in sending the file over.

There is an existing example to stream audio over the network. You may check this out if this is useful for your development. If not, you may request for this feature in our github. (https://www.amebaiot.com/en/amebapro2-arduino-audio-rtp/ ) We will discuss internally if we plan to include this feature in our SDK.

Thanks!

Hi @Kelvin_Huang ,
The problem I am encountering is that the MP3 Module is just connected via the UART Pins and the VCC and the GND, and the libraries for the MP3 Module do not directly allow for files to be directly transferred from AMB82 Mini to the MP3 Player. The code we have right now is just sending play / stop / volume signals to the MP3 Player.

What we want to achieve is when our server sends us a MP3 file on the AMB82 Mini, we want to play it but we can’t find a way to do so. RTP streaming via ffmpeg also does not seem to work (this is the command: ffmpeg -i input-file -c:v copy -c:a aac -b:a 48k -ac 1 -ar 8000 -f rtp rtp://192.168.150.28:5004 )

Is there any way we could write a function in the SDK ourselves to play the MP3 File from the SD card or could you suggest any other ways that might work like a different MP3 module compatible with the AMB82 Mini?
|
|
|
Following is our code for the MP3 Player:

#include "WT2605C_Player.h"
#include "Arduino.h"

#define COMSerial Serial1
#define ShowSerial Serial

WT2605C<HardwareSerial> Mp3Player;

void setup() {
  while (!ShowSerial);
  ShowSerial.begin(115200);
  COMSerial.begin(115200);
  ShowSerial.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
  Mp3Player.init(COMSerial);

  ShowSerial.println("0...");
}


void loop() {
  if(ShowSerial.available()) {
    String input = Serial.readString();
    input.trim();
    
    if(input.startsWith("v")) {
      int vol = input.substring(1).toInt();
      Mp3Player.volume(vol);
      ShowSerial.println("Volume set to: " + String(vol));
    }
    
    else if(input.startsWith("m")) {
      if(input.substring(1) == "1"){
        ShowSerial.println("1");
        int err = Mp3Player.playMode(static_cast<PLAY_MODE>(0x00));
        ShowSerial.println(err);
        if(!err) ShowSerial.println("The playback mode is set to Loop mode.");
        else ShowSerial.println("ERROR");
      }
      else if(input.substring(1) == "2"){
        ShowSerial.println("2");
        int err = Mp3Player.playMode(static_cast<PLAY_MODE>(0x01));
        ShowSerial.println(err);
        if(!err) ShowSerial.println("The playback mode is set to Single song loop mode.");
        else ShowSerial.println("ERROR");
      }
      else if(input.substring(1) == "3"){
        ShowSerial.println("3");
        int err = Mp3Player.playMode(static_cast<PLAY_MODE>(0x02));
        ShowSerial.println(err);
        if(!err) ShowSerial.println("The playback mode is set to Folder loop mode.");
        else ShowSerial.println("ERROR");
      }
      else if(input.substring(1) == "4"){
        ShowSerial.println("4");
        int err = Mp3Player.playMode(static_cast<PLAY_MODE>(0x03));
        ShowSerial.println(err);
        if(!err) ShowSerial.println("The playback mode is set to Random mode.");
        else ShowSerial.println("ERROR");
      }
      else if(input.substring(1) == "5"){
        ShowSerial.println("5");
        int err = Mp3Player.playMode(static_cast<PLAY_MODE>(0x04));
        ShowSerial.println(err);
        if(!err) ShowSerial.println("The playback mode is set to Single song mode.");
        else ShowSerial.println("ERROR");
      }
    }
    else if(input.startsWith("b")){
      int index = input.substring(1).toInt();
      Mp3Player.playSDRootSong(index);
      ShowSerial.println("Play music: " + String(index));
    }
    else if(input.startsWith("+")){
      int err = Mp3Player.volumeUp();
      if(!err) ShowSerial.println("Volume up");
      else ShowSerial.println("ERROR");
    }
    else if(input.startsWith("-")){
      int err = Mp3Player.volumeDown();
      if(!err) ShowSerial.println("Volume down");
      else ShowSerial.println("ERROR");
    }
    else if(input.startsWith("n")){
      Mp3Player.next();
      ShowSerial.println("Next song");
    }
    else if(input.startsWith("p")){
      Mp3Player.previous();
      ShowSerial.println("Previous song");
    }
  }
}

Hi @Incy ,

It should be possible to develop this feature to play audio files from SD card as long as you read the file and process it correctly. However, this feature to be developed should be quite challenging for you. I suggest that you can request for this feature first on our github so that we can discuss if this feature can be ported for future users who intend to use AMB82-Mini to playback audio files directly from SD card to AOUT pin of AMB82-Mini.

Most of the MP3 players out there would not have the ability to write into the SD card of the MP3 module.

I suppose the best way now is to read the mp3 file from SD card in AMB82-Mini, decode the mp3 file, transmit to AOUT, which you can then connect to a speaker to hear the output. [I haven’t try it before, so I might be wrong on these steps, but this is just my thoughts for development].

Actually in AmebaD boards, it does have the ability to record and playback wav files. You may take a look to see if it helps you with this. If this works, your server just can send wav file to AMB82-Mini instead of using mp3.

Thank you.